use of forestry.api.genetics.IChromosomeType in project ForestryMC by ForestryMC.
the class Genome method getChromosomes.
private static IChromosome[] getChromosomes(NBTTagCompound genomeNBT, ISpeciesRoot speciesRoot) {
NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10);
IChromosome[] chromosomes = new IChromosome[speciesRoot.getDefaultTemplate().length];
String primarySpeciesUid = null;
String secondarySpeciesUid = null;
for (int i = 0; i < chromosomesNBT.tagCount(); i++) {
NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(i);
byte chromosomeOrdinal = chromosomeNBT.getByte(SLOT_TAG);
if (chromosomeOrdinal >= 0 && chromosomeOrdinal < chromosomes.length) {
IChromosomeType chromosomeType = speciesRoot.getKaryotype()[chromosomeOrdinal];
Chromosome chromosome = Chromosome.create(primarySpeciesUid, secondarySpeciesUid, chromosomeType, chromosomeNBT);
chromosomes[chromosomeOrdinal] = chromosome;
if (chromosomeOrdinal == speciesRoot.getSpeciesChromosomeType().ordinal()) {
primarySpeciesUid = chromosome.getPrimaryAllele().getUID();
secondarySpeciesUid = chromosome.getSecondaryAllele().getUID();
}
}
}
return chromosomes;
}
use of forestry.api.genetics.IChromosomeType in project ForestryMC by ForestryMC.
the class Genome method checkChromosomes.
private void checkChromosomes(IChromosome[] chromosomes) {
if (chromosomes.length != getDefaultTemplate().length) {
String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template.\n%s", getSpeciesRoot().getUID(), chromosomesToString(chromosomes));
throw new IllegalArgumentException(message);
}
IChromosomeType[] karyotype = getSpeciesRoot().getKaryotype();
for (int i = 0; i < karyotype.length; i++) {
IChromosomeType chromosomeType = karyotype[i];
IChromosome chromosome = chromosomes[i];
if (chromosome == null) {
String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing chromosome '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
throw new IllegalArgumentException(message);
}
IAllele primary = chromosome.getPrimaryAllele();
if (primary == null) {
String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing primary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
throw new IllegalArgumentException(message);
}
IAllele secondary = chromosome.getSecondaryAllele();
if (secondary == null) {
String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing secondary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
throw new IllegalArgumentException(message);
}
Class<? extends IAllele> chromosomeAlleleClass = chromosomeType.getAlleleClass();
if (!chromosomeAlleleClass.isAssignableFrom(primary.getClass())) {
String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Incorrect type for primary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
throw new IllegalArgumentException(message);
}
if (!chromosomeAlleleClass.isAssignableFrom(secondary.getClass())) {
String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Incorrect type for secondary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
throw new IllegalArgumentException(message);
}
}
}
use of forestry.api.genetics.IChromosomeType in project ForestryMC by ForestryMC.
the class AlleleRegistry method addValidAlleleTypes.
@Override
public void addValidAlleleTypes(IAllele allele, IChromosomeType... chromosomeTypes) {
for (IChromosomeType chromosomeType : chromosomeTypes) {
if (!chromosomeType.getAlleleClass().isAssignableFrom(allele.getClass())) {
throw new IllegalArgumentException("Allele class (" + allele.getClass() + ") does not match chromosome type (" + chromosomeType.getAlleleClass() + ").");
}
allelesByType.put(chromosomeType, allele);
typesByAllele.put(allele, chromosomeType);
}
}
use of forestry.api.genetics.IChromosomeType 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);
}
use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.
the class ControlChromosome method setSystem.
public void setSystem(@Nullable IBreedingSystem breedingSystem) {
if (this.breedingSystem != breedingSystem) {
this.breedingSystem = breedingSystem;
deleteAllChildren();
if (breedingSystem != null) {
IFieldKitPlugin fieldKitPlugin = breedingSystem.getFieldKitPlugin();
fieldKitPlugin.getChromosomePickerPositions();
for (Map.Entry<IChromosomeType, IPoint> entry : fieldKitPlugin.getChromosomePickerPositions().entrySet()) {
IChromosomeType chromosomeType = entry.getKey();
IPoint position = entry.getValue();
new ControlChromoPicker(this, position.xPos(), position.yPos(), chromosomeType);
}
}
}
}
Aggregations