aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/bees
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
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')
-rw-r--r--src/main/java/gregtech/common/bees/GT_AlleleHelper.java18
-rw-r--r--src/main/java/gregtech/common/bees/GT_Bee_Mutation.java49
2 files changed, 40 insertions, 27 deletions
diff --git a/src/main/java/gregtech/common/bees/GT_AlleleHelper.java b/src/main/java/gregtech/common/bees/GT_AlleleHelper.java
index 3431f96eb4..cb54f5d4a1 100644
--- a/src/main/java/gregtech/common/bees/GT_AlleleHelper.java
+++ b/src/main/java/gregtech/common/bees/GT_AlleleHelper.java
@@ -9,6 +9,8 @@ import forestry.core.config.Constants;
import forestry.core.genetics.alleles.*;
import forestry.core.utils.vect.IVect;
import forestry.plugins.PluginManager;
+import gregtech.GT_Mod;
+import org.apache.commons.lang3.reflect.FieldUtils;
import java.util.EnumMap;
import java.util.HashMap;
@@ -19,7 +21,7 @@ public class GT_AlleleHelper extends AlleleHelper {
private static final String modId = Constants.ID;
- private final Map<Class, Map<?, ? extends IAllele>> alleleMaps = new HashMap<>();
+ private Map<Class, Map<?, ? extends IAllele>> alleleMaps = new HashMap<>();
public void init() {
if (PluginManager.Module.APICULTURE.isEnabled()) {
@@ -114,20 +116,28 @@ public class GT_AlleleHelper extends AlleleHelper {
}
public static void initialisation(){
- AlleleHelper.instance = new GT_AlleleHelper();
- AlleleHelper.instance.init();
- }
+ GT_AlleleHelper helper = new GT_AlleleHelper();
+ try {
+ helper.alleleMaps = (Map<Class, Map<?, ? extends IAllele>>) FieldUtils.readField(FieldUtils.getField(AlleleHelper.class,"alleleMaps",true),AlleleHelper.instance,true);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ AlleleHelper.instance = helper;
+ //AlleleHelper.instance.init();
+ }
@Override
public <T extends Enum<T> & IChromosomeType> void set(IAllele[] alleles, T chromosomeType, IAllele allele) {
if (allele == null) {
+ GT_Mod.GT_FML_LOGGER.info("Allele is null!");
return;
}
if (!chromosomeType.getAlleleClass().isInstance(allele)) {
+ GT_Mod.GT_FML_LOGGER.info("chromosomeType is not an instance of allele!"+allele.getName());
return;
}
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