use of forestry.lepidopterology.tiles.TileCocoon in project ForestryMC by ForestryMC.
the class CocoonDecorator method setCocoon.
private static boolean setCocoon(World world, BlockPos pos, IButterfly butterfly) {
Block cocoonBlock = ModuleLepidopterology.getBlocks().solidCocoon;
boolean placed = world.setBlockState(pos, cocoonBlock.getDefaultState(), Constants.FLAG_BLOCK_SYNC);
if (!placed) {
return false;
}
IBlockState state = world.getBlockState(pos);
if (!Block.isEqualTo(cocoonBlock, state.getBlock())) {
return false;
}
TileCocoon cocoon = TileUtil.getTile(world, pos, TileCocoon.class);
if (cocoon != null) {
cocoon.setCaterpillar(butterfly);
} else {
return false;
}
cocoonBlock.onBlockAdded(world, pos, state);
world.markBlockRangeForRenderUpdate(pos, pos);
return true;
}
use of forestry.lepidopterology.tiles.TileCocoon 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.lepidopterology.tiles.TileCocoon in project ForestryMC by ForestryMC.
the class BlockCocoon method updateTick.
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
TileCocoon tileCocoon = TileUtil.getTile(world, pos, TileCocoon.class);
if (tileCocoon == null) {
return;
}
if (tileCocoon.isInvalid()) {
return;
}
tileCocoon.onBlockTick();
}
use of forestry.lepidopterology.tiles.TileCocoon in project ForestryMC by ForestryMC.
the class ButterflyRoot method plantCocoon.
@Override
public BlockPos plantCocoon(World world, BlockPos coordinates, IButterfly caterpillar, GameProfile owner, int age, boolean createNursery) {
if (caterpillar == null) {
return BlockPos.ORIGIN;
}
BlockRegistryLepidopterology blocks = ModuleLepidopterology.getBlocks();
BlockPos pos = getValidCocoonPos(world, coordinates, caterpillar, owner, createNursery);
if (pos == BlockPos.ORIGIN) {
return pos;
}
IBlockState state = blocks.cocoon.getDefaultState();
boolean placed = world.setBlockState(pos, state);
if (!placed) {
return BlockPos.ORIGIN;
}
Block block = world.getBlockState(pos).getBlock();
if (blocks.cocoon != block) {
return BlockPos.ORIGIN;
}
TileCocoon cocoon = TileUtil.getTile(world, pos, TileCocoon.class);
if (cocoon == null) {
world.setBlockToAir(pos);
return BlockPos.ORIGIN;
}
cocoon.setCaterpillar(caterpillar);
cocoon.getOwnerHandler().setOwner(owner);
cocoon.setAge(age);
return pos;
}
Aggregations