mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-18 19:39:37 +00:00
Fix #50 Crash server on startup
This commit is contained in:
1 parent
96e4814ae3
commit
8986256b12
1 file changed
+34
-2
@@ -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> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user