aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/common/bees/GT_Bee_Mutation.java')
-rw-r--r--src/main/java/gregtech/common/bees/GT_Bee_Mutation.java44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java b/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
index a83b4c68f1..7b61505fc7 100644
--- a/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
+++ b/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
@@ -8,6 +8,7 @@ import forestry.apiculture.genetics.BeeMutation;
import forestry.core.genetics.mutations.Mutation;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
+import org.apache.commons.lang3.reflect.FieldUtils;
import java.lang.reflect.Field;
import java.util.List;
@@ -15,9 +16,9 @@ import java.util.List;
public class GT_Bee_Mutation extends BeeMutation {
- private int split = 1;
+ private float split = 1;
- public GT_Bee_Mutation(IAlleleBeeSpecies bee0, IAlleleBeeSpecies bee1, IAllele[] result, int chance, int split) {
+ public GT_Bee_Mutation(IAlleleBeeSpecies bee0, IAlleleBeeSpecies bee1, IAllele[] result, int chance, float split) {
super(bee0, bee1, result, chance);
this.split = split;
BeeManager.beeRoot.registerMutation(this);
@@ -25,20 +26,19 @@ public class GT_Bee_Mutation extends BeeMutation {
@Override
public float getBaseChance() {
- return ((float) ((float)super.getBaseChance() / ((float)split)));
+ return super.getBaseChance() / split;
}
@Override
public float getChance(IBeeHousing housing, IAlleleBeeSpecies allele0, IAlleleBeeSpecies allele1, IBeeGenome genome0, IBeeGenome genome1) {
- World world = housing.getWorld();
- ChunkCoordinates housingCoordinates = housing.getCoordinates();
- int x = housingCoordinates.posX;
- int y = housingCoordinates.posY;
- int z = housingCoordinates.posZ;
+ World world = housing != null ? housing.getWorld() : null;
+ ChunkCoordinates housingCoordinates = housing != null ? housing.getCoordinates() : null;
+ int x = housingCoordinates != null ? housingCoordinates.posX : 0;
+ int y = housingCoordinates != null ? housingCoordinates.posY : 0;
+ int z = housingCoordinates != null ? housingCoordinates.posZ : 0;
float processedChance = getBasicChance(world, x, y, z, allele0, allele1, genome0, genome1);
-
if (processedChance <= 0f) {
return 0f;
}
@@ -52,25 +52,27 @@ public class GT_Bee_Mutation extends BeeMutation {
return processedChance;
}
- protected float getBasicChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
+ private float getBasicChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
float mutationChance = this.getBaseChance();
List<IMutationCondition> mutationConditions = null;
+ Field f = FieldUtils.getDeclaredField(Mutation.class, "mutationConditions", true);
+ if (f == null)
+ f = FieldUtils.getField(Mutation.class, "mutationConditions", true);
+ if (f == null)
+ return mutationChance;
try {
- Field f = Mutation.class.getDeclaredField("mutationConditions");
- f.setAccessible(true);
- Object o = f.get(this);
- mutationConditions = o instanceof List ? (List) o : null ;
- } catch (NoSuchFieldException | IllegalAccessException e) {
+ mutationConditions = f.get(this) instanceof List ? (List) f.get(this) : null;
+ } catch (IllegalAccessException e) {
e.printStackTrace();
}
if (mutationConditions != null)
- for (IMutationCondition mutationCondition : mutationConditions) {
- mutationChance *= mutationCondition.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
- if (mutationChance == 0) {
- return 0;
+ for (IMutationCondition mutationCondition : mutationConditions) {
+ mutationChance *= mutationCondition.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
+ if (mutationChance == 0) {
+ return 0;
+ }
}
- }
return mutationChance;
}
-}
+} \ No newline at end of file