aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/bees
diff options
context:
space:
mode:
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.java44
2 files changed, 37 insertions, 25 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 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