use of forestry.api.arboriculture.ITreeGenome 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.ITreeGenome 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.ITreeGenome in project ForestryMC by ForestryMC.
the class ModelDecorativeLeaves method bakeBlock.
@Override
protected void bakeBlock(BlockDecorativeLeaves block, TreeDefinition treeDefinition, IModelBaker baker, boolean inventory) {
TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
ITreeGenome genome = treeDefinition.getGenome();
IAlleleTreeSpecies species = genome.getPrimary();
ILeafSpriteProvider leafSpriteProvider = species.getLeafSpriteProvider();
ResourceLocation leafSpriteLocation = leafSpriteProvider.getSprite(false, Proxies.render.fancyGraphicsEnabled());
TextureAtlasSprite leafSprite = map.getAtlasSprite(leafSpriteLocation.toString());
// Render the plain leaf block.
baker.addBlockModel(null, leafSprite, BlockAbstractLeaves.FOLIAGE_COLOR_INDEX);
// Render overlay for fruit leaves.
ResourceLocation fruitSpriteLocation = genome.getFruitProvider().getDecorativeSprite();
if (fruitSpriteLocation != null) {
TextureAtlasSprite fruitSprite = map.getAtlasSprite(fruitSpriteLocation.toString());
baker.addBlockModel(null, fruitSprite, BlockAbstractLeaves.FRUIT_COLOR_INDEX);
}
// Set the particle sprite
baker.setParticleSprite(leafSprite);
}
use of forestry.api.arboriculture.ITreeGenome in project ForestryMC by ForestryMC.
the class ItemBlockDecorativeLeaves method getColorFromItemstack.
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemstack(ItemStack itemStack, int renderPass) {
int meta = itemStack.getMetadata();
BlockDecorativeLeaves block = getBlock();
TreeDefinition treeDefinition = block.getTreeType(meta);
ITreeGenome genome = treeDefinition.getGenome();
if (renderPass == BlockAbstractLeaves.FRUIT_COLOR_INDEX) {
IFruitProvider fruitProvider = genome.getFruitProvider();
return fruitProvider.getDecorativeColor();
}
return genome.getPrimary().getLeafSpriteProvider().getColor(false);
}
use of forestry.api.arboriculture.ITreeGenome in project ForestryMC by ForestryMC.
the class TreeDecorator method generateBiomeCache.
private static void generateBiomeCache(World world, Random rand) {
for (IAlleleTreeSpecies species : getSpecies()) {
IAllele[] template = TreeManager.treeRoot.getTemplate(species);
ITreeGenome genome = TreeManager.treeRoot.templateAsGenome(template);
ITree tree = TreeManager.treeRoot.getTree(world, genome);
IGrowthProvider growthProvider = species.getGrowthProvider();
for (Biome biome : Biome.REGISTRY) {
Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
if (growthProvider.isBiomeValid(tree, biome)) {
trees.add(tree);
}
}
}
}
Aggregations