use of binnie.core.genetics.Gene in project Binnie by ForestryMC.
the class WindowGenesis method refreshTemplate.
private void refreshTemplate(@Nullable IChromosomeType selection) {
List<Gene> genes = new ArrayList<>();
IChromosomeType[] chromosomeTypes = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(new IChromosomeType[0]);
for (IChromosomeType type : chromosomeTypes) {
IAllele allele = this.template[type.ordinal()];
if (allele == null) {
throw new NullPointerException("Allele missing for Chromosome " + type.getName());
}
genes.add(new Gene(allele, type, this.root));
}
geneList.setOptions(genes);
if (selection != null) {
this.geneList.setValue(new Gene(this.template[selection.ordinal()], selection, this.root));
} else {
this.geneOptions.setOptions(new ArrayList<>());
}
this.refreshPickup();
}
use of binnie.core.genetics.Gene in project Binnie by ForestryMC.
the class IsolatorLogic method onFinishTask.
@Override
protected void onFinishTask() {
super.onFinishTask();
final Random rand = this.getMachine().getWorld().rand;
MachineUtil util = this.getUtil();
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(util.getStack(Isolator.SLOT_TARGET));
if (root == null) {
return;
}
final IIndividual individual = root.getMember(util.getStack(Isolator.SLOT_TARGET));
if (individual == null) {
return;
}
IChromosomeType[] karyotype = root.getKaryotype();
IChromosomeType chromosome = karyotype[rand.nextInt(karyotype.length)];
IGenome genome = individual.getGenome();
IAllele allele = rand.nextBoolean() ? genome.getActiveAllele(chromosome) : genome.getInactiveAllele(chromosome);
Gene gene = Gene.create(allele, chromosome, root);
final ItemStack serum = ItemSequence.create(gene);
util.setStack(Isolator.SLOT_RESULUT, serum);
util.decreaseStack(Isolator.SLOT_SEQUENCER_VIAL, 1);
if (rand.nextFloat() < TARGET_LOSS_CHANCE) {
util.decreaseStack(Isolator.SLOT_TARGET, 1);
}
util.drainTank(Isolator.TANK_ETHANOL, ETHANOL_PER_PROCESS);
}
use of binnie.core.genetics.Gene in project Binnie by ForestryMC.
the class ToleranceSystem method alter.
public ItemStack alter(final ItemStack stack, final ItemStack acc) {
final Random rand = new Random();
final float effect = this.type.getEffect(acc);
if (rand.nextFloat() > Math.abs(effect)) {
return stack;
}
final IIndividual member = AlleleManager.alleleRegistry.getIndividual(stack);
final IGenome genome = member.getGenome();
final IAlleleTolerance tolAllele = (IAlleleTolerance) genome.getActiveAllele(this.chromosomeType);
final Tolerance tol = Tolerance.get(tolAllele.getValue());
final Tolerance newTol = Acclimatiser.alterTolerance(tol, effect);
if (rand.nextFloat() > 1.0f / (-newTol.getBounds()[0] + newTol.getBounds()[1])) {
return stack;
}
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
boolean setPrimary = rand.nextBoolean();
boolean setSecondary = !setPrimary;
Gene gene = new Gene(newTol.getAllele(), this.chromosomeType, root);
Splicer.setGene(gene, stack, setPrimary, setSecondary);
return stack;
}
use of binnie.core.genetics.Gene in project Binnie by ForestryMC.
the class InoculatorRecipeMaker method create.
public static List<InoculatorRecipeWrapper> create() {
List<InoculatorRecipeWrapper> recipes = new ArrayList<>();
for (IBreedingSystem system : Binnie.GENETICS.getActiveSystems()) {
ISpeciesRoot root = system.getSpeciesRoot();
IChromosomeType speciesChromosomeType = root.getSpeciesChromosomeType();
IAllele[] defaultTemplate = root.getDefaultTemplate();
IIndividual individual = root.templateAsIndividual(defaultTemplate);
for (ISpeciesType speciesType : system.getActiveTypes()) {
if (system.isDNAManipulable(speciesType)) {
ItemStack memberStack = root.getMemberStack(individual, speciesType);
memberStack.setItemDamage(OreDictionary.WILDCARD_VALUE);
IAllele species = defaultTemplate[speciesChromosomeType.ordinal()];
ItemStack serum = ItemSerum.create(new Gene(species, speciesChromosomeType, root));
// set fully charged
serum.setItemDamage(0);
recipes.add(new InoculatorRecipeWrapper(serum, memberStack));
recipes.add(new SplicerRecipeWrapper(serum, memberStack));
ItemStack serumArray = ItemSerumArray.create(new Gene(species, speciesChromosomeType, root));
// set fully charged
serumArray.setItemDamage(0);
for (IChromosomeType chromosomeType : root.getKaryotype()) {
if (chromosomeType != speciesChromosomeType) {
IAllele allele = defaultTemplate[chromosomeType.ordinal()];
Engineering.addGene(serumArray, new Gene(allele, chromosomeType, root));
}
}
recipes.add(new InoculatorRecipeWrapper(serumArray, memberStack));
recipes.add(new SplicerRecipeWrapper(serumArray, memberStack));
}
}
}
return recipes;
}
use of binnie.core.genetics.Gene in project Binnie by ForestryMC.
the class IsolatorRecipeMaker method create.
public static List<IsolatorRecipeWrapper> create() {
List<IsolatorRecipeWrapper> recipes = new ArrayList<>();
Collection<ISpeciesRoot> roots = AlleleManager.alleleRegistry.getSpeciesRoot().values();
for (ISpeciesRoot root : roots) {
ISpeciesType[] speciesTypes = root.getIconType().getClass().getEnumConstants();
IChromosomeType speciesChromosomeType = root.getSpeciesChromosomeType();
IAllele[] defaultTemplate = root.getDefaultTemplate();
IIndividual individual = root.templateAsIndividual(defaultTemplate);
for (ISpeciesType speciesType : speciesTypes) {
ItemStack memberStack = root.getMemberStack(individual, speciesType);
memberStack.setItemDamage(OreDictionary.WILDCARD_VALUE);
IAllele species = defaultTemplate[speciesChromosomeType.ordinal()];
ItemStack filledSequence = ItemSequence.create(new Gene(species, speciesChromosomeType, root), false);
IsolatorRecipeWrapper recipeWrapper = new IsolatorRecipeWrapper(memberStack, filledSequence);
recipes.add(recipeWrapper);
}
}
return recipes;
}
Aggregations