Search in sources :

Example 6 with IButterfly

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

the class TileCocoon method readData.

@Override
public void readData(PacketBufferForestry data) throws IOException {
    String speciesUID = data.readString();
    IButterfly caterpillar = getButterfly(speciesUID);
    setCaterpillar(caterpillar);
    age = data.readInt();
}
Also used : IButterfly(forestry.api.lepidopterology.IButterfly)

Example 7 with IButterfly

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

the class ItemButterflyGE method getItemStackDisplayName.

@Override
public String getItemStackDisplayName(ItemStack itemstack) {
    if (itemstack.getTagCompound() == null) {
        return super.getItemStackDisplayName(itemstack);
    }
    IButterfly individual = ButterflyManager.butterflyRoot.getMember(itemstack);
    String customKey = "for.butterflies.custom." + type.getName() + "." + individual.getGenome().getPrimary().getUnlocalizedName().replace("butterflies.species.", "");
    if (Translator.canTranslateToLocal(customKey)) {
        return Translator.translateToLocal(customKey);
    }
    String grammar = Translator.translateToLocal("for.butterflies.grammar." + type.getName());
    String speciesString = individual.getDisplayName();
    String typeString = Translator.translateToLocal("for.butterflies.grammar." + type.getName() + ".type");
    return grammar.replaceAll("%SPECIES", speciesString).replaceAll("%TYPE", typeString);
}
Also used : IButterfly(forestry.api.lepidopterology.IButterfly)

Example 8 with IButterfly

use of forestry.api.lepidopterology.IButterfly 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 9 with IButterfly

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

the class BlockCocoon method getPickBlock.

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    TileCocoon tile = TileUtil.getTile(world, pos, TileCocoon.class);
    if (tile == null) {
        return ItemStack.EMPTY;
    }
    IButterfly caterpillar = tile.getCaterpillar();
    int age = tile.getAge();
    ItemStack stack = ButterflyManager.butterflyRoot.getMemberStack(caterpillar, EnumFlutterType.COCOON);
    if (!stack.isEmpty() && stack.getTagCompound() != null) {
        stack.getTagCompound().setInteger(ItemButterflyGE.NBT_AGE, age);
    }
    return stack;
}
Also used : IButterfly(forestry.api.lepidopterology.IButterfly) TileCocoon(forestry.lepidopterology.tiles.TileCocoon) ItemStack(net.minecraft.item.ItemStack)

Example 10 with IButterfly

use of forestry.api.lepidopterology.IButterfly 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)

Aggregations

IButterfly (forestry.api.lepidopterology.IButterfly)17 ItemStack (net.minecraft.item.ItemStack)4 IEntityButterfly (forestry.api.lepidopterology.IEntityButterfly)3 GuiAlyzer (forestry.core.gui.GuiAlyzer)3 TextLayoutHelper (forestry.core.gui.TextLayoutHelper)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 EntityButterfly (forestry.lepidopterology.entities.EntityButterfly)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 IToolScoop (forestry.api.core.IToolScoop)1 IAllele (forestry.api.genetics.IAllele)1 IAlleleFlowers (forestry.api.genetics.IAlleleFlowers)1 IAlleleInteger (forestry.api.genetics.IAlleleInteger)1 IAlleleTolerance (forestry.api.genetics.IAlleleTolerance)1 IChromosome (forestry.api.genetics.IChromosome)1 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)1 IButterflyGenome (forestry.api.lepidopterology.IButterflyGenome)1 IButterflyNursery (forestry.api.lepidopterology.IButterflyNursery)1 IButterflyRoot (forestry.api.lepidopterology.IButterflyRoot)1 TileLeaves (forestry.arboriculture.tiles.TileLeaves)1 AlleleBoolean (forestry.core.genetics.alleles.AlleleBoolean)1