mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 06:53:20 +00:00
Cleaned up some more, fixed infinite loop with cancelable annotation, Client now compiles and enters world just fine.
This commit is contained in:
1 parent
ba9e3a251c
commit
f31b8a98a9
23 files changed
+230
-189
No files matched your search
@@ -0,0 +1,85 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
import net.minecraft.src.*;
|
||||
|
||||
public class DimensionManager
|
||||
{
|
||||
private static Hashtable<Integer, WorldProvider> providers = new Hashtable<Integer, WorldProvider>();
|
||||
private static Hashtable<Integer, Boolean> spawnSettings = new Hashtable<Integer, Boolean>();
|
||||
private static Hashtable<Integer, World> worlds = new Hashtable<Integer, World>();
|
||||
private static boolean hasInit = false;
|
||||
|
||||
public static boolean registerDimension(int id, WorldProvider provider, boolean keepLoaded)
|
||||
{
|
||||
if (providers.containsValue(id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
providers.put(id, provider);
|
||||
spawnSettings.put(id, keepLoaded);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void init()
|
||||
{
|
||||
if (hasInit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
registerDimension( 0, new WorldProviderSurface(), true);
|
||||
registerDimension(-1, new WorldProviderHell(), true);
|
||||
registerDimension( 1, new WorldProviderEnd(), false);
|
||||
}
|
||||
|
||||
public static WorldProvider getProvider(int id)
|
||||
{
|
||||
return providers.get(id);
|
||||
}
|
||||
|
||||
public static Integer[] getIDs()
|
||||
{
|
||||
return providers.keySet().toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
public static void setWorld(int id, World world)
|
||||
{
|
||||
worlds.put(id, world);
|
||||
}
|
||||
|
||||
public static World getWorld(int id)
|
||||
{
|
||||
return worlds.get(id);
|
||||
}
|
||||
|
||||
public static World[] getWorlds()
|
||||
{
|
||||
return worlds.values().toArray(new World[0]);
|
||||
}
|
||||
|
||||
public static boolean shouldLoadSpawn(int id)
|
||||
{
|
||||
return spawnSettings.contains(id) && spawnSettings.get(id);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
public static WorldProvider createProviderFor(int i) {
|
||||
try {
|
||||
if (providers.containsKey(i))
|
||||
return getProvider(i).getClass().newInstance();
|
||||
else
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
FMLCommonHandler.instance().getFMLLogger().log(Level.SEVERE,String.format("An error occured trying to create an instance of WorldProvider %d (%s)",i,getProvider(i).getClass().getSimpleName()),e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public class Event
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
cls = cls.getSuperclass();
|
||||
}
|
||||
isCancelable = found;
|
||||
}
|
||||
|
||||
@@ -21,33 +21,40 @@ public class EventTransformer implements IClassTransformer
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, byte[] bytes)
|
||||
{
|
||||
{
|
||||
if (name.equals("net.minecraftforge.event.Event") || name.startsWith("net.minecraft.src.") || name.indexOf('.') == -1)
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
ClassReader cr = new ClassReader(bytes);
|
||||
ClassNode classNode = new ClassNode();
|
||||
cr.accept(classNode, 0);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
buildEvents(classNode);
|
||||
if (buildEvents(classNode))
|
||||
{
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_MAXS | COMPUTE_FRAMES);
|
||||
classNode.accept(cw);
|
||||
return cw.toByteArray();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_MAXS | COMPUTE_FRAMES);
|
||||
classNode.accept(cw);
|
||||
|
||||
return cw.toByteArray();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void buildEvents(ClassNode classNode) throws Exception
|
||||
private boolean buildEvents(ClassNode classNode) throws Exception
|
||||
{
|
||||
Class<?> parent = Class.forName(classNode.superName.replace('/', '.'));
|
||||
Class<?> parent = this.getClass().getClassLoader().loadClass(classNode.superName.replace('/', '.'));
|
||||
if (!Event.class.isAssignableFrom(parent))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean hasSetup = false;
|
||||
@@ -79,7 +86,7 @@ public class EventTransformer implements IClassTransformer
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +134,7 @@ public class EventTransformer implements IClassTransformer
|
||||
method.instructions.add(new FieldInsnNode(GETSTATIC, classNode.name, "LISTENER_LIST", tList.getDescriptor()));
|
||||
method.instructions.add(new InsnNode(ARETURN));
|
||||
classNode.methods.add(method);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user