use of binnie.core.api.genetics.IBreedingSystem 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 binnie.core.api.genetics.IBreedingSystem in project Binnie by ForestryMC.
the class WindowGenesis method refreshPickup.
private void refreshPickup() {
this.panelPickup.deleteAllChildren();
int i = 0;
IBreedingSystem system = Binnie.GENETICS.getSystem(this.root);
for (ISpeciesType type : system.getActiveTypes()) {
IIndividual ind = this.root.templateAsIndividual(this.template);
ind.analyze();
ItemStack stack = this.root.getMemberStack(ind, type);
ControlItemDisplay display = new ControlItemDisplay(this.panelPickup, 4 + i % 3 * 18, 4 + i / 3 * 18);
display.setItemStack(stack);
display.setTooltip();
display.addEventHandler(EventMouse.Down.class, EventHandlerOrigin.SELF, display, event -> {
NBTTagCompound nbt = new NBTTagCompound();
stack.writeToNBT(nbt);
Window.get(event.getOrigin()).sendClientAction(ACTION_GENESIS, nbt);
});
++i;
}
}
use of binnie.core.api.genetics.IBreedingSystem 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 binnie.core.api.genetics.IBreedingSystem in project Binnie by ForestryMC.
the class ControlIndividualDisplay method onRenderForeground.
@Override
@SideOnly(Side.CLIENT)
public void onRenderForeground(int guiWidth, int guiHeight) {
TextureAtlasSprite icon = null;
if (this.species == null) {
return;
}
IBreedingSystem system = Binnie.GENETICS.getSystem(this.species.getRoot());
switch(this.discovered) {
case SHOW:
{
super.onRenderForeground(guiWidth, guiHeight);
return;
}
case DISCOVERED:
{
icon = system.getDiscoveredIcon();
break;
}
case UNDISCOVERED:
{
icon = system.getUndiscoveredIcon();
break;
}
}
if (icon != null) {
RenderUtil.drawGuiSprite(Point.ZERO, icon);
}
}
use of binnie.core.api.genetics.IBreedingSystem in project Binnie by ForestryMC.
the class ControlMutationBox method setSpecies.
public void setSpecies(@Nullable final IAlleleSpecies species) {
if (species != this.species) {
this.species = species;
this.movePercentage(-100.0f);
final IBreedingSystem system = ((WindowAbstractDatabase) this.getTopParent()).getBreedingSystem();
final List<IMutation> discovered = system.getDiscoveredMutations(Window.get(this).getWorld(), Window.get(this).getUsername());
if (species != null) {
if (this.type == Type.Resultant) {
this.setOptions(system.getResultantMutations(species));
} else {
final List<IMutation> mutations = system.getFurtherMutations(species);
int i = 0;
while (i < mutations.size()) {
final IMutation mutation = mutations.get(i);
if (!discovered.contains(mutation) && !((IAlleleSpecies) mutation.getTemplate()[0]).isCounted()) {
mutations.remove(i);
} else {
++i;
}
}
this.setOptions(mutations);
}
}
}
}
Aggregations