use of forestry.api.genetics.ISpeciesRoot 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);
}
use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.
the class BreedingSystem method calculateArrays.
@Override
public void calculateArrays() {
ISpeciesRoot speciesRoot = getSpeciesRoot();
calculateAlleles(speciesRoot);
calculateBranches(speciesRoot);
calculateMutations(speciesRoot);
}
use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.
the class Gene method readFromNBT.
@Override
public void readFromNBT(final NBTTagCompound nbt) {
this.allele = AlleleManager.alleleRegistry.getAllele(nbt.getString("allele"));
String rootKey = nbt.getString("root");
ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(rootKey);
Preconditions.checkArgument(root != null, "Could not find root: %s", rootKey);
this.root = root;
final int chromoID = nbt.getByte("chromo");
Preconditions.checkArgument(chromoID >= 0 && chromoID < this.root.getKaryotype().length, "Invalid chromosomeId: %s", chromoID);
this.chromosome = this.root.getKaryotype()[chromoID];
}
use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.
the class ManagerGenetics method loadAlleles.
private void loadAlleles() {
this.invalidChromosomeTypes.clear();
for (IBreedingSystem system : BREEDING_SYSTEMS.values()) {
ISpeciesRoot root = system.getSpeciesRoot();
Map<IChromosomeType, List<IAllele>> chromosomeMap = new LinkedHashMap<>();
for (IChromosomeType chromosome : root.getKaryotype()) {
TreeSet<IAllele> alleles = new TreeSet<>(new ComparatorAllele());
for (IIndividual individual : root.getIndividualTemplates()) {
IGenome genome = individual.getGenome();
IAllele activeAllele = genome.getActiveAllele(chromosome);
IAllele inactiveAllele = genome.getInactiveAllele(chromosome);
if (chromosome.getAlleleClass().isInstance(activeAllele)) {
alleles.add(activeAllele);
}
if (!chromosome.getAlleleClass().isInstance(inactiveAllele)) {
continue;
}
alleles.add(inactiveAllele);
}
system.addExtraAlleles(chromosome, alleles);
if (alleles.size() == 0) {
this.invalidChromosomeTypes.add(chromosome);
} else {
final List<IAllele> alleleList = new ArrayList<>(alleles);
chromosomeMap.put(chromosome, alleleList);
}
}
this.chromosomeArray.put(root, chromosomeMap);
}
}
use of forestry.api.genetics.ISpeciesRoot in project Binnie by ForestryMC.
the class Splicer method setGene.
public static void setGene(IGene gene, ItemStack target, boolean setPrimary, boolean setSecondary) {
int chromosomeID = gene.getChromosome().ordinal();
Class<? extends IAllele> cls = gene.getChromosome().getAlleleClass();
if (!cls.isInstance(gene.getAllele())) {
return;
}
NBTTagCompound targetTag = target.getTagCompound();
NBTTagCompound mate = null;
if (targetTag != null && targetTag.hasKey("Mate")) {
mate = targetTag.getCompoundTag("Mate").copy();
}
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(target);
Preconditions.checkNotNull(speciesRoot);
IIndividual original = speciesRoot.getMember(target);
Preconditions.checkNotNull(original);
IChromosome[] chromosomes = original.getGenome().getChromosomes();
IAllele[] primaryAlleles = new IAllele[chromosomes.length];
IAllele[] secondaryAlleles = new IAllele[chromosomes.length];
for (int i = 0; i < chromosomes.length; i++) {
IChromosome chromosome = chromosomes[i];
if (i == chromosomeID && setPrimary) {
primaryAlleles[i] = gene.getAllele();
} else {
primaryAlleles[i] = chromosome.getPrimaryAllele();
}
if (i == chromosomeID && setSecondary) {
secondaryAlleles[i] = gene.getAllele();
} else {
secondaryAlleles[i] = chromosome.getSecondaryAllele();
}
}
IIndividual individual = speciesRoot.templateAsIndividual(primaryAlleles, secondaryAlleles);
if (original.isAnalyzed()) {
individual.analyze();
}
if (original instanceof IBee) {
IBee individualBee = (IBee) individual;
IBee originalBee = (IBee) original;
individualBee.setIsNatural(originalBee.isNatural());
}
NBTTagCompound nbt = new NBTTagCompound();
individual.writeToNBT(nbt);
if (mate != null) {
nbt.setTag("Mate", mate);
}
target.setTagCompound(nbt);
}
Aggregations