use of forestry.api.genetics.IIndividual in project ForestryMC by ForestryMC.
the class EscritoireGame method probe.
public void probe(ItemStack specimen, IInventory inventory, int startSlot, int slotCount) {
if (status != Status.PLAYING) {
return;
}
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
if (individual == null) {
return;
}
if (bountyLevel > 1) {
bountyLevel--;
}
IAlleleSpecies species = individual.getGenome().getPrimary();
gameBoard.hideProbedTokens();
int revealCount = getSampleSize(slotCount);
for (int i = 0; i < revealCount; i++) {
ItemStack sample = inventory.decrStackSize(startSlot + i, 1);
if (!sample.isEmpty()) {
if (rand.nextFloat() < species.getResearchSuitability(sample)) {
gameBoard.probe();
}
}
}
lastUpdate = System.currentTimeMillis();
}
use of forestry.api.genetics.IIndividual in project ForestryMC by ForestryMC.
the class Bee method retrievePollen.
/* FLOWERS */
@Override
@Nullable
public IIndividual retrievePollen(IBeeHousing housing) {
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
int chance = Math.round(genome.getFlowering() * beeModifier.getFloweringModifier(getGenome(), 1f));
World world = housing.getWorldObj();
Random random = world.rand;
// Correct speed
if (random.nextInt(100) >= chance) {
return null;
}
Vec3i area = getArea(genome, beeModifier);
Vec3i offset = new Vec3i(-area.getX() / 2, -area.getY() / 4, -area.getZ() / 2);
BlockPos housingPos = housing.getCoordinates();
IIndividual pollen = null;
for (int i = 0; i < 20; i++) {
BlockPos randomPos = VectUtil.getRandomPositionInArea(random, area);
BlockPos blockPos = VectUtil.add(housingPos, randomPos, offset);
ICheckPollinatable pitcher = TileUtil.getTile(world, blockPos, ICheckPollinatable.class);
if (pitcher != null) {
if (genome.getFlowerProvider().isAcceptedPollinatable(world, pitcher)) {
pollen = pitcher.getPollen();
}
} else {
pollen = GeneticsUtil.getPollen(world, blockPos);
}
if (pollen != null) {
return pollen;
}
}
return null;
}
use of forestry.api.genetics.IIndividual in project ForestryMC by ForestryMC.
the class InventoryEscritoire method canSlotAccept.
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + tile.getGame().getSampleSize(SLOTS_INPUT_COUNT)) {
ItemStack specimen = getStackInSlot(SLOT_ANALYZE);
if (specimen.isEmpty()) {
return false;
}
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
return individual != null && individual.getGenome().getPrimary().getResearchSuitability(itemStack) > 0;
}
return slotIndex == SLOT_ANALYZE && (AlleleManager.alleleRegistry.isIndividual(itemStack) || GeneticsUtil.getGeneticEquivalent(itemStack) != null);
}
use of forestry.api.genetics.IIndividual in project ForestryMC by ForestryMC.
the class ItemInventoryAlyzer method analyzeSpecimen.
private void analyzeSpecimen(ItemStack specimen) {
if (specimen.isEmpty()) {
return;
}
ItemStack convertedSpecimen = GeneticsUtil.convertToGeneticEquivalent(specimen);
if (!ItemStack.areItemStacksEqual(specimen, convertedSpecimen)) {
setInventorySlotContents(SLOT_SPECIMEN, convertedSpecimen);
specimen = convertedSpecimen;
}
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen);
// No individual, abort
if (speciesRoot == null) {
return;
}
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 (!isAlyzingFuel(getStackInSlot(SLOT_ENERGY))) {
return;
}
}
if (individual.analyze()) {
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
breedingTracker.registerSpecies(individual.getGenome().getPrimary());
breedingTracker.registerSpecies(individual.getGenome().getSecondary());
NBTTagCompound nbttagcompound = new NBTTagCompound();
individual.writeToNBT(nbttagcompound);
specimen.setTagCompound(nbttagcompound);
if (requiresEnergy) {
// Decrease energy
decrStackSize(SLOT_ENERGY, 1);
}
}
}
setInventorySlotContents(SLOT_ANALYZE_1, specimen);
setInventorySlotContents(SLOT_SPECIMEN, ItemStack.EMPTY);
}
use of forestry.api.genetics.IIndividual 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;
}
Aggregations