Search in sources :

Example 1 with ItemGrafter

use of forestry.arboriculture.items.ItemGrafter in project ForestryMC by ForestryMC.

the class ModuleArboriculture method onHarvestDropsEvent.

@SubscribeEvent
public void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent event) {
    IBlockState state = event.getState();
    Block block = state.getBlock();
    if (block instanceof BlockLeaves && !(block instanceof BlockForestryLeaves)) {
        EntityPlayer player = event.getHarvester();
        if (player != null) {
            ItemStack harvestingTool = player.getHeldItemMainhand();
            if (harvestingTool.getItem() instanceof ItemGrafter) {
                if (event.getDrops().isEmpty()) {
                    World world = event.getWorld();
                    Item itemDropped = block.getItemDropped(state, world.rand, 3);
                    if (itemDropped != Items.AIR) {
                        event.getDrops().add(new ItemStack(itemDropped, 1, block.damageDropped(state)));
                    }
                }
                harvestingTool.damageItem(1, player);
                if (harvestingTool.isEmpty()) {
                    net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, harvestingTool, EnumHand.MAIN_HAND);
                }
            }
        }
    }
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) BlockLeaves(net.minecraft.block.BlockLeaves) BlockForestryLeaves(forestry.arboriculture.blocks.BlockForestryLeaves) ItemGrafter(forestry.arboriculture.items.ItemGrafter) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

BlockForestryLeaves (forestry.arboriculture.blocks.BlockForestryLeaves)1 ItemGrafter (forestry.arboriculture.items.ItemGrafter)1 Block (net.minecraft.block.Block)1 BlockLeaves (net.minecraft.block.BlockLeaves)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1