Search in sources :

Example 1 with IButterflyNursery

use of forestry.api.lepidopterology.IButterflyNursery in project ForestryMC by ForestryMC.

the class ItemButterflyGE method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    ItemStack stack = player.getHeldItem(hand);
    IButterfly flutter = ButterflyManager.butterflyRoot.getMember(stack);
    IBlockState blockState = world.getBlockState(pos);
    if (type == EnumFlutterType.COCOON) {
        pos = ButterflyManager.butterflyRoot.plantCocoon(world, pos, flutter, player.getGameProfile(), getAge(stack), true);
        if (pos != BlockPos.ORIGIN) {
            PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, world.getBlockState(pos));
            NetworkUtil.sendNetworkPacket(packet, pos, world);
            if (!player.capabilities.isCreativeMode) {
                stack.shrink(1);
            }
            return EnumActionResult.SUCCESS;
        } else {
            return EnumActionResult.PASS;
        }
    } else if (type == EnumFlutterType.CATERPILLAR) {
        IButterflyNursery nursery = GeneticsUtil.getOrCreateNursery(player.getGameProfile(), world, pos, true);
        if (nursery != null) {
            if (!nursery.canNurse(flutter)) {
                return EnumActionResult.PASS;
            }
            nursery.setCaterpillar(flutter);
            PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
            NetworkUtil.sendNetworkPacket(packet, pos, world);
            if (!player.capabilities.isCreativeMode) {
                stack.shrink(1);
            }
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.PASS;
    } else {
        return EnumActionResult.PASS;
    }
}
Also used : IButterflyNursery(forestry.api.lepidopterology.IButterflyNursery) IButterfly(forestry.api.lepidopterology.IButterfly) IBlockState(net.minecraft.block.state.IBlockState) PacketFXSignal(forestry.core.network.packets.PacketFXSignal) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IButterflyNursery

use of forestry.api.lepidopterology.IButterflyNursery in project ForestryMC by ForestryMC.

the class ButterflyRoot method isPositionValid.

public boolean isPositionValid(World world, BlockPos pos, IButterfly caterpillar, GameProfile gameProfile, boolean createNursery) {
    IBlockState blockState = world.getBlockState(pos);
    if (BlockUtil.canReplace(blockState, world, pos)) {
        BlockPos nurseryPos = pos.up();
        IButterflyNursery nursery = GeneticsUtil.getNursery(world, nurseryPos);
        if (isNurseryValid(nursery, caterpillar, gameProfile)) {
            return true;
        } else if (createNursery && GeneticsUtil.canCreateNursery(world, nurseryPos)) {
            nursery = GeneticsUtil.getOrCreateNursery(gameProfile, world, nurseryPos, false);
            return isNurseryValid(nursery, caterpillar, gameProfile);
        }
    }
    return false;
}
Also used : IButterflyNursery(forestry.api.lepidopterology.IButterflyNursery) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IButterflyNursery (forestry.api.lepidopterology.IButterflyNursery)2 IBlockState (net.minecraft.block.state.IBlockState)2 IButterfly (forestry.api.lepidopterology.IButterfly)1 PacketFXSignal (forestry.core.network.packets.PacketFXSignal)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1