use of crazypants.enderio.base.farming.FarmingTool in project EnderIO by SleepyTrousers.
the class TreeFarmer method harvestSingleBlock.
void harvestSingleBlock(@Nonnull IFarmer farm, @Nonnull final World world, @Nonnull final HarvestResult result, @Nonnull final BlockPos harvestPos) {
float chance = 1.0F;
NNList<ItemStack> drops = new NNList<>();
final IBlockState state = farm.getBlockState(harvestPos);
final Block blk = state.getBlock();
if (blk instanceof IShearable && hasShears && ((shearCount / result.getHarvestedBlocks().size() + noShearingPercentage) < 100)) {
drops.addAll(((IShearable) blk).onSheared(farm.getTool(FarmingTool.SHEARS), world, harvestPos, 0));
shearCount += 100;
farm.registerAction(FarmingAction.HARVEST, FarmingTool.SHEARS, state, harvestPos);
hasShears = farm.hasTool(FarmingTool.SHEARS);
if (!hasShears) {
farm.setNotification(FarmNotification.NO_SHEARS);
}
} else {
FarmingTool tool = isWood(blk) || !hasHoe ? FarmingTool.AXE : FarmingTool.HOE;
blk.getDrops(drops, world, harvestPos, state, fortune);
EntityPlayerMP joe = farm.startUsingItem(tool);
chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, harvestPos, state, fortune, chance, false, joe);
farm.registerAction(FarmingAction.HARVEST, tool, state, harvestPos);
NNList.wrap(farm.endUsingItem(tool)).apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack drop) {
result.getDrops().add(new EntityItem(world, harvestPos.getX() + 0.5, harvestPos.getY() + 0.5, harvestPos.getZ() + 0.5, drop.copy()));
}
});
if (tool == FarmingTool.AXE) {
hasAxe = farm.hasTool(FarmingTool.AXE);
if (!hasAxe) {
farm.setNotification(FarmNotification.NO_AXE);
}
} else {
hasHoe = farm.hasTool(FarmingTool.HOE);
if (!hasHoe) {
farm.setNotification(FarmNotification.NO_HOE);
}
}
}
BlockPos farmPos = farm.getLocation();
for (ItemStack drop : drops) {
if (world.rand.nextFloat() <= chance) {
result.getDrops().add(new EntityItem(world, farmPos.getX() + 0.5, farmPos.getY() + 0.5, farmPos.getZ() + 0.5, drop.copy()));
}
}
farm.getWorld().setBlockToAir(harvestPos);
}
Aggregations