Search in sources :

Example 1 with TileSapling

use of forestry.arboriculture.tiles.TileSapling in project ForestryMC by ForestryMC.

the class TreeRoot method plantSapling.

@Override
public boolean plantSapling(World world, ITree tree, GameProfile owner, BlockPos pos) {
    BlockRegistryArboriculture blocks = ModuleArboriculture.getBlocks();
    IBlockState state = blocks.saplingGE.getDefaultState().withProperty(BlockSapling.TREE, tree.getGenome().getPrimary());
    boolean placed = world.setBlockState(pos, state);
    if (!placed) {
        return false;
    }
    IBlockState blockState = world.getBlockState(pos);
    Block block = blockState.getBlock();
    if (blocks.saplingGE != block) {
        return false;
    }
    TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
    if (sapling == null) {
        world.setBlockToAir(pos);
        return false;
    }
    sapling.setTree(tree.copy());
    sapling.getOwnerHandler().setOwner(owner);
    PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState);
    NetworkUtil.sendNetworkPacket(packet, pos, world);
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockRegistryArboriculture(forestry.arboriculture.blocks.BlockRegistryArboriculture) Block(net.minecraft.block.Block) PacketFXSignal(forestry.core.network.packets.PacketFXSignal) TileSapling(forestry.arboriculture.tiles.TileSapling)

Example 2 with TileSapling

use of forestry.arboriculture.tiles.TileSapling in project ForestryMC by ForestryMC.

the class BlockSapling method canBlockStay.

/* PLANTING */
public static boolean canBlockStay(IBlockAccess world, BlockPos pos) {
    TileSapling tile = TileUtil.getTile(world, pos, TileSapling.class);
    if (tile == null) {
        return false;
    }
    ITree tree = tile.getTree();
    return tree != null && tree.canStay(world, pos);
}
Also used : ITree(forestry.api.arboriculture.ITree) TileSapling(forestry.arboriculture.tiles.TileSapling)

Example 3 with TileSapling

use of forestry.arboriculture.tiles.TileSapling in project ForestryMC by ForestryMC.

the class TreeGrowthHelper method isSapling.

private static boolean isSapling(ITreeGenome genome, World world, BlockPos pos) {
    if (!world.isBlockLoaded(pos)) {
        return false;
    }
    if (world.isAirBlock(pos)) {
        return false;
    }
    TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
    if (sapling == null) {
        return false;
    }
    ITree tree = sapling.getTree();
    return tree != null && tree.getGenome().getPrimary().getUID().equals(genome.getPrimary().getUID());
}
Also used : ITree(forestry.api.arboriculture.ITree) TileSapling(forestry.arboriculture.tiles.TileSapling)

Aggregations

TileSapling (forestry.arboriculture.tiles.TileSapling)3 ITree (forestry.api.arboriculture.ITree)2 BlockRegistryArboriculture (forestry.arboriculture.blocks.BlockRegistryArboriculture)1 PacketFXSignal (forestry.core.network.packets.PacketFXSignal)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1