Search in sources :

Example 1 with Gene

use of binnie.core.genetics.Gene 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 Gene

use of binnie.core.genetics.Gene in project Binnie by ForestryMC.

the class GeneItem method create.

@Nullable
public static GeneItem create(ItemStack stack) {
    NBTTagCompound tagCompound = stack.getTagCompound();
    if (tagCompound != null && tagCompound.hasKey("gene", Constants.NBT.TAG_COMPOUND)) {
        NBTTagCompound geneNbt = tagCompound.getCompoundTag("gene");
        Gene gene = Gene.create(geneNbt);
        return new GeneItem(gene);
    }
    return null;
}
Also used : Gene(binnie.core.genetics.Gene) IGene(binnie.core.api.genetics.IGene) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 3 with Gene

use of binnie.core.genetics.Gene in project Binnie by ForestryMC.

the class InoculatorRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, InoculatorRecipeWrapper recipeWrapper, IIngredients ingredients) {
    if (!splicer) {
        IDrawable tank = GeneticsJeiPlugin.drawables.getTank();
        IDrawable tankOverlay = GeneticsJeiPlugin.drawables.getTankOverlay();
        IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks();
        fluidStacks.init(Inoculator.TANK_VEKTOR, true, 1, 1, 16, 58, 100, false, tankOverlay);
        fluidStacks.setBackground(Inoculator.TANK_VEKTOR, tank);
        fluidStacks.set(ingredients);
    }
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    itemStacks.init(0, true, 22, 0);
    itemStacks.init(1, true, 42, 21);
    itemStacks.init(2, false, 92, 21);
    IDrawable slot = GeneticsJeiPlugin.guiHelper.getSlotDrawable();
    for (int i = 0; i <= 2; i++) {
        itemStacks.setBackground(i, slot);
    }
    recipeWrapper.setCurrentIngredients(itemStacks.getGuiIngredients());
    IFocus<?> focus = recipeLayout.getFocus();
    if (focus != null) {
        Object focusValue = focus.getValue();
        if (focusValue instanceof ItemStack) {
            ItemStack focusStack = (ItemStack) focusValue;
            if (AlleleManager.alleleRegistry.isIndividual(focusStack)) {
                if (focus.getMode() == IFocus.Mode.INPUT) {
                    ItemStack serum = recipeWrapper.getInputSerum();
                    ItemStack output = InoculatorLogic.applySerum(focusStack, serum);
                    itemStacks.set(0, serum);
                    itemStacks.set(1, focusStack);
                    itemStacks.set(2, output);
                    return;
                } else if (focus.getMode() == IFocus.Mode.OUTPUT) {
                    IIndividual individual = AlleleManager.alleleRegistry.getIndividual(focusStack);
                    if (individual != null) {
                        ISpeciesRoot speciesRoot = individual.getGenome().getSpeciesRoot();
                        IAlleleSpecies species = individual.getGenome().getPrimary();
                        ItemStack serum = ItemSerum.create(new Gene(species, speciesRoot.getSpeciesChromosomeType(), speciesRoot));
                        // set fully charged
                        serum.setItemDamage(0);
                        itemStacks.set(0, serum);
                        itemStacks.set(1, recipeWrapper.getWildcardTarget());
                        itemStacks.set(2, focusStack);
                        return;
                    }
                }
            } else if (focusStack.getItem() instanceof ItemSerum) {
                ItemStack input = recipeWrapper.getWildcardTarget();
                ItemStack output = InoculatorLogic.applySerum(input, focusStack);
                itemStacks.set(0, focusStack);
                itemStacks.set(1, input);
                itemStacks.set(2, output);
                return;
            }
        }
    }
    itemStacks.set(ingredients);
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) IGuiFluidStackGroup(mezz.jei.api.gui.IGuiFluidStackGroup) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) ItemSerum(binnie.genetics.item.ItemSerum) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) ItemStack(net.minecraft.item.ItemStack) IDrawable(mezz.jei.api.gui.IDrawable)

Example 4 with Gene

use of binnie.core.genetics.Gene in project Binnie by ForestryMC.

the class WindowGeneBank method initialiseClient.

