Search in sources :

Example 1 with TileSapling

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

the class TreeHelper method plantSapling.

@Override
public boolean plantSapling(World world, ITree tree, GameProfile owner, int x, int y, int z) {
    boolean placed = world.setBlock(x, y, z, ForestryBlock.saplingGE.block(), 0, Defaults.FLAG_BLOCK_SYNCH);
    if (!placed) {
        return false;
    }
    if (!ForestryBlock.saplingGE.isBlockEqual(world, x, y, z)) {
        return false;
    }
    TileEntity tile = world.getTileEntity(x, y, z);
    if (!(tile instanceof TileSapling)) {
        world.setBlockToAir(x, y, z);
        return false;
    }
    TileSapling sapling = (TileSapling) tile;
    sapling.setTree(tree.copy());
    sapling.setOwner(owner);
    world.markBlockForUpdate(x, y, z);
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileSapling(forestry.arboriculture.gadgets.TileSapling)

Example 2 with TileSapling

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

the class EventHandlerArboriculture method handleBonemeal.

@SubscribeEvent
public void handleBonemeal(BonemealEvent event) {
    if (!Proxies.common.isSimulating(event.world)) {
        return;
    }
    TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
    if (tile instanceof TileSapling) {
        int result = ((TileSapling) tile).tryGrow(true);
        if (result == 1 || result == 2) {
            event.setResult(Result.ALLOW);
        }
    } else if (tile instanceof TileFruitPod) {
        if (((TileFruitPod) tile).canMature()) {
            ((TileFruitPod) tile).mature();
            event.setResult(Result.ALLOW);
        }
    } else if (tile instanceof IFruitBearer) {
        IFruitBearer bearer = (IFruitBearer) tile;
        if (bearer.getRipeness() < 1.0f) {
            bearer.addRipeness(1.0f);
            event.setResult(Result.ALLOW);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFruitBearer(forestry.api.genetics.IFruitBearer) TileSapling(forestry.arboriculture.gadgets.TileSapling) TileFruitPod(forestry.arboriculture.gadgets.TileFruitPod) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 3 with TileSapling

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

the class SaplingRenderHandler method renderWorldBlock.

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
    if (modelId != this.getRenderId()) {
        return false;
    }
    TileSapling tile = BlockSapling.getSaplingTile(world, x, y, z);
    if (tile == null || tile.getTree() == null) {
        return true;
    }
    IAlleleTreeSpecies species = tile.getTree().getGenome().getPrimary();
    renderCrossedSquares(species, world, block, x, y, z);
    renderLayer = 1;
    renderCrossedSquares(species, world, block, x, y, z);
    renderLayer = 0;
    return true;
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) TileSapling(forestry.arboriculture.gadgets.TileSapling)

Example 4 with TileSapling

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

the class GrowthProvider method hasSufficientSaplings.

protected boolean hasSufficientSaplings(ITreeGenome genome, World world, int xPos, int yPos, int zPos, int expectedGirth) {
    if (expectedGirth == 1) {
        return true;
    }
    int offset = (expectedGirth - 1) / 2;
    for (int x = xPos - offset; x < xPos - offset + expectedGirth; x++) {
        for (int z = zPos - offset; z < zPos - offset + expectedGirth; z++) {
            if (world.isAirBlock(x, yPos, z)) {
                return false;
            }
            TileEntity tile = world.getTileEntity(x, yPos, z);
            if (!(tile instanceof TileSapling)) {
                return false;
            }
            ITree tree = ((TileSapling) tile).getTree();
            if (tree == null || !tree.getGenome().getPrimary().getUID().equals(genome.getPrimary().getUID())) {
                return false;
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITree(forestry.api.arboriculture.ITree) TileSapling(forestry.arboriculture.gadgets.TileSapling)

Aggregations

TileSapling (forestry.arboriculture.gadgets.TileSapling)4 TileEntity (net.minecraft.tileentity.TileEntity)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)1 ITree (forestry.api.arboriculture.ITree)1 IFruitBearer (forestry.api.genetics.IFruitBearer)1 TileFruitPod (forestry.arboriculture.gadgets.TileFruitPod)1