Search in sources :

Example 1 with TileCocoon

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) TileCocoon(forestry.lepidopterology.tiles.TileCocoon)

Example 2 with TileCocoon

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;
}
Also used : IButterfly(forestry.api.lepidopterology.IButterfly) TileCocoon(forestry.lepidopterology.tiles.TileCocoon) ItemStack(net.minecraft.item.ItemStack)

Example 3 with TileCocoon

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();
}
Also used : TileCocoon(forestry.lepidopterology.tiles.TileCocoon)

Example 4 with TileCocoon

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockRegistryLepidopterology(forestry.lepidopterology.blocks.BlockRegistryLepidopterology) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TileCocoon(forestry.lepidopterology.tiles.TileCocoon)

Aggregations

TileCocoon (forestry.lepidopterology.tiles.TileCocoon)4 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 IButterfly (forestry.api.lepidopterology.IButterfly)1 BlockRegistryLepidopterology (forestry.lepidopterology.blocks.BlockRegistryLepidopterology)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1