mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-24 22:14:42 +00:00
FarmStation: crops other than trees now require a hoe to be harvested, and the hoe takes 1 damage point per harvest.
This commit is contained in:
1 parent
2bd229f15a
commit
88f1bb1bc4
8 files changed
+51
-43
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockNewLeaf;
|
||||
import net.minecraft.block.BlockOldLeaf;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -35,6 +37,10 @@ import crazypants.util.Util;
|
||||
|
||||
public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
|
||||
public static final String NOTIFICATION_NO_HOE = "noHoe";
|
||||
public static final String NOTIFICATION_NO_AXE = "noAxe";
|
||||
public static final String NOTIFICATION_NO_SEEDS = "noSeeds";
|
||||
|
||||
private BlockCoord lastScanned;
|
||||
private EntityPlayerMP farmerJoe;
|
||||
|
||||
@@ -78,7 +84,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
Block dirtBlock = getBlock(dirtLoc);
|
||||
if((dirtBlock == Blocks.dirt || dirtBlock == Blocks.grass)) {
|
||||
if(!hasHoe()) {
|
||||
setNotification("noHoe");
|
||||
setNotification(NOTIFICATION_NO_HOE);
|
||||
return false;
|
||||
}
|
||||
damageHoe(1, dirtLoc);
|
||||
@@ -115,23 +121,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public void damageMaxLootingItem(int damage, BlockCoord bc, Block block) {
|
||||
int maxLooting = -1;
|
||||
ItemStack toDamage = null;
|
||||
for (int i = minToolSlot; i <= maxToolSlot; i++) {
|
||||
if(inventory[i] != null) {
|
||||
int level = getLooting(inventory[i]);
|
||||
if(level > maxLooting) {
|
||||
maxLooting = level;
|
||||
toDamage = inventory[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(toDamage != null) {
|
||||
damageTool(toDamage.getItem().getClass(), block, bc, damage);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasHoe() {
|
||||
return hasTool(ItemHoe.class);
|
||||
}
|
||||
@@ -140,10 +129,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
return hasTool(ItemAxe.class);
|
||||
}
|
||||
|
||||
public boolean hasDefaultHarvestTool() {
|
||||
return hasAxe() || hasHoe();
|
||||
}
|
||||
|
||||
public int getAxeLootingValue() {
|
||||
ItemStack tool = getTool(ItemAxe.class);
|
||||
if(tool == null) {
|
||||
@@ -183,11 +168,14 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
if(tool == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(tool.getItem() instanceof ItemAxe) {
|
||||
tool.getItem().onBlockDestroyed(tool, worldObj, blk, bc.x, bc.y, bc.z, farmerJoe);
|
||||
if(tool.getItem() instanceof ItemAxe) {
|
||||
tool.getItem().onBlockDestroyed(tool, worldObj, blk, bc.x, bc.y, bc.z, farmerJoe);
|
||||
} else if(tool.getItem() instanceof ItemHoe) {
|
||||
int origDamage = tool.getItemDamage();
|
||||
tool.getItem().onItemUse(tool, farmerJoe, worldObj, bc.x, bc.y, bc.z, 1, 0.5f, 0.5f, 0.5f);
|
||||
if(origDamage == tool.getItemDamage() && tool.isItemStackDamageable()) {
|
||||
tool.damageItem(1, farmerJoe);
|
||||
}
|
||||
} else if(tool.isItemStackDamageable()) {
|
||||
tool.damageItem(1, farmerJoe);
|
||||
}
|
||||
@@ -197,6 +185,10 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLeaves(Block blk) {
|
||||
return (blk instanceof BlockOldLeaf || blk instanceof BlockNewLeaf);
|
||||
}
|
||||
|
||||
private void destroyTool(Class<?> class1) {
|
||||
for (int i = minToolSlot; i <= maxToolSlot; i++) {
|
||||
if(Util.isType(inventory[i], class1)) {
|
||||
|
||||
@@ -119,7 +119,11 @@ public class CustomSeedFarmer implements IFarmerJoe {
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(!canHarvest(farm, bc, block, meta) || !farm.hasDefaultHarvestTool()) {
|
||||
if(!canHarvest(farm, bc, block, meta)) {
|
||||
return null;
|
||||
}
|
||||
if(!farm.hasHoe()) {
|
||||
farm.setNotification(TileFarmStation.NOTIFICATION_NO_HOE);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -127,7 +131,7 @@ public class CustomSeedFarmer implements IFarmerJoe {
|
||||
List<EntityItem> result = new ArrayList<EntityItem>();
|
||||
|
||||
ArrayList<ItemStack> drops = block.getDrops(worldObj, bc.x, bc.y, bc.z, meta, farm.getMaxLootingValue());
|
||||
farm.damageMaxLootingItem(1, bc, block);
|
||||
farm.damageHoe(1, bc);
|
||||
farm.actionPerformed(false);
|
||||
boolean removed = false;
|
||||
if(drops != null) {
|
||||
|
||||
@@ -18,14 +18,18 @@ public class NaturaBerryFarmer extends PickableFarmer {
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(block != getPlantedBlock() || !farm.hasDefaultHarvestTool()) {
|
||||
if(block != getPlantedBlock()) {
|
||||
return null;
|
||||
}
|
||||
if(!farm.hasHoe()) {
|
||||
farm.setNotification(TileFarmStation.NOTIFICATION_NO_HOE);
|
||||
return null;
|
||||
}
|
||||
|
||||
IHarvestResult res = new HarvestResult();
|
||||
|
||||
BlockCoord checkBlock = bc;
|
||||
for(int i=0; i < 5 && farm.hasDefaultHarvestTool(); i++) {
|
||||
for(int i=0; i < 5 && farm.hasHoe(); i++) {
|
||||
meta = farm.getBlockMeta(checkBlock);
|
||||
IHarvestResult blockRes = super.harvestBlock(farm, checkBlock, block, meta);
|
||||
|
||||
@@ -36,7 +40,7 @@ public class NaturaBerryFarmer extends PickableFarmer {
|
||||
res.getDrops().add(stack);
|
||||
}
|
||||
farm.actionPerformed(false);
|
||||
farm.damageMaxLootingItem(1, checkBlock, farm.getBlock(checkBlock));
|
||||
farm.damageHoe(1, checkBlock);
|
||||
}
|
||||
checkBlock = checkBlock.getLocation(ForgeDirection.UP);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,11 @@ public class PickableFarmer extends CustomSeedFarmer {
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(!canHarvest(farm, bc, block, meta) || !farm.hasDefaultHarvestTool()) {
|
||||
if(!canHarvest(farm, bc, block, meta)) {
|
||||
return null;
|
||||
}
|
||||
if(!farm.hasHoe()) {
|
||||
farm.setNotification(TileFarmStation.NOTIFICATION_NO_HOE);
|
||||
return null;
|
||||
}
|
||||
EntityPlayerMP player = farm.getFakePlayer();
|
||||
@@ -48,7 +52,7 @@ public class PickableFarmer extends CustomSeedFarmer {
|
||||
}
|
||||
}
|
||||
farm.actionPerformed(false);
|
||||
farm.damageMaxLootingItem(1, bc, block);
|
||||
farm.damageHoe(1, bc);
|
||||
return new HarvestResult(drops, bc);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PlantableFarmer implements IFarmerJoe {
|
||||
|
||||
ItemStack seedStack = farm.getSeedTypeInSuppliesFor(bc);
|
||||
if(seedStack == null) {
|
||||
farm.setNotification("noSeeds");
|
||||
farm.setNotification(TileFarmStation.NOTIFICATION_NO_SEEDS);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -72,10 +72,7 @@ public class PlantableFarmer implements IFarmerJoe {
|
||||
}
|
||||
|
||||
if(type == EnumPlantType.Crop) {
|
||||
if(!farm.tillBlock(bc)) {
|
||||
if(!farm.hasHoe()) {
|
||||
farm.setNotification("noHoe");
|
||||
}
|
||||
if(!farm.tillBlock(bc)) {
|
||||
return false;
|
||||
}
|
||||
return plantFromInventory(farm, bc, plantable);
|
||||
@@ -144,7 +141,11 @@ public class PlantableFarmer implements IFarmerJoe {
|
||||
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
if(!canHarvest(farm, bc, block, meta) || !farm.hasDefaultHarvestTool()) {
|
||||
if(!canHarvest(farm, bc, block, meta)) {
|
||||
return null;
|
||||
}
|
||||
if(!farm.hasHoe()) {
|
||||
farm.setNotification(TileFarmStation.NOTIFICATION_NO_HOE);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -154,7 +155,7 @@ public class PlantableFarmer implements IFarmerJoe {
|
||||
ItemStack removedPlantable = null;
|
||||
|
||||
ArrayList<ItemStack> drops = block.getDrops(worldObj, bc.x, bc.y, bc.z, meta, farm.getMaxLootingValue());
|
||||
farm.damageMaxLootingItem(1, bc, block);
|
||||
farm.damageHoe(1, bc);
|
||||
farm.actionPerformed(false);
|
||||
boolean removed = false;
|
||||
if(drops != null) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class StemFarmer extends CustomSeedFarmer {
|
||||
boolean done = false;
|
||||
do{
|
||||
harvestCoord = harvestCoord.getLocation(ForgeDirection.UP);
|
||||
if(plantedBlock == farm.getBlock(harvestCoord) && farm.hasDefaultHarvestTool()) {
|
||||
if(plantedBlock == farm.getBlock(harvestCoord) && farm.hasHoe()) {
|
||||
res.harvestedBlocks.add(harvestCoord);
|
||||
ArrayList<ItemStack> drops = plantedBlock.getDrops(farm.getWorldObj(), harvestCoord.x, harvestCoord.y, harvestCoord.z, meta, farm.getMaxLootingValue());
|
||||
if(drops != null) {
|
||||
@@ -55,7 +55,7 @@ public class StemFarmer extends CustomSeedFarmer {
|
||||
}
|
||||
|
||||
}
|
||||
farm.damageMaxLootingItem(1, harvestCoord, farm.getBlock(harvestCoord));
|
||||
farm.damageHoe(1, harvestCoord);
|
||||
farm.actionPerformed(false);
|
||||
farm.getWorldObj().setBlockToAir(harvestCoord.x, harvestCoord.y, harvestCoord.z);
|
||||
} else {
|
||||
|
||||
@@ -136,7 +136,7 @@ public class TreeFarmer implements IFarmerJoe {
|
||||
}
|
||||
|
||||
if (!farm.hasAxe()) {
|
||||
farm.setNotification("noAxe");
|
||||
farm.setNotification(TileFarmStation.NOTIFICATION_NO_AXE);
|
||||
}
|
||||
|
||||
res.harvestedBlocks.clear();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package crazypants.enderio.machine.spawner;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
@@ -296,7 +300,6 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity {
|
||||
for (int i = 0; i < spawnCount; ++i) {
|
||||
|
||||
Entity entity = EntityList.createEntityByName(getEntityNameToSpawn(), getSpawnerWorld());
|
||||
|
||||
if(entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user