use of forestry.api.genetics.IChromosomeType 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);
}
}
}
use of forestry.api.genetics.IChromosomeType 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.IChromosomeType 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");
}
use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.
the class ItemSerum method getSubItems.
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (this.isInCreativeTab(tab)) {
for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
Map<IChromosomeType, List<IAllele>> chromosomeMap = Binnie.GENETICS.getChromosomeMap(root);
if (chromosomeMap != null) {
for (Map.Entry<IChromosomeType, List<IAllele>> entry : chromosomeMap.entrySet()) {
IChromosomeType chromosome = entry.getKey();
for (final IAllele allele : entry.getValue()) {
Gene gene = Gene.create(allele, chromosome, root);
IGeneItem geneItem = new GeneItem(gene);
ItemStack stack = new ItemStack(this);
geneItem.writeToItem(stack);
items.add(stack);
}
}
}
}
}
}
use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.
the class ItemSerumArray method getSubItems.
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (this.isInCreativeTab(tab)) {
for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
for (IIndividual template : root.getIndividualTemplates()) {
if (template.getGenome().getPrimary().isSecret()) {
continue;
}
IGeneItem geneItem = new GeneArrayItem();
for (IChromosomeType type : root.getKaryotype()) {
IChromosome chromosome = template.getGenome().getChromosomes()[type.ordinal()];
if (chromosome != null) {
IAllele active = chromosome.getActiveAllele();
geneItem.addGene(new Gene(active, type, root));
}
}
ItemStack array = new ItemStack(this);
geneItem.writeToItem(array);
items.add(array);
}
}
}
}
Aggregations