Search in sources :

Example 16 with ISpeciesRoot

use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.

the class WindowGenesis method initialiseClient.

@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    new ControlPlayerInventory(this);
    this.setTitle(I18N.localise("binniecore.gui.genesis.title"));
    final ControlTabBar<IBreedingSystem> tabSystems = new GenesisTabSystems(this);
    this.root = Binnie.GENETICS.getActiveSystems().iterator().next().getSpeciesRoot();
    this.template = this.root.getDefaultTemplate();
    final Area one = new Area(32, 28, 170, 100);
    final Area two = new Area(214, 28, 100, 100);
    new Panel(this, one.outset(1), MinecraftGUI.PanelType.BLACK);
    new Panel(this, two.outset(1), MinecraftGUI.PanelType.BLACK);
    this.geneList = new GeneList(this, one);
    this.geneOptions = new GeneOptions(this, two);
    tabSystems.addEventHandler(EventValueChanged.class, EventHandlerOrigin.SELF, tabSystems, event -> {
        Object value = event.getValue();
        if (!(value instanceof BreedingSystem)) {
            return;
        }
        IBreedingSystem breedingSystem = (IBreedingSystem) value;
        root = breedingSystem.getSpeciesRoot();
        template = root.getDefaultTemplate();
        refreshTemplate(null);
    });
    this.geneList.addEventHandler(EventValueChanged.class, EventHandlerOrigin.SELF, this.geneList, event -> {
        Object value = event.getValue();
        if (!(value instanceof Gene)) {
            return;
        }
        Gene gene = (Gene) value;
        Map<IChromosomeType, List<IAllele>> map = Binnie.GENETICS.getChromosomeMap(root);
        List<Gene> options = new ArrayList<>();
        IChromosomeType chromosomeType = gene.getChromosome();
        List<IAllele> alleles = map.get(chromosomeType);
        for (IAllele allele : alleles) {
            options.add(new Gene(allele, chromosomeType, root));
        }
        geneOptions.setOptions(options);
    });
    this.geneOptions.addEventHandler(EventValueChanged.class, EventHandlerOrigin.SELF, this.geneOptions, event -> {
        Object value = event.getValue();
        if (!(value instanceof Gene)) {
            return;
        }
        Gene gene = (Gene) value;
        IChromosomeType chromosomeType = gene.getChromosome();
        ISpeciesRoot speciesRoot = gene.getSpeciesRoot();
        IAllele allele = gene.getAllele();
        if (chromosomeType == speciesRoot.getSpeciesChromosomeType()) {
            template = speciesRoot.getTemplate(allele.getUID());
        } else {
            template[chromosomeType.ordinal()] = allele;
        }
        refreshTemplate(chromosomeType);
    });
    this.panelPickup = new Panel(this, 16, 140, 60, 42, MinecraftGUI.PanelType.BLACK);
    this.refreshTemplate(null);
}
Also used : BreedingSystem(binnie.core.genetics.BreedingSystem) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) IAllele(forestry.api.genetics.IAllele) Panel(binnie.core.gui.window.Panel) Area(binnie.core.gui.geometry.Area) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Gene(binnie.core.genetics.Gene) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) ArrayList(java.util.ArrayList) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 17 with ISpeciesRoot

use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.

the class WindowFieldKit method refreshSpecies.

