Search in sources :

Example 26 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class FarmableGE method plantSaplingAt.

@Override
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
    ITreeRoot treeRoot = TreeManager.treeRoot;
    ITree tree = treeRoot.getMember(germling);
    return tree != null && treeRoot.plantSapling(world, tree, player.getGameProfile(), pos);
}
Also used : ITreeRoot(forestry.api.arboriculture.ITreeRoot) ITree(forestry.api.arboriculture.ITree)

Example 27 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class BlockAbstractLeaves method onSheared.

@Override
public final List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
    ITree tree = getTree(world, pos);
    if (tree == null) {
        tree = TreeDefinition.Oak.getIndividual();
    }
    ItemStack decorativeLeaves = tree.getGenome().getDecorativeLeaves();
    if (decorativeLeaves.isEmpty()) {
        return Collections.emptyList();
    } else {
        return Collections.singletonList(decorativeLeaves);
    }
}
Also used : ITree(forestry.api.arboriculture.ITree) ItemStack(net.minecraft.item.ItemStack)

Example 28 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class Tree method createOffspring.

private ITree createOffspring(World world, ITreeGenome mate, @Nullable GameProfile playerProfile, BlockPos pos) {
    IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length];
    IChromosome[] parent1 = genome.getChromosomes();
    IChromosome[] parent2 = mate.getChromosomes();
    // Check for mutation. Replace one of the parents with the mutation
    // template if mutation occured.
    IChromosome[] mutated = mutateSpecies(world, playerProfile, pos, genome, mate);
    if (mutated == null) {
        mutated = mutateSpecies(world, playerProfile, pos, mate, genome);
    }
    if (mutated != null) {
        return new Tree(new TreeGenome(mutated));
    }
    for (int i = 0; i < parent1.length; i++) {
        if (parent1[i] != null && parent2[i] != null) {
            chromosomes[i] = Chromosome.inheritChromosome(world.rand, parent1[i], parent2[i]);
        }
    }
    return new Tree(new TreeGenome(chromosomes));
}
Also used : IChromosome(forestry.api.genetics.IChromosome) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 29 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class Tree method copy.

