Search in sources :

Example 1 with IBreedingSystem

use of binnie.core.api.genetics.IBreedingSystem 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 2 with IBreedingSystem

use of binnie.core.api.genetics.IBreedingSystem in project Binnie by ForestryMC.

the class WindowGenesis method refreshPickup.

private void refreshPickup() {
    this.panelPickup.deleteAllChildren();
    int i = 0;
    IBreedingSystem system = Binnie.GENETICS.getSystem(this.root);
    for (ISpeciesType type : system.getActiveTypes()) {
        IIndividual ind = this.root.templateAsIndividual(this.template);
        ind.analyze();
        ItemStack stack = this.root.getMemberStack(ind, type);
        ControlItemDisplay display = new ControlItemDisplay(this.panelPickup, 4 + i % 3 * 18, 4 + i / 3 * 18);
        display.setItemStack(stack);
        display.setTooltip();
        display.addEventHandler(EventMouse.Down.class, EventHandlerOrigin.SELF, display, event -> {
            NBTTagCompound nbt = new NBTTagCompound();
            stack.writeToNBT(nbt);
            Window.get(event.getOrigin()).sendClientAction(ACTION_GENESIS, nbt);
        });
        ++i;
    }
}
Also used : ControlItemDisplay(binnie.core.gui.minecraft.control.ControlItemDisplay) IIndividual(forestry.api.genetics.IIndividual) ISpeciesType(forestry.api.genetics.ISpeciesType) EventMouse(binnie.core.gui.events.EventMouse) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IBreedingSystem

use of binnie.core.api.genetics.IBreedingSystem 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 4 with IBreedingSystem

use of binnie.core.api.genetics.IBreedingSystem in project Binnie by ForestryMC.

the class ControlIndividualDisplay method onRenderForeground.

@Override
@SideOnly(Side.CLIENT)
public void onRenderForeground(int guiWidth, int guiHeight) {
    TextureAtlasSprite icon = null;
    if (this.species == null) {
        return;
    }
    IBreedingSystem system = Binnie.GENETICS.getSystem(this.species.getRoot());
    switch(this.discovered) {
        case SHOW:
            {
                super.onRenderForeground(guiWidth, guiHeight);
                return;
            }
        case DISCOVERED:
            {
                icon = system.getDiscoveredIcon();
                break;
            }
        case UNDISCOVERED:
            {
                icon = system.getUndiscoveredIcon();
                break;
            }
    }
    if (icon != null) {
        RenderUtil.drawGuiSprite(Point.ZERO, icon);
    }
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with IBreedingSystem

use of binnie.core.api.genetics.IBreedingSystem in project Binnie by ForestryMC.

the class ControlMutationBox method setSpecies.

public void setSpecies(@Nullable final IAlleleSpecies species) {
    if (species != this.species) {
        this.species = species;
        this.movePercentage(-100.0f);
        final IBreedingSystem system = ((WindowAbstractDatabase) this.getTopParent()).getBreedingSystem();
        final List<IMutation> discovered = system.getDiscoveredMutations(Window.get(this).getWorld(), Window.get(this).getUsername());
        if (species != null) {
            if (this.type == Type.Resultant) {
                this.setOptions(system.getResultantMutations(species));
            } else {
                final List<IMutation> mutations = system.getFurtherMutations(species);
                int i = 0;
                while (i < mutations.size()) {
                    final IMutation mutation = mutations.get(i);
                    if (!discovered.contains(mutation) && !((IAlleleSpecies) mutation.getTemplate()[0]).isCounted()) {
                        mutations.remove(i);
                    } else {
                        ++i;
                    }
                }
                this.setOptions(mutations);
            }
        }
    }
}
Also used : IMutation(forestry.api.genetics.IMutation) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem)

Aggregations

IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)22 ArrayList (java.util.ArrayList)8 IAllele (forestry.api.genetics.IAllele)7 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)6 IChromosomeType (forestry.api.genetics.IChromosomeType)5 IIndividual (forestry.api.genetics.IIndividual)5 ItemStack (net.minecraft.item.ItemStack)5 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)4 Gene (binnie.core.genetics.Gene)3 Point (binnie.core.gui.geometry.Point)3 ControlPlayerInventory (binnie.core.gui.minecraft.control.ControlPlayerInventory)3 List (java.util.List)3 IGene (binnie.core.api.genetics.IGene)2 BreedingSystem (binnie.core.genetics.BreedingSystem)2 ControlText (binnie.core.gui.controls.ControlText)2 Control (binnie.core.gui.controls.core.Control)2 ControlScrollableContent (binnie.core.gui.controls.scroll.ControlScrollableContent)2 Area (binnie.core.gui.geometry.Area)2 ControlItemDisplay (binnie.core.gui.minecraft.control.ControlItemDisplay)2