private void refreshSpecies() {
    final ItemStack item = this.getWindowInventory().getStackInSlot(INDIVIDUAL_SLOT);
    if (item.isEmpty() || !AlleleManager.alleleRegistry.isIndividual(item)) {
        return;
    }
    final IIndividual ind = AlleleManager.alleleRegistry.getIndividual(item);
    if (ind == null) {
        return;
    }
    final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(item);
    if (root == null) {
        return;
    }
    IBreedingSystem system = Binnie.GENETICS.getSystem(root);
    this.chromo.setSystem(system);
    final Random rand = new Random();
    this.info.clear();
    for (final IChromosomeType type : root.getKaryotype()) {
        if (!Binnie.GENETICS.isInvalidChromosome(type)) {
            final IAllele allele = ind.getGenome().getActiveAllele(type);
            final List<String> infos = new ArrayList<>();
            int i = 0;
            for (String pref = root.getUID() + ".fieldkit." + type.getName().toLowerCase() + '.'; I18N.canLocalise(pref + i); ++i) {
                infos.add(I18N.localise(pref + i));
            }
            String text = system.getAlleleName(type, allele);
            if (!infos.isEmpty()) {
                text = infos.get(rand.nextInt(infos.size()));
            }
            this.info.put(type, text);
            this.chromo.setSystem(system);
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) Random(java.util.Random) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack) Point(binnie.core.gui.geometry.Point)

Example 18 with ISpeciesRoot

use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.

the class TreeBreedingSystem method getChance.

@Override
public float getChance(final IMutation mutation, final EntityPlayer player, final IAlleleSpecies firstSpecies, final IAlleleSpecies secondSpecies) {
    ISpeciesRoot speciesRoot = this.getSpeciesRoot();
    final ITreeGenome genome0 = (ITreeGenome) speciesRoot.templateAsGenome(speciesRoot.getTemplate(firstSpecies));
    final ITreeGenome genome2 = (ITreeGenome) speciesRoot.templateAsGenome(speciesRoot.getTemplate(secondSpecies));
    return ((ITreeMutation) mutation).getChance(player.world, player.getPosition(), (IAlleleTreeSpecies) firstSpecies, (IAlleleTreeSpecies) secondSpecies, genome0, genome2);
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) ITreeMutation(forestry.api.arboriculture.ITreeMutation) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 19 with ISpeciesRoot

use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.

the class GenepoolRecipeMaker method create.

public static List<GenepoolRecipeWrapper> create() {
    List<GenepoolRecipeWrapper> recipes = new ArrayList<>();
    Collection<ISpeciesRoot> roots = AlleleManager.alleleRegistry.getSpeciesRoot().values();
    for (ISpeciesRoot root : roots) {
        ISpeciesType[] speciesTypes = root.getIconType().getClass().getEnumConstants();
        IAllele[] defaultTemplate = root.getDefaultTemplate();
        IIndividual individual = root.templateAsIndividual(defaultTemplate);
        for (ISpeciesType speciesType : speciesTypes) {
            ItemStack memberStack = root.getMemberStack(individual, speciesType);
            memberStack.setItemDamage(OreDictionary.WILDCARD_VALUE);
            GenepoolRecipeWrapper recipeWrapper = new GenepoolRecipeWrapper(memberStack);
            recipes.add(recipeWrapper);
        }
    }
    return recipes;
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) ISpeciesType(forestry.api.genetics.ISpeciesType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 20 with ISpeciesRoot

use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.

the class WindowAnalyst method initialiseServer.

@Override
public void initialiseServer() {
    for (IBreedingSystem system : Binnie.GENETICS.getActiveSystems()) {
        ISpeciesRoot root = system.getSpeciesRoot();
        if (root != null) {
            IBreedingTracker tracker = root.getBreedingTracker(getWorld(), getUsername());
            if (tracker != null) {
                tracker.synchToPlayer(getPlayer());
            }
        }
    }
    // create slots
    getWindowInventory().createSlot(0);
    getWindowInventory().createSlot(1);
    setupValidators();
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IBreedingTracker(forestry.api.genetics.IBreedingTracker) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem)

Aggregations

ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)49 IIndividual (forestry.api.genetics.IIndividual)30 ItemStack (net.minecraft.item.ItemStack)20 IAllele (forestry.api.genetics.IAllele)17 IChromosomeType (forestry.api.genetics.IChromosomeType)11 Gene (binnie.core.genetics.Gene)10 IBreedingTracker (forestry.api.genetics.IBreedingTracker)7 IGenome (forestry.api.genetics.IGenome)7 ArrayList (java.util.ArrayList)7 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)6 ISpeciesType (forestry.api.genetics.ISpeciesType)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 IGene (binnie.core.api.genetics.IGene)4 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)4 IFilterData (forestry.api.genetics.IFilterData)3 List (java.util.List)3 Random (java.util.Random)3 Nullable (javax.annotation.Nullable)3 IGeneItem (binnie.genetics.genetics.IGeneItem)2 ForestryEvent (forestry.api.core.ForestryEvent)2