use of forestry.api.genetics.IBreedingTracker in project ForestryMC by ForestryMC.
the class TileDatabase method analyzeSpecimen.
// Called by the container on the server side
public ItemStack analyzeSpecimen(int selectedDatabaseSlot) {
if (selectedDatabaseSlot < 0) {
return ItemStack.EMPTY;
}
ItemStack specimen = getStackInSlot(selectedDatabaseSlot);
if (specimen.isEmpty()) {
return ItemStack.EMPTY;
}
ItemStack convertedSpecimen = GeneticsUtil.convertToGeneticEquivalent(specimen);
if (!ItemStack.areItemStacksEqual(specimen, convertedSpecimen)) {
setInventorySlotContents(selectedDatabaseSlot, convertedSpecimen);
specimen = convertedSpecimen;
}
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen);
// No individual, abort
if (speciesRoot == null) {
return specimen;
}
IIndividual individual = speciesRoot.getMember(specimen);
// Analyze if necessary
if (individual != null && !individual.isAnalyzed()) {
final boolean requiresEnergy = ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.APICULTURE));
if (requiresEnergy) {
// Requires energy
if (!analyzerInventory.isAlyzingFuel(analyzerInventory.getStackInSlot(InventoryDatabaseAnalyzer.SLOT_ENERGY))) {
return specimen;
}
}
if (individual.analyze()) {
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(world, ownerHandler.getOwner());
breedingTracker.registerSpecies(individual.getGenome().getPrimary());
breedingTracker.registerSpecies(individual.getGenome().getSecondary());
NBTTagCompound nbttagcompound = new NBTTagCompound();
individual.writeToNBT(nbttagcompound);
specimen.setTagCompound(nbttagcompound);
if (requiresEnergy) {
// Decrease energy
analyzerInventory.decrStackSize(InventoryDatabaseAnalyzer.SLOT_ENERGY, 1);
}
}
setInventorySlotContents(selectedDatabaseSlot, specimen);
}
return specimen;
}
use of forestry.api.genetics.IBreedingTracker in project Binnie by ForestryMC.
the class BreedingSystem method onSyncBreedingTracker.
@Override
@SubscribeEvent
public final void onSyncBreedingTracker(final ForestryEvent.SyncedBreedingTracker event) {
final IBreedingTracker tracker = event.tracker;
if (!this.getTrackerClass().isInstance(tracker)) {
return;
}
this.syncTracker(tracker);
}
use of forestry.api.genetics.IBreedingTracker in project Binnie by ForestryMC.
the class ManagerGenetics method analyse.
public static ItemStack analyse(ItemStack stack, World world, GameProfile username) {
if (!stack.isEmpty()) {
ItemStack conv = Binnie.GENETICS.getConversionStack(stack).copy();
if (!conv.isEmpty()) {
conv.setCount(stack.getCount());
stack = conv;
}
ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
if (root != null) {
final IIndividual ind = root.getMember(stack);
ind.analyze();
IBreedingTracker breedingTracker = ind.getGenome().getSpeciesRoot().getBreedingTracker(world, username);
breedingTracker.registerBirth(ind);
final NBTTagCompound nbttagcompound = new NBTTagCompound();
ind.writeToNBT(nbttagcompound);
stack.setTagCompound(nbttagcompound);
return stack;
}
if (stack.getItem() instanceof IItemAnalysable) {
return ((IItemAnalysable) stack.getItem()).analyse(stack);
}
}
return stack;
}
Aggregations