Search in sources :

Example 1 with IApiaristTracker

use of forestry.api.apiculture.IApiaristTracker in project ForestryMC by ForestryMC.

the class BeeRoot method getBreedingTracker.

@Override
public IApiaristTracker getBreedingTracker(World world, @Nullable GameProfile player) {
    String filename = "ApiaristTracker." + (player == null ? "common" : player.getId());
    ApiaristTracker tracker = (ApiaristTracker) world.loadData(ApiaristTracker.class, filename);
    // Create a tracker if there is none yet.
    if (tracker == null) {
        tracker = new ApiaristTracker(filename);
        world.setData(filename, tracker);
    }
    tracker.setUsername(player);
    tracker.setWorld(world);
    return tracker;
}
Also used : IApiaristTracker(forestry.api.apiculture.IApiaristTracker)

Example 2 with IApiaristTracker

use of forestry.api.apiculture.IApiaristTracker in project ForestryMC by ForestryMC.

the class BeeRoot method getBeekeepingMode.

@Override
public IBeekeepingMode getBeekeepingMode(World world) {
    if (activeBeekeepingMode != null) {
        return activeBeekeepingMode;
    }
    // No beekeeping mode yet, get it.
    IApiaristTracker tracker = getBreedingTracker(world, null);
    String modeName = tracker.getModeName();
    IBeekeepingMode mode = getBeekeepingMode(modeName);
    Preconditions.checkNotNull(mode);
    setBeekeepingMode(world, mode);
    FMLCommonHandler.instance().getFMLLogger().debug("Set beekeeping mode for a world to " + mode);
    return activeBeekeepingMode;
}
Also used : IBeekeepingMode(forestry.api.apiculture.IBeekeepingMode) IApiaristTracker(forestry.api.apiculture.IApiaristTracker)

Example 3 with IApiaristTracker

use of forestry.api.apiculture.IApiaristTracker in project ForestryMC by ForestryMC.

the class BeekeepingLogic method spawnOffspring.

/**
 * Creates the succeeding princess and between one and three drones.
 */
private static Collection<ItemStack> spawnOffspring(IBee queen, IBeeHousing beeHousing) {
    World world = beeHousing.getWorldObj();
    Stack<ItemStack> offspring = new Stack<>();
    IApiaristTracker breedingTracker = BeeManager.beeRoot.getBreedingTracker(world, beeHousing.getOwner());
    // Princess
    boolean secondPrincess = world.rand.nextInt(10000) < ModuleApiculture.getSecondPrincessChance() * 100;
    int count = secondPrincess ? 2 : 1;
    while (count > 0) {
        count--;
        IBee heiress = queen.spawnPrincess(beeHousing);
        if (heiress != null) {
            ItemStack princess = BeeManager.beeRoot.getMemberStack(heiress, EnumBeeType.PRINCESS);
            breedingTracker.registerPrincess(heiress);
            offspring.push(princess);
        }
    }
    // Drones
    List<IBee> drones = queen.spawnDrones(beeHousing);
    for (IBee drone : drones) {
        ItemStack droneStack = BeeManager.beeRoot.getMemberStack(drone, EnumBeeType.DRONE);
        breedingTracker.registerDrone(drone);
        offspring.push(droneStack);
    }
    IBeeHousingInventory beeInventory = beeHousing.getBeeInventory();
    Collection<ItemStack> spawn = new ArrayList<>();
    while (!offspring.isEmpty()) {
        ItemStack spawned = offspring.pop();
        if (!beeInventory.addProduct(spawned, true)) {
            spawn.add(spawned);
        }
    }
    return spawn;
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) ArrayList(java.util.ArrayList) IApiaristTracker(forestry.api.apiculture.IApiaristTracker) IBee(forestry.api.apiculture.IBee) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IApiaristTracker

use of forestry.api.apiculture.IApiaristTracker in project ForestryMC by ForestryMC.

the class GuiNaturalistInventory method displayBreedingStatistics.

