mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-28 07:56:01 +00:00
Make reflection Java 12+ compatible, mark mods as children of the main mod (#26)
* Update buildscript and dependencies * Update NEI api * Make reflection Java 12+ compatible, mark mods as children of the main mod
This commit is contained in:
1 parent
c70a3448e5
commit
f2f1dd1195
7 files changed
+106
-85
No files matched your search
@@ -3,7 +3,7 @@ package binnie.extratrees;
|
||||
import binnie.core.block.TileEntityMetadata;
|
||||
import forestry.api.arboriculture.EnumWoodType;
|
||||
import forestry.arboriculture.tiles.TileWood;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -14,9 +14,21 @@ import net.minecraft.world.WorldSettings;
|
||||
import net.minecraft.world.WorldSettings.GameType;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import sun.reflect.ReflectionFactory;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
public class FakeWorld extends World {
|
||||
private static Unsafe unsafe;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
unsafe = (Unsafe) theUnsafe.get(null);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static FakeWorld instance = SilentObjectCreator.create(FakeWorld.class);
|
||||
|
||||
protected Block block;
|
||||
@@ -106,22 +118,10 @@ public class FakeWorld extends World {
|
||||
* Creating objects without calling constructors.
|
||||
*/
|
||||
public static <T> T create(Class<T> clazz) {
|
||||
return create(clazz, Object.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating objects without calling constructors.
|
||||
*/
|
||||
public static <T> T create(Class<T> clazz, Class<? super T> parent) {
|
||||
try {
|
||||
ReflectionFactory rf = ReflectionFactory.getReflectionFactory();
|
||||
Constructor objDef = parent.getDeclaredConstructor();
|
||||
Constructor intConstr = rf.newConstructorForSerialization(clazz, objDef);
|
||||
return clazz.cast(intConstr.newInstance());
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot create object", e);
|
||||
return clazz.cast(unsafe.allocateInstance(clazz));
|
||||
} catch (InstantiationException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import binnie.extratrees.ExtraTrees;
|
||||
import binnie.extratrees.block.FruitPod;
|
||||
import binnie.extratrees.config.ConfigurationMain;
|
||||
import binnie.extratrees.item.Food;
|
||||
import com.gtnewhorizon.gtnhlib.reflect.Fields;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import forestry.api.arboriculture.EnumTreeChromosome;
|
||||
@@ -18,7 +19,6 @@ import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IFruitFamily;
|
||||
import forestry.arboriculture.FruitProviderNone;
|
||||
import forestry.arboriculture.genetics.alleles.AlleleTreeSpecies;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -254,12 +254,9 @@ public enum ExtraTreeFruitGene implements IAlleleFruit, IFruitProvider {
|
||||
try {
|
||||
IAlleleFruit lemon = (IAlleleFruit) AlleleManager.alleleRegistry.getAllele("forestry.fruitLemon");
|
||||
FruitProviderNone prov = (FruitProviderNone) lemon.getProvider();
|
||||
Field f = FruitProviderNone.class.getDeclaredField("family");
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
f.setAccessible(true);
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(f, f.getModifiers() & 0xFFFFFFEF);
|
||||
f.set(prov, familyCitrus);
|
||||
Fields.ofClass(FruitProviderNone.class)
|
||||
.getField(Fields.LookupType.DECLARED, "family", IFruitFamily.class)
|
||||
.setValue(prov, familyCitrus);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user