aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
diff options
context:
space:
mode:
authorKiwi <42833050+Kiwi233@users.noreply.github.com>2020-05-24 08:28:19 +0800
committerGitHub <noreply@github.com>2020-05-24 08:28:19 +0800
commitf0bce85d3faf040d87a22d83250ae2d9767c3642 (patch)
treeed60c1d975c8b06a27cae03d148714f7bb9e9805 /src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
parentac7282a30ef161101cabc921e52db5c5d7e0096c (diff)
parentd6c19a9b6434c8a4c59ea8452603f85cfd2ad208 (diff)
downloadGT5-Unofficial-f0bce85d3faf040d87a22d83250ae2d9767c3642.tar.gz
GT5-Unofficial-f0bce85d3faf040d87a22d83250ae2d9767c3642.tar.bz2
GT5-Unofficial-f0bce85d3faf040d87a22d83250ae2d9767c3642.zip
Merge pull request #1 from GTNewHorizons/experimental
5/24
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.java49
1 files changed, 26 insertions, 23 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 852f00e6d6..7b61505fc7 100644
--- a/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
+++ b/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java
@@ -5,8 +5,10 @@ import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import forestry.api.genetics.IMutationCondition;
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;
@@ -14,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);
@@ -24,19 +26,18 @@ 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;
-
- float processedChance = getbasicChance(world, x, y, z, allele0, allele1, genome0, genome1);
+ 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;
@@ -51,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) {
- float mutationChance = getBaseChance();
+ 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 = this.getClass().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