diff --git a/src/main/java/binnie/extratrees/FakeWorld.java b/src/main/java/binnie/extratrees/FakeWorld.java index a7570216..0ca732c9 100644 --- a/src/main/java/binnie/extratrees/FakeWorld.java +++ b/src/main/java/binnie/extratrees/FakeWorld.java @@ -13,15 +13,19 @@ 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 java.lang.reflect.Constructor; public class FakeWorld extends World { - public static FakeWorld instance = new FakeWorld(); + public static FakeWorld instance = SilentObjectCreator.create(FakeWorld.class); protected Block block; protected int metadata; protected TileEntity te; - public FakeWorld() { + //It is never called. + private FakeWorld() { super(null, "", null, new WorldSettings(Long.MAX_VALUE, GameType.NOT_SET, false, false, WorldType.FLAT), null); } @@ -100,4 +104,32 @@ public class FakeWorld extends World { return null; } + public static class SilentObjectCreator { + /** + * Creating objects without calling constructors. + */ + public static T create(Class clazz) { + return create(clazz, Object.class); + } + + /** + * Creating objects without calling constructors. + */ + public static T create(Class clazz, + Class 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); + } + } + } }