mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 17:14:46 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cf6e9699a | ||
|
|
b61cf685e4 | ||
|
|
da4f06a618 |
No files matched your search
+1
-1
@@ -3,7 +3,7 @@
|
||||
dependencies {
|
||||
api('curse.maven:cofh-lib-220333:2388748')
|
||||
compileOnlyApi('com.github.GTNewHorizons:Angelica:1.0.0-alpha52:api')
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.6.8-GTNH:dev')
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.6.11-GTNH:dev')
|
||||
compileOnly('com.github.GTNewHorizons:inventory-tweaks:1.6.2:api')
|
||||
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.39:api')
|
||||
compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.genetics;
|
||||
|
||||
import static forestry.core.utils.MathUtil.safeAdd;
|
||||
import static forestry.core.utils.MathUtil.safeMultiply;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -699,9 +702,9 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
|
||||
// boost chance for researched mutations
|
||||
if (breedingTracker.isResearched(beeMutation)) {
|
||||
float mutationBoost = chance * (Config.researchMutationBoostMultiplier - 1.0f);
|
||||
float mutationBoost = safeMultiply(chance, Config.researchMutationBoostMultiplier - 1.0f);
|
||||
mutationBoost = Math.min(Config.maxResearchMutationBoostPercent, mutationBoost);
|
||||
chance += mutationBoost;
|
||||
chance = safeAdd(chance, mutationBoost);
|
||||
}
|
||||
|
||||
if (chance > world.rand.nextFloat() * 100) {
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.genetics;
|
||||
|
||||
import static forestry.core.utils.MathUtil.safeMultiply;
|
||||
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -49,8 +51,12 @@ public class BeeMutation extends Mutation implements IBeeMutationCustom {
|
||||
IBeeModifier beeHousingModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
|
||||
IBeeModifier beeModeModifier = BeeManager.beeRoot.getBeekeepingMode(world).getBeeModifier();
|
||||
|
||||
processedChance *= beeHousingModifier.getMutationModifier(genome0, genome1, processedChance);
|
||||
processedChance *= beeModeModifier.getMutationModifier(genome0, genome1, processedChance);
|
||||
processedChance = safeMultiply(
|
||||
processedChance,
|
||||
beeHousingModifier.getMutationModifier(genome0, genome1, processedChance));
|
||||
processedChance = safeMultiply(
|
||||
processedChance,
|
||||
beeModeModifier.getMutationModifier(genome0, genome1, processedChance));
|
||||
|
||||
return processedChance;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import static forestry.core.utils.MathUtil.safeMultiply;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -126,7 +128,9 @@ public abstract class Mutation implements IMutationCustom {
|
||||
IGenome genome1, IClimateProvider climate) {
|
||||
float mutationChance = chance;
|
||||
for (IMutationCondition mutationCondition : mutationConditions) {
|
||||
mutationChance *= mutationCondition.getChance(world, x, y, z, allele0, allele1, genome0, genome1, climate);
|
||||
mutationChance = safeMultiply(
|
||||
mutationChance,
|
||||
mutationCondition.getChance(world, x, y, z, allele0, allele1, genome0, genome1, climate));
|
||||
if (mutationChance == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package forestry.core.utils;
|
||||
|
||||
public class MathUtil {
|
||||
|
||||
public static float safeMultiply(float a, float b) {
|
||||
if (a > 0 && b > 0 && a > Float.MAX_VALUE / b) {
|
||||
return Float.MAX_VALUE;
|
||||
} else if (a > 0 && b < 0 && a > Float.MIN_VALUE / b) {
|
||||
return Float.MIN_VALUE;
|
||||
} else if (a < 0 && b > 0 && a < Float.MIN_VALUE / b) {
|
||||
return Float.MIN_VALUE;
|
||||
} else if (a < 0 && b < 0 && a < Float.MAX_VALUE / b) {
|
||||
return Float.MAX_VALUE;
|
||||
} else {
|
||||
return a * b;
|
||||
}
|
||||
}
|
||||
|
||||
public static float safeAdd(float a, float b) {
|
||||
if (a > 0 && b > 0 && a > Float.MAX_VALUE - b) {
|
||||
return Float.MAX_VALUE;
|
||||
} else if (a < 0 && b < 0 && a < Float.MIN_VALUE - b) {
|
||||
return Float.MIN_VALUE;
|
||||
} else {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user