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