mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 23:33:00 +00:00
Fix #697 boost mutation chance when researched in the Escritoire
This commit is contained in:
1 parent
d31968d190
commit
6a6627394b
16 files changed
+239
-120
No files matched your search
@@ -20,6 +20,7 @@ import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.apiculture.IApiaristTracker;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.genetics.BreedingTracker;
|
||||
|
||||
public class ApiaristTracker extends BreedingTracker implements IApiaristTracker {
|
||||
@@ -61,13 +62,16 @@ public class ApiaristTracker extends BreedingTracker implements IApiaristTracker
|
||||
|
||||
@Override
|
||||
public void registerPickup(IIndividual individual) {
|
||||
if (!individual.getGenome().getPrimary().getRoot().getUID().equals(BeeHelper.UID)) {
|
||||
ISpeciesRoot speciesRoot = individual.getGenome().getPrimary().getRoot();
|
||||
if (!speciesRoot.getUID().equals(speciesRootUID())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!individual.isPureBred(EnumBeeChromosome.SPECIES)) {
|
||||
return;
|
||||
}
|
||||
if (BeeManager.beeRoot.getCombinations(individual.getGenome().getPrimary()).size() > 0) {
|
||||
|
||||
if (speciesRoot.getCombinations(individual.getGenome().getPrimary()).size() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.apiculture.IAlleleBeeEffect;
|
||||
@@ -41,15 +43,18 @@ import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IChromosome;
|
||||
import forestry.api.genetics.IEffectData;
|
||||
import forestry.api.genetics.IFlowerProvider;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.arboriculture.genetics.FakePollinatable;
|
||||
import forestry.arboriculture.genetics.ICheckPollinatable;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.genetics.Chromosome;
|
||||
import forestry.core.genetics.GenericRatings;
|
||||
@@ -604,29 +609,45 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
|
||||
IBeeGenome genome0;
|
||||
IBeeGenome genome1;
|
||||
IAllele allele0;
|
||||
IAllele allele1;
|
||||
IAlleleSpecies allele0;
|
||||
IAlleleSpecies allele1;
|
||||
|
||||
if (world.rand.nextBoolean()) {
|
||||
allele0 = parent1[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = parent2[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
allele0 = (IAlleleBeeSpecies) parent1[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = (IAlleleBeeSpecies) parent2[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
|
||||
genome0 = genomeOne;
|
||||
genome1 = genomeTwo;
|
||||
} else {
|
||||
allele0 = parent2[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = parent1[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
allele0 = (IAlleleBeeSpecies) parent2[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = (IAlleleBeeSpecies) parent1[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
|
||||
genome0 = genomeTwo;
|
||||
genome1 = genomeOne;
|
||||
}
|
||||
|
||||
for (IBeeMutation mutation : BeeManager.beeRoot.getMutations(true)) {
|
||||
float chance = mutation.getChance(housing, allele0, allele1, genome0, genome1);
|
||||
GameProfile playerProfile = housing.getOwnerName();
|
||||
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) {
|
||||
IApiaristTracker breedingTracker = BeeManager.beeRoot.getBreedingTracker(world, housing.getOwnerName());
|
||||
breedingTracker.registerMutation(mutation);
|
||||
return BeeManager.beeRoot.templateAsChromosomes(mutation.getTemplate());
|
||||
breedingTracker.registerMutation(beeMutation);
|
||||
return BeeManager.beeRoot.templateAsChromosomes(beeMutation.getTemplate());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public enum BeeDefinition implements IBeeDefinition {
|
||||
protected void registerMutations() {
|
||||
for (BeeDefinition hiveBee0 : overworldHiveBees) {
|
||||
for (BeeDefinition hiveBee1 : overworldHiveBees) {
|
||||
if (hiveBee0 != hiveBee1) {
|
||||
if (hiveBee0.ordinal() < hiveBee1.ordinal()) {
|
||||
registerMutation(hiveBee0, hiveBee1, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ public class BeeMutation extends Mutation implements IBeeMutationCustom {
|
||||
|
||||
@Override
|
||||
public float getChance(IBeeHousing housing, IAlleleBeeSpecies allele0, IAlleleBeeSpecies allele1, IBeeGenome genome0, IBeeGenome genome1) {
|
||||
|
||||
World world = housing.getWorld();
|
||||
int x = housing.getXCoord();
|
||||
int y = housing.getYCoord();
|
||||
@@ -53,19 +52,8 @@ public class BeeMutation extends Mutation implements IBeeMutationCustom {
|
||||
|
||||
processedChance *= housing.getMutationModifier(genome0, genome1, 1f);
|
||||
processedChance *= BeeManager.beeRoot.getBeekeepingMode(world).getMutationModifier(genome0, genome1, 1f);
|
||||
if (processedChance <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (this.species0.getUID().equals(allele0.getUID()) && this.species1.getUID().equals(allele1.getUID())) {
|
||||
return processedChance;
|
||||
}
|
||||
if (this.species1.getUID().equals(allele0.getUID()) && this.species0.getUID().equals(allele1.getUID())) {
|
||||
return processedChance;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
return processedChance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,6 +31,8 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -116,18 +118,18 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv
|
||||
float saplingModifier = 1.0f;
|
||||
|
||||
if (Proxies.common.isSimulating(world)) {
|
||||
if (player != null) {
|
||||
ItemStack held = player.inventory.getCurrentItem();
|
||||
if (held != null && held.getItem() instanceof IToolGrafter) {
|
||||
saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, x, y, z);
|
||||
held.damageItem(1, player);
|
||||
if (held.stackSize <= 0) {
|
||||
player.destroyCurrentEquippedItem();
|
||||
}
|
||||
ItemStack held = player.inventory.getCurrentItem();
|
||||
if (held != null && held.getItem() instanceof IToolGrafter) {
|
||||
saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, x, y, z);
|
||||
held.damageItem(1, player);
|
||||
if (held.stackSize <= 0) {
|
||||
player.destroyCurrentEquippedItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
drops.set(getLeafDrop(world, x, y, z, saplingModifier, fortune));
|
||||
GameProfile playerProfile = player.getGameProfile();
|
||||
ArrayList<ItemStack> leafDrops = getLeafDrop(world, playerProfile, x, y, z, saplingModifier, fortune);
|
||||
drops.set(leafDrops);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,13 +139,13 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv
|
||||
|
||||
// leaves not harvested, get drops normally
|
||||
if (ret == null) {
|
||||
ret = getLeafDrop(world, x, y, z, 1.0f, fortune);
|
||||
ret = getLeafDrop(world, null, x, y, z, 1.0f, fortune);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private ArrayList<ItemStack> getLeafDrop(World world, int x, int y, int z, float saplingModifier, int fortune) {
|
||||
private static ArrayList<ItemStack> getLeafDrop(World world, GameProfile playerProfile, int x, int y, int z, float saplingModifier, int fortune) {
|
||||
ArrayList<ItemStack> prod = new ArrayList<ItemStack>();
|
||||
|
||||
TileLeaves tile = getLeafTile(world, x, y, z);
|
||||
@@ -152,7 +154,14 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv
|
||||
}
|
||||
|
||||
// Add saplings
|
||||
ITree[] saplings = tile.getTree().getSaplings(world, x, y, z, saplingModifier);
|
||||
ITree[] saplings;
|
||||
try {
|
||||
saplings = tile.getTree().getSaplings(world, playerProfile, x, y, z, saplingModifier);
|
||||
} catch (Throwable ignored) {
|
||||
// legacy
|
||||
saplings = tile.getTree().getSaplings(world, x, y, z, saplingModifier);
|
||||
}
|
||||
|
||||
for (ITree sapling : saplings) {
|
||||
if (sapling != null) {
|
||||
prod.add(PluginArboriculture.treeInterface.getMemberStack(sapling, EnumGermlingType.SAPLING.ordinal()));
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.genetics;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
@@ -34,18 +35,22 @@ import forestry.api.arboriculture.EnumGrowthConditions;
|
||||
import forestry.api.arboriculture.EnumTreeChromosome;
|
||||
import forestry.api.arboriculture.IAlleleLeafEffect;
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.arboriculture.IArboristTracker;
|
||||
import forestry.api.arboriculture.IFruitProvider;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.arboriculture.ITreeGenome;
|
||||
import forestry.api.arboriculture.ITreeMutation;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleBoolean;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IChromosome;
|
||||
import forestry.api.genetics.IEffectData;
|
||||
import forestry.api.genetics.IFruitFamily;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.arboriculture.gadgets.ForestryBlockLeaves;
|
||||
import forestry.arboriculture.gadgets.TileLeaves;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.genetics.Chromosome;
|
||||
@@ -355,6 +360,11 @@ public class Tree extends Individual implements ITree, IPlantable {
|
||||
/* REPRODUCTION */
|
||||
@Override
|
||||
public ITree[] getSaplings(World world, int x, int y, int z, float modifier) {
|
||||
return getSaplings(world, null, x, y, z, modifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITree[] getSaplings(World world, GameProfile playerProfile, int x, int y, int z, float modifier) {
|
||||
ArrayList<ITree> prod = new ArrayList<ITree>();
|
||||
|
||||
float chance = genome.getFertility() * modifier;
|
||||
@@ -363,14 +373,14 @@ public class Tree extends Individual implements ITree, IPlantable {
|
||||
if (this.getMate() == null) {
|
||||
prod.add(PluginArboriculture.treeInterface.getTree(world, new TreeGenome(genome.getChromosomes())));
|
||||
} else {
|
||||
prod.add(createOffspring(world, x, y, z));
|
||||
prod.add(createOffspring(world, playerProfile, x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
return prod.toArray(new ITree[prod.size()]);
|
||||
}
|
||||
|
||||
private ITree createOffspring(World world, int x, int y, int z) {
|
||||
private ITree createOffspring(World world, GameProfile playerProfile, int x, int y, int z) {
|
||||
|
||||
IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length];
|
||||
IChromosome[] parent1 = genome.getChromosomes();
|
||||
@@ -378,9 +388,9 @@ public class Tree extends Individual implements ITree, IPlantable {
|
||||
|
||||
// Check for mutation. Replace one of the parents with the mutation
|
||||
// template if mutation occured.
|
||||
IChromosome[] mutated = mutateSpecies(world, x, y, z, genome, mate);
|
||||
IChromosome[] mutated = mutateSpecies(world, playerProfile, x, y, z, genome, mate);
|
||||
if (mutated == null) {
|
||||
mutated = mutateSpecies(world, x, y, z, mate, genome);
|
||||
mutated = mutateSpecies(world, playerProfile, x, y, z, mate, genome);
|
||||
}
|
||||
|
||||
if (mutated != null) {
|
||||
@@ -396,41 +406,57 @@ public class Tree extends Individual implements ITree, IPlantable {
|
||||
return new Tree(new TreeGenome(chromosomes));
|
||||
}
|
||||
|
||||
private IChromosome[] mutateSpecies(World world, int x, int y, int z, IGenome genomeOne, IGenome genomeTwo) {
|
||||
private static IChromosome[] mutateSpecies(World world, @Nullable GameProfile playerProfile, int x, int y, int z, IGenome genomeOne, IGenome genomeTwo) {
|
||||
|
||||
IChromosome[] parent1 = genomeOne.getChromosomes();
|
||||
IChromosome[] parent2 = genomeTwo.getChromosomes();
|
||||
|
||||
IGenome genome0;
|
||||
IGenome genome1;
|
||||
IAllele allele0;
|
||||
IAllele allele1;
|
||||
IAlleleSpecies allele0;
|
||||
IAlleleSpecies allele1;
|
||||
|
||||
if (world.rand.nextBoolean()) {
|
||||
allele0 = parent1[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = parent2[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
allele0 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
|
||||
genome0 = genomeOne;
|
||||
genome1 = genomeTwo;
|
||||
} else {
|
||||
allele0 = parent2[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = parent1[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
allele0 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
|
||||
allele1 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
|
||||
|
||||
genome0 = genomeTwo;
|
||||
genome1 = genomeOne;
|
||||
}
|
||||
|
||||
for (ITreeMutation mutation : PluginArboriculture.treeInterface.getMutations(true)) {
|
||||
IArboristTracker breedingTracker = null;
|
||||
if (playerProfile != null) {
|
||||
breedingTracker = PluginArboriculture.treeInterface.getBreedingTracker(world, playerProfile);
|
||||
}
|
||||
|
||||
List<IMutation> combinations = PluginArboriculture.treeInterface.getCombinations(allele0, allele1, true);
|
||||
for (IMutation mutation : combinations) {
|
||||
ITreeMutation treeMutation = (ITreeMutation) mutation;
|
||||
// Stop blacklisted species.
|
||||
// if (BeeManager.breedingManager.isBlacklisted(mutation.getTemplate()[0].getUID())) {
|
||||
// continue;
|
||||
// }
|
||||
float chance = mutation.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
|
||||
|
||||
float chance = treeMutation.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
|
||||
if (chance <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// boost chance for researched mutations
|
||||
if (breedingTracker != null && breedingTracker.isResearched(treeMutation)) {
|
||||
float mutationBoost = chance * (Config.researchMutationBoostMultiplier - 1.0f);
|
||||
mutationBoost = Math.min(Config.maxResearchMutationBoostPercent, mutationBoost);
|
||||
chance += mutationBoost;
|
||||
}
|
||||
|
||||
if (chance > world.rand.nextFloat() * 100) {
|
||||
// IApiaristTracker breedingTracker = BeeManager.breedingManager.getApiaristTracker(world);
|
||||
// breedingTracker.registerMutation(mutation);
|
||||
return PluginArboriculture.treeInterface.templateAsChromosomes(mutation.getTemplate());
|
||||
return PluginArboriculture.treeInterface.templateAsChromosomes(treeMutation.getTemplate());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.arboriculture.genetics;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.arboriculture.ITreeGenome;
|
||||
import forestry.api.arboriculture.ITreeMutation;
|
||||
import forestry.api.arboriculture.ITreeRoot;
|
||||
@@ -40,21 +41,19 @@ public class TreeMutation extends Mutation implements ITreeMutation {
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
return getChance(world, x, y, z, (IAlleleTreeSpecies) allele0, (IAlleleTreeSpecies) allele1, (ITreeGenome) genome0, (ITreeGenome) genome1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAlleleTreeSpecies allele0, IAlleleTreeSpecies allele1, ITreeGenome genome0, ITreeGenome genome1) {
|
||||
float processedChance = super.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
|
||||
if (processedChance <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
processedChance *= PluginArboriculture.treeInterface.getTreekeepingMode(world).getMutationModifier((ITreeGenome) genome0, (ITreeGenome) genome1, 1f);
|
||||
processedChance *= PluginArboriculture.treeInterface.getTreekeepingMode(world).getMutationModifier(genome0, genome1, 1f);
|
||||
|
||||
if (this.species0.getUID().equals(allele0.getUID()) && this.species1.getUID().equals(allele1.getUID())) {
|
||||
return processedChance;
|
||||
}
|
||||
if (this.species1.getUID().equals(allele0.getUID()) && this.species0.getUID().equals(allele1.getUID())) {
|
||||
return processedChance;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return processedChance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.interfaces.IPickupHandler;
|
||||
|
||||
@@ -29,7 +31,11 @@ public class PickupHandlerCore implements IPickupHandler {
|
||||
|
||||
ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(itemstack);
|
||||
if (root != null) {
|
||||
root.getBreedingTracker(entityitem.worldObj, entityPlayer.getGameProfile()).registerPickup(root.getMember(itemstack));
|
||||
IIndividual individual = root.getMember(itemstack);
|
||||
if (individual != null) {
|
||||
IBreedingTracker tracker = root.getBreedingTracker(entityitem.worldObj, entityPlayer.getGameProfile());
|
||||
tracker.registerPickup(individual);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -55,8 +55,10 @@ public class Config {
|
||||
// Graphics
|
||||
public static boolean enableParticleFX = true;
|
||||
|
||||
// Bees
|
||||
// Genetics
|
||||
public static boolean clearInvalidChromosomes = false;
|
||||
public static float researchMutationBoostMultiplier = 1.5f;
|
||||
public static float maxResearchMutationBoostPercent = 5.0f;
|
||||
|
||||
// Dungeon loot
|
||||
public static boolean dungeonLootRare = false;
|
||||
@@ -244,6 +246,9 @@ public class Config {
|
||||
}
|
||||
|
||||
clearInvalidChromosomes = configCommon.getBooleanLocalized("genetics", "clear.invalid.chromosomes", clearInvalidChromosomes);
|
||||
researchMutationBoostMultiplier = configCommon.getFloatLocalized("genetics.research.boost", "multiplier", researchMutationBoostMultiplier, 1.0f, 1000.f);
|
||||
maxResearchMutationBoostPercent = configCommon.getFloatLocalized("genetics.research.boost", "max.percent", maxResearchMutationBoostPercent, 0.0f, 100.0f);
|
||||
|
||||
dungeonLootRare = configCommon.getBooleanLocalized("difficulty", "loot.rare", dungeonLootRare);
|
||||
|
||||
enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply);
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -34,8 +36,20 @@ import forestry.core.proxy.Proxies;
|
||||
|
||||
public abstract class BreedingTracker extends WorldSavedData implements IBreedingTracker {
|
||||
|
||||
private List<String> discoveredSpecies = new ArrayList<String>();
|
||||
private List<String> discoveredMutations = new ArrayList<String>();
|
||||
private static final String SPECIES_COUNT_KEY = "SpeciesCount";
|
||||
private static final String MUTATIONS_COUNT_KEY = "MutationsCount";
|
||||
private static final String RESEARCHED_COUNT_KEY = "ResearchedCount";
|
||||
private static final String SPECIES_KEY = "SD";
|
||||
private static final String MUTATIONS_KEY = "MD";
|
||||
private static final String RESEARCHED_KEY = "RD";
|
||||
private static final String MODE_NAME_KEY = "BMS";
|
||||
private static final String MUTATION_FORMAT = "%s-%s=%s";
|
||||
|
||||
public static final String TYPE_KEY = "TYPE";
|
||||
|
||||
private final Set<String> discoveredSpecies = new HashSet<String>();
|
||||
private final Set<String> discoveredMutations = new HashSet<String>();
|
||||
private final Set<String> researchedMutations = new HashSet<String>();
|
||||
private String modeName;
|
||||
|
||||
private final GameProfile username;
|
||||
@@ -94,54 +108,53 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
|
||||
if (nbttagcompound.hasKey("BMS")) {
|
||||
modeName = nbttagcompound.getString("BMS");
|
||||
}
|
||||
|
||||
// / SPECIES
|
||||
discoveredSpecies = new ArrayList<String>();
|
||||
int count = nbttagcompound.getInteger("SpeciesCount");
|
||||
for (int i = 0; i < count; i++) {
|
||||
discoveredSpecies.add(nbttagcompound.getString("SD" + i));
|
||||
}
|
||||
|
||||
// / MUTATIONS
|
||||
discoveredMutations = new ArrayList<String>();
|
||||
count = nbttagcompound.getInteger("MutationsCount");
|
||||
for (int i = 0; i < count; i++) {
|
||||
discoveredMutations.add(nbttagcompound.getString("MD" + i));
|
||||
if (nbttagcompound.hasKey(MODE_NAME_KEY)) {
|
||||
modeName = nbttagcompound.getString(MODE_NAME_KEY);
|
||||
}
|
||||
|
||||
readValuesFromNBT(nbttagcompound, discoveredSpecies, SPECIES_COUNT_KEY, SPECIES_KEY);
|
||||
readValuesFromNBT(nbttagcompound, discoveredMutations, MUTATIONS_COUNT_KEY, MUTATIONS_KEY);
|
||||
readValuesFromNBT(nbttagcompound, researchedMutations, RESEARCHED_COUNT_KEY, RESEARCHED_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
|
||||
if (modeName != null && !modeName.isEmpty()) {
|
||||
nbttagcompound.setString("BMS", modeName);
|
||||
nbttagcompound.setString(MODE_NAME_KEY, modeName);
|
||||
}
|
||||
|
||||
nbttagcompound.setString("TYPE", speciesRootUID());
|
||||
|
||||
// / SPECIES
|
||||
nbttagcompound.setInteger("SpeciesCount", discoveredSpecies.size());
|
||||
for (int i = 0; i < discoveredSpecies.size(); i++) {
|
||||
if (discoveredSpecies.get(i) != null) {
|
||||
nbttagcompound.setString("SD" + i, discoveredSpecies.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// / MUTATIONS
|
||||
nbttagcompound.setInteger("MutationsCount", discoveredMutations.size());
|
||||
for (int i = 0; i < discoveredMutations.size(); i++) {
|
||||
if (discoveredMutations.get(i) != null) {
|
||||
nbttagcompound.setString("MD" + i, discoveredMutations.get(i));
|
||||
}
|
||||
}
|
||||
nbttagcompound.setString(TYPE_KEY, speciesRootUID());
|
||||
|
||||
writeValuesToNBT(nbttagcompound, discoveredSpecies, SPECIES_COUNT_KEY, SPECIES_KEY);
|
||||
writeValuesToNBT(nbttagcompound, discoveredMutations, MUTATIONS_COUNT_KEY, MUTATIONS_KEY);
|
||||
writeValuesToNBT(nbttagcompound, researchedMutations, RESEARCHED_COUNT_KEY, RESEARCHED_KEY);
|
||||
}
|
||||
|
||||
private static final String MUTATION_FORMAT = "%s-%s=%s";
|
||||
private static void readValuesFromNBT(NBTTagCompound nbttagcompound, Collection<String> values, String countKey, String key) {
|
||||
values.clear();
|
||||
if (nbttagcompound.hasKey(countKey)) {
|
||||
final int count = nbttagcompound.getInteger(countKey);
|
||||
for (int i = 0; i < count; i++) {
|
||||
String value = nbttagcompound.getString(key + i);
|
||||
if (value != null && value.length() > 0) {
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeValuesToNBT(NBTTagCompound nbttagcompound, Collection<String> values, String countKey, String key) {
|
||||
final int count = values.size();
|
||||
nbttagcompound.setInteger(countKey, count);
|
||||
Iterator<String> iterator = values.iterator();
|
||||
for (int i = 0; i < count; i++) {
|
||||
String value = iterator.next();
|
||||
if (value != null && value.length() > 0) {
|
||||
nbttagcompound.setString(key + i, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getMutationString(IMutation mutation) {
|
||||
String species0 = mutation.getAllele0().getUID();
|
||||
@@ -153,12 +166,14 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
@Override
|
||||
public void registerMutation(IMutation mutation) {
|
||||
String mutationString = getMutationString(mutation);
|
||||
discoveredMutations.add(mutationString);
|
||||
markDirty();
|
||||
if (!discoveredMutations.contains(mutationString)) {
|
||||
discoveredMutations.add(mutationString);
|
||||
markDirty();
|
||||
|
||||
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(speciesRootUID());
|
||||
ForestryEvent event = new ForestryEvent.MutationDiscovered(speciesRoot, username, mutation, this);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(speciesRootUID());
|
||||
ForestryEvent event = new ForestryEvent.MutationDiscovered(speciesRoot, username, mutation, this);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,4 +209,20 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void researchMutation(IMutation mutation) {
|
||||
String mutationString = getMutationString(mutation);
|
||||
if (!researchedMutations.contains(mutationString)) {
|
||||
researchedMutations.add(mutationString);
|
||||
markDirty();
|
||||
|
||||
registerMutation(mutation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResearched(IMutation mutation) {
|
||||
String mutationString = getMutationString(mutation);
|
||||
return researchedMutations.contains(mutationString);
|
||||
}
|
||||
}
|
||||
@@ -136,16 +136,27 @@ public class ItemResearchNote extends ItemForestry {
|
||||
}
|
||||
|
||||
IBreedingTracker tracker = encoded.getRoot().getBreedingTracker(world, player.getGameProfile());
|
||||
if (tracker.isDiscovered(encoded)) {
|
||||
if (tracker.isResearched(encoded)) {
|
||||
player.addChatMessage(new ChatComponentTranslation("for.chat.cannotmemorizeagain"));
|
||||
return false;
|
||||
}
|
||||
|
||||
tracker.registerSpecies((IAlleleSpecies) encoded.getAllele0());
|
||||
tracker.registerSpecies((IAlleleSpecies) encoded.getAllele1());
|
||||
tracker.registerSpecies((IAlleleSpecies) encoded.getTemplate()[root.getKaryotypeKey().ordinal()]);
|
||||
tracker.registerMutation(encoded);
|
||||
IAlleleSpecies species0 = (IAlleleSpecies) encoded.getAllele0();
|
||||
IAlleleSpecies species1 = (IAlleleSpecies) encoded.getAllele1();
|
||||
IAlleleSpecies speciesResult = (IAlleleSpecies) encoded.getTemplate()[root.getKaryotypeKey().ordinal()];
|
||||
|
||||
tracker.registerSpecies(species0);
|
||||
tracker.registerSpecies(species1);
|
||||
tracker.registerSpecies(speciesResult);
|
||||
|
||||
tracker.researchMutation(encoded);
|
||||
player.addChatMessage(new ChatComponentTranslation("for.chat.memorizednote"));
|
||||
|
||||
player.addChatMessage(new ChatComponentTranslation("for.chat.memorizednote2",
|
||||
EnumChatFormatting.GRAY + species0.getName(),
|
||||
EnumChatFormatting.GRAY + species1.getName(),
|
||||
EnumChatFormatting.GREEN + speciesResult.getName()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IChromosome;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IMutation;
|
||||
@@ -82,6 +84,23 @@ public abstract class SpeciesRoot implements ISpeciesRoot {
|
||||
return combinations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IMutation> getCombinations(IAlleleSpecies parentSpecies0, IAlleleSpecies parentSpecies1, boolean shuffle) {
|
||||
List<IMutation> combinations = new ArrayList<IMutation>();
|
||||
|
||||
String parentSpecies1UID = parentSpecies1.getUID();
|
||||
for (IMutation mutation : getMutations(shuffle)) {
|
||||
if (mutation.isPartner(parentSpecies0)) {
|
||||
IAllele partner = mutation.getPartner(parentSpecies0);
|
||||
if (partner != null && partner.getUID().equals(parentSpecies1UID)) {
|
||||
combinations.add(mutation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return combinations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends IMutation> getPaths(IAllele result, IChromosomeType chromosomeType) {
|
||||
ArrayList<IMutation> paths = new ArrayList<IMutation>();
|
||||
|
||||
@@ -37,6 +37,7 @@ import forestry.apiculture.network.PacketActiveUpdate;
|
||||
import forestry.core.circuits.ContainerSolderingIron;
|
||||
import forestry.core.circuits.ItemCircuitBoard;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.genetics.BreedingTracker;
|
||||
import forestry.core.gui.ContainerLiquidTanks;
|
||||
import forestry.core.gui.ContainerSocketed;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
@@ -181,7 +182,7 @@ public class PacketHandler {
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
IBreedingTracker tracker = null;
|
||||
String type = packet.getTagCompound().getString("TYPE");
|
||||
String type = packet.getTagCompound().getString(BreedingTracker.TYPE_KEY);
|
||||
|
||||
ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(type);
|
||||
if (root != null) {
|
||||
|
||||
@@ -43,7 +43,6 @@ import forestry.core.genetics.Chromosome;
|
||||
import forestry.core.genetics.GenericRatings;
|
||||
import forestry.core.genetics.IndividualLiving;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.plugins.PluginLepidopterology;
|
||||
|
||||
public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
@@ -178,7 +177,7 @@ public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedEnvironment(World world, double x, double y, double z) {
|
||||
return isAcceptedEnvironment(world, (int)x, (int)y, (int)z);
|
||||
return isAcceptedEnvironment(world, (int) x, (int) y, (int) z);
|
||||
}
|
||||
|
||||
private boolean isAcceptedEnvironment(World world, int x, int y, int z) {
|
||||
|
||||
Reference in new issue
Block a user