Search in sources :

Example 1 with IToolScoop

use of forestry.api.core.IToolScoop in project ForestryMC by ForestryMC.

the class BlockForestryLeaves method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    TileLeaves leaves = TileUtil.getTile(worldIn, pos, TileLeaves.class);
    if (leaves != null) {
        IButterfly caterpillar = leaves.getCaterpillar();
        ItemStack heldItem = playerIn.getHeldItem(hand);
        if (heldItem.getItem() instanceof IToolScoop && caterpillar != null) {
            ItemStack butterfly = ButterflyManager.butterflyRoot.getMemberStack(caterpillar, EnumFlutterType.CATERPILLAR);
            ItemStackUtil.dropItemStackAsEntity(butterfly, worldIn, pos);
            leaves.setCaterpillar(null);
            return true;
        }
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
Also used : IButterfly(forestry.api.lepidopterology.IButterfly) TileLeaves(forestry.arboriculture.tiles.TileLeaves) IToolScoop(forestry.api.core.IToolScoop) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IToolScoop

use of forestry.api.core.IToolScoop in project ForestryMC by ForestryMC.

the class EntityButterfly method processInteract.

/* INTERACTION */
@Override
protected boolean processInteract(EntityPlayer player, EnumHand hand) {
    if (isDead) {
        return false;
    }
    ItemStack stack = player.getHeldItem(hand);
    if ((stack.getItem() instanceof IToolScoop)) {
        if (!world.isRemote) {
            IButterflyRoot root = contained.getGenome().getPrimary().getRoot();
            ILepidopteristTracker tracker = root.getBreedingTracker(world, player.getGameProfile());
            ItemStack itemStack = root.getMemberStack(contained.copy(), EnumFlutterType.BUTTERFLY);
            tracker.registerCatch(contained);
            ItemStackUtil.dropItemStackAsEntity(itemStack, world, posX, posY, posZ);
            setDead();
        } else {
            player.swingArm(hand);
        }
        return true;
    }
    return false;
}
Also used : IButterflyRoot(forestry.api.lepidopterology.IButterflyRoot) ILepidopteristTracker(forestry.api.lepidopterology.ILepidopteristTracker) IToolScoop(forestry.api.core.IToolScoop) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IToolScoop (forestry.api.core.IToolScoop)2 ItemStack (net.minecraft.item.ItemStack)2 IButterfly (forestry.api.lepidopterology.IButterfly)1 IButterflyRoot (forestry.api.lepidopterology.IButterflyRoot)1 ILepidopteristTracker (forestry.api.lepidopterology.ILepidopteristTracker)1 TileLeaves (forestry.arboriculture.tiles.TileLeaves)1