@Override
public ITree copy() {
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    this.writeToNBT(nbttagcompound);
    return new Tree(nbttagcompound);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ITree(forestry.api.arboriculture.ITree)

Example 30 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class TreeAlyzerPlugin method drawAnalyticsPage2.

@SideOnly(Side.CLIENT)
@Override
public void drawAnalyticsPage2(GuiScreen gui, ItemStack itemStack) {
    if (gui instanceof GuiAlyzer) {
        GuiAlyzer guiAlyzer = (GuiAlyzer) gui;
        ITree tree = TreeManager.treeRoot.getMember(itemStack);
        if (tree == null) {
            return;
        }
        TextLayoutHelper textLayout = guiAlyzer.getTextLayout();
        textLayout.startPage(GuiAlyzer.COLUMN_0, GuiAlyzer.COLUMN_1, GuiAlyzer.COLUMN_2);
        int speciesDominance0 = guiAlyzer.getColorCoding(tree.getGenome().getPrimary().isDominant());
        int speciesDominance1 = guiAlyzer.getColorCoding(tree.getGenome().getSecondary().isDominant());
        textLayout.drawLine(Translator.translateToLocal("for.gui.active"), GuiAlyzer.COLUMN_1);
        textLayout.drawLine(Translator.translateToLocal("for.gui.inactive"), GuiAlyzer.COLUMN_2);
        textLayout.newLine();
        textLayout.newLine();
        String yes = Translator.translateToLocal("for.yes");
        String no = Translator.translateToLocal("for.no");
        String fireproofActive = StringUtil.readableBoolean(tree.getGenome().getFireproof(), yes, no);
        String fireproofInactive = StringUtil.readableBoolean(((AlleleBoolean) tree.getGenome().getInactiveAllele(EnumTreeChromosome.FIREPROOF)).getValue(), yes, no);
        guiAlyzer.drawRow(Translator.translateToLocal("for.gui.fireproof"), fireproofActive, fireproofInactive, tree, EnumTreeChromosome.FIREPROOF);
        textLayout.newLine();
        textLayout.drawLine(Translator.translateToLocal("for.gui.native"), GuiAlyzer.COLUMN_0);
        textLayout.drawLine(Translator.translateToLocal("for.gui." + tree.getGenome().getPrimary().getPlantType().toString().toLowerCase(Locale.ENGLISH)), GuiAlyzer.COLUMN_1, speciesDominance0);
        textLayout.drawLine(Translator.translateToLocal("for.gui." + tree.getGenome().getSecondary().getPlantType().toString().toLowerCase(Locale.ENGLISH)), GuiAlyzer.COLUMN_2, speciesDominance1);
        textLayout.newLine();
        // FRUITS
        textLayout.drawLine(Translator.translateToLocal("for.gui.supports"), GuiAlyzer.COLUMN_0);
        List<IFruitFamily> families0 = new ArrayList<>(tree.getGenome().getPrimary().getSuitableFruit());
        List<IFruitFamily> families1 = new ArrayList<>(tree.getGenome().getSecondary().getSuitableFruit());
        int max = Math.max(families0.size(), families1.size());
        for (int i = 0; i < max; i++) {
            if (i > 0) {
                textLayout.newLineCompressed();
            }
            if (families0.size() > i) {
                textLayout.drawLine(families0.get(i).getName(), GuiAlyzer.COLUMN_1, speciesDominance0);
            }
            if (families1.size() > i) {
                textLayout.drawLine(families1.get(i).getName(), GuiAlyzer.COLUMN_2, speciesDominance1);
            }
        }
        textLayout.newLine();
        int fruitDominance0 = guiAlyzer.getColorCoding(tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).isDominant());
        int fruitDominance1 = guiAlyzer.getColorCoding(tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS).isDominant());
        textLayout.drawLine(Translator.translateToLocal("for.gui.fruits"), GuiAlyzer.COLUMN_0);
        String strike = "";
        IAllele fruit0 = tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS);
        if (!tree.canBearFruit() && fruit0 != AlleleFruits.fruitNone) {
            strike = TextFormatting.STRIKETHROUGH.toString();
        }
        textLayout.drawLine(strike + tree.getGenome().getFruitProvider().getDescription(), GuiAlyzer.COLUMN_1, fruitDominance0);
        strike = "";
        IAlleleFruit fruit1 = (IAlleleFruit) tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS);
        if (!tree.getGenome().getSecondary().getSuitableFruit().contains(fruit1.getProvider().getFamily()) && fruit1 != AlleleFruits.fruitNone) {
            strike = TextFormatting.STRIKETHROUGH.toString();
        }
        textLayout.drawLine(strike + fruit1.getProvider().getDescription(), GuiAlyzer.COLUMN_2, fruitDominance1);
        textLayout.newLine();
        textLayout.drawLine(Translator.translateToLocal("for.gui.family"), GuiAlyzer.COLUMN_0);
        IFruitFamily primary = tree.getGenome().getFruitProvider().getFamily();
        IFruitFamily secondary = ((IAlleleFruit) tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS)).getProvider().getFamily();
        if (primary != null && !primary.getUID().equals(EnumFruitFamily.NONE.getUID())) {
            textLayout.drawLine(primary.getName(), GuiAlyzer.COLUMN_1, fruitDominance0);
        }
        if (secondary != null && !secondary.getUID().equals(EnumFruitFamily.NONE.getUID())) {
            textLayout.drawLine(secondary.getName(), GuiAlyzer.COLUMN_2, fruitDominance1);
        }
        textLayout.endPage();
    }
}
Also used : TextLayoutHelper(forestry.core.gui.TextLayoutHelper) IAllele(forestry.api.genetics.IAllele) IFruitFamily(forestry.api.genetics.IFruitFamily) ArrayList(java.util.ArrayList) ITree(forestry.api.arboriculture.ITree) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit) GuiAlyzer(forestry.core.gui.GuiAlyzer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ITree (forestry.api.arboriculture.ITree)33 ItemStack (net.minecraft.item.ItemStack)9 ITreeGenome (forestry.api.arboriculture.ITreeGenome)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)4 IFruitProvider (forestry.api.arboriculture.IFruitProvider)4 IAllele (forestry.api.genetics.IAllele)4 EnumGermlingType (forestry.api.arboriculture.EnumGermlingType)3 IAlleleFruit (forestry.api.arboriculture.IAlleleFruit)3 TileSapling (forestry.arboriculture.tiles.TileSapling)3 GuiAlyzer (forestry.core.gui.GuiAlyzer)3 TextLayoutHelper (forestry.core.gui.TextLayoutHelper)3 TileLeaves (forestry.arboriculture.tiles.TileLeaves)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 IBlockState (net.minecraft.block.state.IBlockState)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 BlockPos (net.minecraft.util.math.BlockPos)2 Biome (net.minecraft.world.biome.Biome)2 WorldGenerator (net.minecraft.world.gen.feature.WorldGenerator)2