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