Compare commits

...
3 Commits
Author SHA1 Message Date
Martin Robertz 6cf6e9699a update deps 2024-06-27 21:48:49 +02:00
github-actions[bot]andGitHub GTNH Actions b61cf685e4 spotlessApply (#77)
Co-authored-by: GitHub GTNH Actions <>
2024-06-27 14:52:49 +01:00
GTNH-Colen da4f06a618 Fix bee breeding overflowing with mutation. 2024-06-27 14:30:45 +01:00
5 changed files with 48 additions and 6 deletions

No files matched your search

+1 -1
View File
@@ -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;
}
}
}