Search in sources :

Example 1 with IAlleleFruit

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

the class TileFruitPod method readData.

@Override
public void readData(PacketBufferForestry data) throws IOException {
    IAllele stored = AlleleManager.alleleRegistry.getAllele(data.readString());
    if (stored instanceof IAlleleFruit) {
        allele = (IAlleleFruit) stored;
    } else {
        allele = defaultAllele;
    }
    world.markBlockRangeForRenderUpdate(getPos(), getPos());
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit)

Example 2 with IAlleleFruit

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

the class TileFruitPod method readFromNBT.

/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    IAllele stored = AlleleManager.alleleRegistry.getAllele(nbttagcompound.getString("UID"));
    if (stored instanceof IAlleleFruit) {
        allele = (IAlleleFruit) stored;
    } else {
        allele = defaultAllele;
    }
    maturity = nbttagcompound.getShort("MT");
    sappiness = nbttagcompound.getFloat("SP");
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit)

Example 3 with IAlleleFruit

use of forestry.api.arboriculture.IAlleleFruit 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());
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit) ITree(forestry.api.arboriculture.ITree)

Example 4 with IAlleleFruit

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

the class TreeDatabaseTab method createElements.

@Override
public void createElements(IGuiElementHelper elementHelper, ITree tree, ItemStack itemStack) {
    IAlleleTreeSpecies primarySpecies = tree.getGenome().getPrimary();
    boolean active = tab == EnumDatabaseTab.ACTIVE_SPECIES;
    IAlleleTreeSpecies species = active ? primarySpecies : tree.getGenome().getSecondary();
    int speciesColor = elementHelper.factory().getColorCoding(species.isDominant());
    elementHelper.addText(Translator.translateToLocal("for.gui.database.tab." + tab.name().toLowerCase() + ".name"), GuiElementAlignment.CENTER, 0xcfb53b);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.species"), tree, EnumTreeChromosome.SPECIES, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.saplings"), tree, EnumTreeChromosome.FERTILITY, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.maturity"), tree, EnumTreeChromosome.MATURATION, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.height"), tree, EnumTreeChromosome.HEIGHT, active);
    IAlleleInteger girth = (IAlleleInteger) (active ? tree.getGenome().getActiveAllele(EnumTreeChromosome.GIRTH) : tree.getGenome().getInactiveAllele(EnumTreeChromosome.GIRTH));
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.girth"), GuiElementAlignment.CENTER);
    elementHelper.addText(String.format("%sx%s", girth.getValue(), girth.getValue()), GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(girth.isDominant()));
    elementHelper.addAllele(Translator.translateToLocal("for.gui.yield"), tree, EnumTreeChromosome.YIELD, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.sappiness"), tree, EnumTreeChromosome.SAPPINESS, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.effect"), tree, EnumTreeChromosome.EFFECT, active);
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.native"), GuiElementAlignment.CENTER);
    elementHelper.addText(Translator.translateToLocal("for.gui." + tree.getGenome().getPrimary().getPlantType().toString().toLowerCase(Locale.ENGLISH)), GuiElementAlignment.CENTER, speciesColor);
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.supports"), GuiElementAlignment.CENTER);
    List<IFruitFamily> families = new ArrayList<>(tree.getGenome().getPrimary().getSuitableFruit());
    for (IFruitFamily fruitFamily : families) {
        elementHelper.addText(fruitFamily.getName(), GuiElementAlignment.CENTER, speciesColor);
    }
    IAlleleFruit fruit = (IAlleleFruit) (active ? tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS) : tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS));
    int colorCoding = elementHelper.factory().getColorCoding(tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).isDominant());
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.fruits"), GuiElementAlignment.CENTER);
    String strike = "";
    if (!species.getSuitableFruit().contains(fruit.getProvider().getFamily()) && fruit != AlleleFruits.fruitNone) {
        strike = TextFormatting.STRIKETHROUGH.toString();
    }
    elementHelper.addText(strike + fruit.getProvider().getDescription(), GuiElementAlignment.CENTER, colorCoding);
    IFruitFamily family = fruit.getProvider().getFamily();
    if (family != null && !family.getUID().equals(EnumFruitFamily.NONE.getUID())) {
        elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.family"), GuiElementAlignment.CENTER);
        elementHelper.addText(family.getName(), GuiElementAlignment.CENTER, colorCoding);
    }
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IAlleleInteger(forestry.api.genetics.IAlleleInteger) IFruitFamily(forestry.api.genetics.IFruitFamily) ArrayList(java.util.ArrayList) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit)

Example 5 with IAlleleFruit

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

the class TreeRoot method getFruitProvidersForFruitFamily.

@Override
public Collection<IFruitProvider> getFruitProvidersForFruitFamily(IFruitFamily fruitFamily) {
    if (providersForFamilies.isEmpty()) {
        @SuppressWarnings("unchecked") Collection<IAlleleFruit> fruitAlleles = (Collection<IAlleleFruit>) (Object) AlleleManager.alleleRegistry.getRegisteredAlleles(EnumTreeChromosome.FRUITS);
        for (IAlleleFruit alleleFruit : fruitAlleles) {
            IFruitProvider fruitProvider = alleleFruit.getProvider();
            Collection<IFruitProvider> fruitProviders = providersForFamilies.computeIfAbsent(fruitProvider.getFamily(), k -> new ArrayList<>());
            fruitProviders.add(fruitProvider);
        }
    }
    return providersForFamilies.computeIfAbsent(fruitFamily, k -> new ArrayList<>());
}
Also used : Collection(java.util.Collection) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit) IFruitProvider(forestry.api.arboriculture.IFruitProvider)

Aggregations

IAlleleFruit (forestry.api.arboriculture.IAlleleFruit)9 IAllele (forestry.api.genetics.IAllele)4 ArrayList (java.util.ArrayList)4 ITree (forestry.api.arboriculture.ITree)2 IFruitFamily (forestry.api.genetics.IFruitFamily)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)1 IFruitProvider (forestry.api.arboriculture.IFruitProvider)1 IWoodType (forestry.api.arboriculture.IWoodType)1 WoodBlockKind (forestry.api.arboriculture.WoodBlockKind)1 IAlleleInteger (forestry.api.genetics.IAlleleInteger)1 BlockFruitPod (forestry.arboriculture.blocks.BlockFruitPod)1 GuiAlyzer (forestry.core.gui.GuiAlyzer)1 TextLayoutHelper (forestry.core.gui.TextLayoutHelper)1 Collection (java.util.Collection)1 IBlockState (net.minecraft.block.state.IBlockState)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1