@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    super.initialiseClient();
    this.addEventHandler(EventValueChanged.class, event -> {
        if (event.getValue() instanceof BreedingSystem) {
            WindowGeneBank.this.genes.setValue((IBreedingSystem) event.getValue());
        }
    });
    int x = 16;
    final int y = 32;
    new ControlPlayerInventory(this, x, y);
    x += 124;
    int boxX = x;
    final int geneBoxWidth = 120;
    new Panel(this, boxX + 24, 32, geneBoxWidth, 120, MinecraftGUI.PanelType.BLACK);
    new Panel(this, boxX + 24 + geneBoxWidth, 32, 14, 120, MinecraftGUI.PanelType.GRAY);
    final ControlScrollableContent<ControlGeneScroll> scroll = new ControlScrollableContent<>(this, boxX + 24 + 2, 34, geneBoxWidth + 10, 116, 12);
    final ControlTextEdit edit = new ControlTextEdit(this, boxX + 27 + geneBoxWidth - 70, 18, 80, 12);
    this.addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, edit, event -> {
        String value = event.getValue();
        if (value == null) {
            value = "";
        }
        WindowGeneBank.this.genes.setFilter(value);
    });
    this.genes = new ControlGeneScroll(scroll, 1, 1, geneBoxWidth, 116);
    scroll.setScrollableContent(this.genes);
    this.genes.setGenes(Binnie.GENETICS.getFirstActiveSystem());
    final ControlTabBar<IBreedingSystem> tabBar = new GeneBankTabBar(this, boxX);
    tabBar.setValue(Binnie.GENETICS.getFirstActiveSystem());
    boxX -= 8;
    final ControlTabBar<String> infoTabs = new ControlTabBar<>(this, boxX + 8, 160, 16, 50, Alignment.LEFT, Arrays.asList("Info", "Stats", "Ranking"));
    final Panel panelProject = new Panel(this, boxX + 24, 160, geneBoxWidth + 20, 50, MinecraftGUI.PanelType.BLACK);
    int totalGenes = 0;
    int seqGenes = 0;
    for (final IBreedingSystem system : Binnie.GENETICS.getActiveSystems()) {
        final GeneTracker tracker = GeneTracker.getTracker(this.getWorld(), this.getUsername());
        final Map<IChromosomeType, List<IAllele>> genes = Binnie.GENETICS.getChromosomeMap(system.getSpeciesRoot());
        for (final Map.Entry<IChromosomeType, List<IAllele>> entry : genes.entrySet()) {
            totalGenes += entry.getValue().size();
            for (final IAllele allele : entry.getValue()) {
                final Gene gene = new Gene(allele, entry.getKey(), system.getSpeciesRoot());
                if (tracker.isSequenced(gene)) {
                    ++seqGenes;
                }
            }
        }
    }
    new ControlText(panelProject, new Point(4, 4), "§nFull Genome Project");
    new ControlText(panelProject, new Point(4, 18), "§oSequenced §r" + seqGenes + '/' + totalGenes + " §oGenes");
}
Also used : BreedingSystem(binnie.core.genetics.BreedingSystem) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) ControlText(binnie.core.gui.controls.ControlText) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) Point(binnie.core.gui.geometry.Point) Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) IAllele(forestry.api.genetics.IAllele) Panel(binnie.core.gui.window.Panel) Gene(binnie.core.genetics.Gene) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType) GeneTracker(binnie.genetics.genetics.GeneTracker) Map(java.util.Map) ControlScrollableContent(binnie.core.gui.controls.scroll.ControlScrollableContent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with Gene

use of binnie.core.genetics.Gene in project Binnie by ForestryMC.

the class WindowGeneBank method receiveGuiNBTOnServer.

@Override
public void receiveGuiNBTOnServer(EntityPlayer player, String name, NBTTagCompound nbt) {
    super.receiveGuiNBTOnServer(player, name, nbt);
    if (name.equals("gene-select")) {
        Gene gene = new Gene(nbt.getCompoundTag("gene"));
        ItemStack held = this.getHeldItemStack();
        ItemStack converted = Engineering.addGene(held, gene);
        this.getPlayer().inventory.setItemStack(converted);
        this.getPlayer().inventory.markDirty();
        if (this.getPlayer() instanceof EntityPlayerMP) {
            ((EntityPlayerMP) this.getPlayer()).sendContainerToPlayer(player.inventoryContainer);
        }
    }
}
Also used : Gene(binnie.core.genetics.Gene) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Gene (binnie.core.genetics.Gene)18 IAllele (forestry.api.genetics.IAllele)11 IChromosomeType (forestry.api.genetics.IChromosomeType)11 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)10 ItemStack (net.minecraft.item.ItemStack)8 IGene (binnie.core.api.genetics.IGene)7 IIndividual (forestry.api.genetics.IIndividual)6 ArrayList (java.util.ArrayList)6 List (java.util.List)4 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)3 Map (java.util.Map)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BreedingSystem (binnie.core.genetics.BreedingSystem)2 ControlText (binnie.core.gui.controls.ControlText)2 Point (binnie.core.gui.geometry.Point)2 ControlPlayerInventory (binnie.core.gui.minecraft.control.ControlPlayerInventory)2 Panel (binnie.core.gui.window.Panel)2 GeneTracker (binnie.genetics.genetics.GeneTracker)2 IGeneItem (binnie.genetics.genetics.IGeneItem)2 IGenome (forestry.api.genetics.IGenome)2