Fix wrong behavior of berry bush harvester

This commit is contained in:
tterrag1098 committed 2014-12-30 16:31:21 -05:00
1 parent 8843604edb
commit a75bcd1855
1 file changed
+31 -19
@@ -18,7 +18,7 @@ public class NaturaBerryFarmer extends PickableFarmer {
@Override
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
if(block != getPlantedBlock()) {
return null;
}
@@ -26,28 +26,33 @@ public class NaturaBerryFarmer extends PickableFarmer {
farm.setNotification(TileFarmStation.NOTIFICATION_NO_HOE);
return null;
}
IHarvestResult res = new HarvestResult();
IHarvestResult res = new HarvestResult();
BlockCoord checkBlock = bc;
for(int i=0; i < 5 && farm.hasHoe(); i++) {
for (int i = 0; i < 5 && farm.hasHoe(); i++) {
meta = farm.getBlockMeta(checkBlock);
IHarvestResult blockRes = super.harvestBlock(farm, checkBlock, block, meta);
if(blockRes != null) {
res.getHarvestedBlocks().add(checkBlock);
List<EntityItem> addToDrops = blockRes.getDrops();
for(EntityItem stack : addToDrops) {
res.getDrops().add(stack);
block = farm.getBlock(checkBlock);
if(super.canHarvest(farm, bc, block, meta)) { // redundant check because our canHarvest checks all 5 blocks so a bush may be invalid in the stack of 5
IHarvestResult blockRes = super.harvestBlock(farm, checkBlock, block, meta);
if(blockRes != null) {
res.getHarvestedBlocks().add(checkBlock);
List<EntityItem> addToDrops = blockRes.getDrops();
for (EntityItem stack : addToDrops) {
res.getDrops().add(stack);
}
}
}
checkBlock = checkBlock.getLocation(ForgeDirection.UP);
}
if(res.getHarvestedBlocks().isEmpty()) {
return null;
}
}
return res;
}
@@ -56,11 +61,18 @@ public class NaturaBerryFarmer extends PickableFarmer {
if(!Config.farmEssenceBerriesEnabled && "tile.ore.berries.two".equals(block.getUnlocalizedName()) && meta == grownBlockMeta) {
return false;
}
BlockCoord checkBlock = bc;
meta = farm.getBlockMeta(checkBlock);
block = checkBlock.getBlock(farm.getWorldObj());
return super.canHarvest(farm, checkBlock, block, meta);
for (int i = 0; i < 5; i++) {
meta = farm.getBlockMeta(checkBlock);
block = checkBlock.getBlock(farm.getWorldObj());
if(super.canHarvest(farm, checkBlock, block, meta)) {
return true;
}
checkBlock = checkBlock.getLocation(ForgeDirection.UP);
}
return false;
}
}