Added support for multi-layer natura berry bushes.

This commit is contained in:
CrazyPants committed 2014-05-20 15:12:29 +08:00
1 parent 584ead10bb
commit d5978e0213
1 file changed
+30 -26
@@ -21,39 +21,43 @@ public class NaturaBerryFarmer extends PickableFarmer {
if(block != getPlantedBlock()) {
return null;
}
BlockCoord upLoc = bc.getLocation(ForgeDirection.UP);
Block aboveBlock = farm.getBlock(upLoc);
ArrayList<ItemStack> drops = null;
if(aboveBlock == getPlantedBlock()) {
drops = block.getDrops(farm.getWorld(), upLoc.x, upLoc.y, upLoc.z, meta, farm.getMaxLootingValue());
farm.damageMaxLootingItem();
farm.actionPerformed();
farm.getWorld().setBlockToAir(upLoc.x, upLoc.y, upLoc.z);
}
IHarvestResult res = super.harvestBlock(farm, bc, block, meta);
if(drops != null) {
if(res == null) {
res = new HarvestResult();
}
res.getHarvestedBlocks().add(upLoc);
List<EntityItem> addToDrops = res.getDrops();
for(ItemStack stack : drops) {
addToDrops.add(new EntityItem(farm.getWorld(), upLoc.x + 0.5, upLoc.y + 1, upLoc.z + 0.5, stack.copy()));
IHarvestResult res = new HarvestResult();
BlockCoord checkBlock = bc;
for(int i=0; i < 5; 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);
}
}
checkBlock = checkBlock.getLocation(ForgeDirection.UP);
}
if(res.getHarvestedBlocks().isEmpty()) {
return null;
}
return res;
}
@Override
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
BlockCoord upLoc = bc.getLocation(ForgeDirection.UP);
Block aboveBlock = farm.getBlock(upLoc);
if(aboveBlock == getPlantedBlock()) {
return true;
}
return super.canHarvest(farm, bc, block, meta);
BlockCoord checkBlock = bc;
for(int i=0; i < 5; i++) {
meta = farm.getBlockMeta(checkBlock);
if(super.canHarvest(farm, checkBlock, block, meta)) {
return true;
}
checkBlock = checkBlock.getLocation(ForgeDirection.UP);
}
return false;
}
}