Search in sources :

Example 1 with ITreeGenome

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());
}
Also used : ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome) IFruitProvider(forestry.api.arboriculture.IFruitProvider)

Example 2 with ITreeGenome

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());
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IBlockState(net.minecraft.block.state.IBlockState) ITreekeepingMode(forestry.api.arboriculture.ITreekeepingMode) ILeafTickHandler(forestry.api.arboriculture.ILeafTickHandler) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 3 with ITreeGenome

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);
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) TextureMap(net.minecraft.client.renderer.texture.TextureMap) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) ILeafSpriteProvider(forestry.api.arboriculture.ILeafSpriteProvider) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 4 with ITreeGenome

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);
}
Also used : BlockDecorativeLeaves(forestry.arboriculture.blocks.BlockDecorativeLeaves) TreeDefinition(forestry.arboriculture.genetics.TreeDefinition) ITreeGenome(forestry.api.arboriculture.ITreeGenome) IFruitProvider(forestry.api.arboriculture.IFruitProvider) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with ITreeGenome

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);
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) Biome(net.minecraft.world.biome.Biome) IGrowthProvider(forestry.api.arboriculture.IGrowthProvider) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Aggregations

ITreeGenome (forestry.api.arboriculture.ITreeGenome)28 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)14 IFruitProvider (forestry.api.arboriculture.IFruitProvider)11 ItemStack (net.minecraft.item.ItemStack)9 ITree (forestry.api.arboriculture.ITree)8 ILeafSpriteProvider (forestry.api.arboriculture.ILeafSpriteProvider)7 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 ArrayList (java.util.ArrayList)5 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 TextureMap (net.minecraft.client.renderer.texture.TextureMap)5 ResourceLocation (net.minecraft.util.ResourceLocation)5 ETTreeDefinition (binnie.extratrees.genetics.ETTreeDefinition)3 TreeDefinition (forestry.arboriculture.genetics.TreeDefinition)3 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)2 ITreeMutation (forestry.api.arboriculture.ITreeMutation)2 IAllele (forestry.api.genetics.IAllele)2 IChromosome (forestry.api.genetics.IChromosome)2 ControlText (binnie.core.gui.controls.ControlText)1 Control (binnie.core.gui.controls.core.Control)1