private void displayBreedingStatistics(int x) {
    textLayout.startPage();
    textLayout.drawLine(Translator.translateToLocal("for.gui.speciescount") + ": " + breedingTracker.getSpeciesBred() + "/" + speciesRoot.getSpeciesCount(), x);
    textLayout.newLine();
    textLayout.newLine();
    if (breedingTracker instanceof IApiaristTracker) {
        IApiaristTracker tracker = (IApiaristTracker) breedingTracker;
        textLayout.drawLine(Translator.translateToLocal("for.gui.queens") + ": " + tracker.getQueenCount(), x);
        textLayout.newLine();
        textLayout.drawLine(Translator.translateToLocal("for.gui.princesses") + ": " + tracker.getPrincessCount(), x);
        textLayout.newLine();
        textLayout.drawLine(Translator.translateToLocal("for.gui.drones") + ": " + tracker.getDroneCount(), x);
        textLayout.newLine();
    }
    textLayout.endPage();
}
Also used : IApiaristTracker(forestry.api.apiculture.IApiaristTracker)

Example 5 with IApiaristTracker

use of forestry.api.apiculture.IApiaristTracker in project ForestryMC by ForestryMC.

the class Bee method mutateSpecies.

@Nullable
private static IChromosome[] mutateSpecies(IBeeHousing housing, IBeeGenome genomeOne, IBeeGenome genomeTwo) {
    World world = housing.getWorldObj();
    IChromosome[] parent1 = genomeOne.getChromosomes();
    IChromosome[] parent2 = genomeTwo.getChromosomes();
    IBeeGenome genome0;
    IBeeGenome genome1;
    IAlleleBeeSpecies allele0;
    IAlleleBeeSpecies allele1;
    if (world.rand.nextBoolean()) {
        allele0 = (IAlleleBeeSpecies) parent1[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleBeeSpecies) parent2[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeOne;
        genome1 = genomeTwo;
    } else {
        allele0 = (IAlleleBeeSpecies) parent2[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleBeeSpecies) parent1[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeTwo;
        genome1 = genomeOne;
    }
    GameProfile playerProfile = housing.getOwner();
    IApiaristTracker breedingTracker = BeeManager.beeRoot.getBreedingTracker(world, playerProfile);
    List<IMutation> combinations = BeeManager.beeRoot.getCombinations(allele0, allele1, true);
    for (IMutation mutation : combinations) {
        IBeeMutation beeMutation = (IBeeMutation) mutation;
        float chance = beeMutation.getChance(housing, allele0, allele1, genome0, genome1);
        if (chance <= 0) {
            continue;
        }
        // boost chance for researched mutations
        if (breedingTracker.isResearched(beeMutation)) {
            float mutationBoost = chance * (Config.researchMutationBoostMultiplier - 1.0f);
            mutationBoost = Math.min(Config.maxResearchMutationBoostPercent, mutationBoost);
            chance += mutationBoost;
        }
        if (chance > world.rand.nextFloat() * 100) {
            breedingTracker.registerMutation(mutation);
            return BeeManager.beeRoot.templateAsChromosomes(mutation.getTemplate());
        }
    }
    return null;
}
Also used : IAlleleBeeSpecies(forestry.api.apiculture.IAlleleBeeSpecies) IMutation(forestry.api.genetics.IMutation) GameProfile(com.mojang.authlib.GameProfile) IBeeMutation(forestry.api.apiculture.IBeeMutation) IChromosome(forestry.api.genetics.IChromosome) IApiaristTracker(forestry.api.apiculture.IApiaristTracker) World(net.minecraft.world.World) IBeeGenome(forestry.api.apiculture.IBeeGenome) Nullable(javax.annotation.Nullable)

Aggregations

IApiaristTracker (forestry.api.apiculture.IApiaristTracker)6 World (net.minecraft.world.World)2 GameProfile (com.mojang.authlib.GameProfile)1 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)1 IBee (forestry.api.apiculture.IBee)1 IBeeGenome (forestry.api.apiculture.IBeeGenome)1 IBeeHousingInventory (forestry.api.apiculture.IBeeHousingInventory)1 IBeeMutation (forestry.api.apiculture.IBeeMutation)1 IBeekeepingMode (forestry.api.apiculture.IBeekeepingMode)1 IChromosome (forestry.api.genetics.IChromosome)1 IMutation (forestry.api.genetics.IMutation)1 ArrayList (java.util.ArrayList)1 Stack (java.util.Stack)1 Nullable (javax.annotation.Nullable)1 ItemStack (net.minecraft.item.ItemStack)1