use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.
the class TileLeaves method readData.
@Override
public void readData(PacketBufferForestry data) throws IOException {
// this is called instead of super.readData, be careful!
String speciesUID = data.readString();
byte leafState = data.readByte();
isFruitLeaf = (leafState & hasFruitFlag) > 0;
isPollinatedState = (leafState & isPollinatedFlag) > 0;
String fruitAlleleUID = null;
if (isFruitLeaf) {
fruitAlleleUID = data.readString();
colourFruits = data.readInt();
}
IAllele[] treeTemplate = TreeManager.treeRoot.getTemplate(speciesUID);
if (treeTemplate != null) {
if (fruitAlleleUID != null) {
IAllele fruitAllele = AlleleManager.alleleRegistry.getAllele(fruitAlleleUID);
if (fruitAllele instanceof IAlleleFruit) {
treeTemplate[EnumTreeChromosome.FRUITS.ordinal()] = fruitAllele;
}
}
ITree tree = TreeManager.treeRoot.templateAsIndividual(treeTemplate);
if (isPollinatedState) {
tree.mate(tree);
}
setTree(tree);
world.markBlockRangeForRenderUpdate(getPos(), getPos());
}
}
use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.
the class TileLeaves method determineFruitColour.
private int determineFruitColour() {
ITree tree = getTree();
if (tree == null) {
tree = TreeDefinition.Cherry.getIndividual();
}
ITreeGenome genome = tree.getGenome();
IFruitProvider fruit = genome.getFruitProvider();
return fruit.getColour(genome, world, getPos(), getRipeningTime());
}
use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.
the class TileLeaves method onBlockTick.
@Override
public void onBlockTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
ITree tree = getTree();
if (tree == null) {
return;
}
ITreeGenome genome = tree.getGenome();
IAlleleTreeSpecies primary = genome.getPrimary();
if (!checkedForConversionToDefaultLeaves) {
if (shouldConvertToDefaultLeaves()) {
IBlockState defaultLeaves = ModuleArboriculture.getBlocks().getDefaultLeaves(primary.getUID());
worldIn.setBlockState(getPos(), defaultLeaves);
return;
}
checkedForConversionToDefaultLeaves = true;
}
boolean isDestroyed = isDestroyed(tree, damage);
for (ILeafTickHandler tickHandler : primary.getRoot().getLeafTickHandlers()) {
if (tickHandler.onRandomLeafTick(tree, world, rand, getPos(), isDestroyed)) {
return;
}
}
if (isDestroyed) {
return;
}
if (damage > 0) {
damage--;
}
if (hasFruit() && getRipeningTime() < ripeningPeriod) {
ITreekeepingMode treekeepingMode = TreeManager.treeRoot.getTreekeepingMode(world);
float sappinessModifier = treekeepingMode.getSappinessModifier(genome, 1f);
float sappiness = genome.getSappiness() * sappinessModifier;
if (rand.nextFloat() < sappiness) {
ripeningTime++;
sendNetworkUpdateRipening();
}
}
if (caterpillar != null) {
matureCaterpillar();
}
effectData = tree.doEffect(effectData, world, getPos());
}
use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.
the class TileLeaves method mateWith.
@Override
public void mateWith(IIndividual individual) {
if (individual instanceof ITree) {
ITree tree = getTree();
if (tree == null || world == null) {
return;
}
tree.mate((ITree) individual);
if (!world.isRemote) {
sendNetworkUpdate();
}
}
}
use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.
the class TileLeaves method readFromNBT.
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
ripeningTime = nbttagcompound.getShort("RT");
damage = nbttagcompound.getInteger("ENC");
if (nbttagcompound.hasKey("CATER")) {
maturationTime = nbttagcompound.getInteger("CATMAT");
caterpillar = ButterflyManager.butterflyRoot.getMember(nbttagcompound.getCompoundTag("CATER"));
}
ITree tree = getTree();
if (tree != null) {
setTree(tree);
}
}
Aggregations