Search in sources :

Example 1 with FarmingTool

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);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FarmingTool(crazypants.enderio.base.farming.FarmingTool) NNList(com.enderio.core.common.util.NNList) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

NNList (com.enderio.core.common.util.NNList)1 FarmingTool (crazypants.enderio.base.farming.FarmingTool)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 IShearable (net.minecraftforge.common.IShearable)1