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();
}
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);
}
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;
}
}
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;
}
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);
}
Aggregations