From d2c7a856c178eb4e0f1fa9d931af2859ecc0f1fb Mon Sep 17 00:00:00 2001 From: LexManos Date: Fri, 24 Feb 2012 02:38:16 -0800 Subject: [PATCH] Initial attempt at server side extra dimensions support. Mods must register there dimensions on load, by calling DimensionManager.registerDimension(uniqueID, WorldProvier, boolean) Mods are resposible for writing there own transporter blocks. Initial commit, needs some more testing and design thoughts. --- .../minecraft/src/forge/DimensionManager.java | 70 +++++ .../server/MinecraftServer.java.patch | 250 ++++++++++++++++++ .../src/ConsoleCommandHandler.java.patch | 81 ++++++ .../src/GuiStatsComponent.java.patch | 51 ++++ .../net/minecraft/src/ModLoader.java.patch | 20 +- .../net/minecraft/src/ModLoaderMp.java.patch | 26 ++ .../minecraft/src/PlayerNBTManager.java.patch | 24 ++ .../net/minecraft/src/SaveOldDir.java.patch | 30 +++ .../src/ServerConfigurationManager.java.patch | 147 ++++++++++ .../minecraft/src/WorldProvider.java.patch | 71 +++++ .../minecraft/src/WorldProviderEnd.java.patch | 25 ++ .../src/WorldProviderHell.java.patch | 31 +++ .../src/WorldProviderSurface.java.patch | 25 ++ .../net/minecraft/src/WorldServer.java.patch | 29 +- 14 files changed, 876 insertions(+), 4 deletions(-) create mode 100644 forge/forge_common/net/minecraft/src/forge/DimensionManager.java create mode 100644 forge/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/GuiStatsComponent.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/ModLoaderMp.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/PlayerNBTManager.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/SaveOldDir.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/ServerConfigurationManager.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/WorldProvider.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/WorldProviderEnd.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/WorldProviderHell.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/WorldProviderSurface.java.patch diff --git a/forge/forge_common/net/minecraft/src/forge/DimensionManager.java b/forge/forge_common/net/minecraft/src/forge/DimensionManager.java new file mode 100644 index 000000000..ffe993d36 --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/DimensionManager.java @@ -0,0 +1,70 @@ +package net.minecraft.src.forge; + +import java.util.Hashtable; + +import net.minecraft.src.*; + +public class DimensionManager +{ + private static Hashtable providers = new Hashtable(); + private static Hashtable spawnSettings = new Hashtable(); + private static Hashtable worlds = new Hashtable(); + 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(); + } +} diff --git a/forge/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch b/forge/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch new file mode 100644 index 000000000..6296a2a3d --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch @@ -0,0 +1,250 @@ +--- ../src_base/minecraft_server/net/minecraft/server/MinecraftServer.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/server/MinecraftServer.java 0000-00-00 00:00:00.000000000 -0000 +@@ -7,6 +7,7 @@ + import java.util.ArrayList; + import java.util.Collections; + import java.util.HashMap; ++import java.util.Hashtable; + import java.util.Iterator; + import java.util.List; + import java.util.Random; +@@ -42,12 +43,14 @@ + import net.minecraft.src.ThreadServerApplication; + import net.minecraft.src.ThreadSleepForever; + import net.minecraft.src.Vec3D; ++import net.minecraft.src.World; + import net.minecraft.src.WorldInfo; + import net.minecraft.src.WorldManager; + import net.minecraft.src.WorldProvider; + import net.minecraft.src.WorldServer; + import net.minecraft.src.WorldServerMulti; + import net.minecraft.src.WorldSettings; ++import net.minecraft.src.forge.DimensionManager; + + public class MinecraftServer + implements Runnable, ICommandListener, IServer +@@ -58,9 +61,10 @@ + private int serverPort; + public NetworkListenThread networkServer; + public PropertyManager propertyManagerObj; +- public WorldServer worldMngr[]; ++ //public WorldServer worldMngr[]; + public long field_40027_f[]; +- public long field_40028_g[][]; ++ //public long field_40028_g[][]; ++ public Hashtable worldTickTimes = new Hashtable(); + public ServerConfigurationManager configManager; + private ConsoleCommandHandler commandHandler; + private boolean serverRunning; +@@ -70,7 +74,7 @@ + public int percentDone; + private List playersOnline; + private List commands; +- public EntityTracker entityTracker[]; ++ //public EntityTracker entityTracker[]; + public boolean onlineMode; + public boolean spawnPeacefulMobs; + public boolean field_44002_p; +@@ -88,7 +92,7 @@ + deathTime = 0; + playersOnline = new ArrayList(); + commands = Collections.synchronizedList(new ArrayList()); +- entityTracker = new EntityTracker[3]; ++ //entityTracker = new EntityTracker[3]; + new ThreadSleepForever(this); + } + +@@ -143,9 +147,11 @@ + logger.warning("To change this, set \"online-mode\" to \"true\" in the server.settings file."); + } + configManager = new ServerConfigurationManager(this); ++ /* + entityTracker[0] = new EntityTracker(this, 0); + entityTracker[1] = new EntityTracker(this, -1); + entityTracker[2] = new EntityTracker(this, 1); ++ */ + long l = System.nanoTime(); + String s = propertyManagerObj.getStringProperty("level-name", "world"); + String s1 = propertyManagerObj.getStringProperty("level-seed", ""); +@@ -196,46 +202,43 @@ + logger.info("Converting map!"); + isaveformat.convertMapFormat(s, new ConvertProgressUpdater(this)); + } +- worldMngr = new WorldServer[3]; +- field_40028_g = new long[worldMngr.length][100]; ++ //worldMngr = new WorldServer[3]; ++ //field_40028_g = new long[3][100]; + int i = propertyManagerObj.getIntProperty("gamemode", 0); + i = WorldSettings.validGameType(i); + logger.info((new StringBuilder()).append("Default game type: ").append(i).toString()); + boolean flag = propertyManagerObj.getBooleanProperty("generate-structures", true); + WorldSettings worldsettings = new WorldSettings(l, i, flag, false, enumworldtype); + SaveOldDir saveolddir = new SaveOldDir(new File("."), s, true); +- for (int j = 0; j < worldMngr.length; j++) +- { +- byte byte0 = 0; +- if (j == 1) +- { +- byte0 = -1; +- } +- if (j == 2) +- { +- byte0 = 1; +- } +- if (j == 0) +- { +- worldMngr[j] = new WorldServer(this, saveolddir, s, byte0, worldsettings); +- } +- else +- { +- worldMngr[j] = new WorldServerMulti(this, saveolddir, s, byte0, worldsettings, worldMngr[0]); +- } +- worldMngr[j].addWorldAccess(new WorldManager(this, worldMngr[j])); +- worldMngr[j].difficultySetting = propertyManagerObj.getIntProperty("difficulty", 1); +- worldMngr[j].setAllowedSpawnTypes(propertyManagerObj.getBooleanProperty("spawn-monsters", true), spawnPeacefulMobs); +- worldMngr[j].getWorldInfo().setGameType(i); +- configManager.setPlayerManager(worldMngr); ++ ++ WorldServer overWorld = new WorldServer(this, saveolddir, s, 0, worldsettings); ++ overWorld.addWorldAccess(new WorldManager(this, overWorld)); ++ overWorld.difficultySetting = propertyManagerObj.getIntProperty("difficulty", 1); ++ overWorld.setAllowedSpawnTypes(propertyManagerObj.getBooleanProperty("spawn-monsters", true), spawnPeacefulMobs); ++ overWorld.getWorldInfo().setGameType(i); ++ worldTickTimes.put(0, new long[100]); ++ configManager.setPlayerManager(new WorldServer[]{ overWorld }); ++ ++ for (Integer id : DimensionManager.getIDs()) ++ { ++ if (id == 0) ++ { ++ continue; ++ } ++ WorldServer world = new WorldServerMulti(this, saveolddir, s, id, worldsettings, overWorld); ++ world.addWorldAccess(new WorldManager(this, overWorld)); ++ world.difficultySetting = propertyManagerObj.getIntProperty("difficulty", 1); ++ world.setAllowedSpawnTypes(propertyManagerObj.getBooleanProperty("spawn-monsters", true), spawnPeacefulMobs); ++ world.getWorldInfo().setGameType(i); ++ worldTickTimes.put(id, new long[100]); + } + + char c = \304; + long l1 = System.currentTimeMillis(); +- for (int k = 0; k < 1; k++) ++ for (Integer id : DimensionManager.getIDs()) + { +- logger.info((new StringBuilder()).append("Preparing start region for level ").append(k).toString()); +- WorldServer worldserver = worldMngr[k]; ++ logger.info("Preparing start region for level " + id); ++ WorldServer worldserver = (WorldServer)DimensionManager.getWorld(id); + ChunkCoordinates chunkcoordinates = worldserver.getSpawnPoint(); + for (int i1 = -c; i1 <= c && serverRunning; i1 += 16) + { +@@ -278,9 +281,9 @@ + private void saveServerWorld() + { + logger.info("Saving chunks"); +- for (int i = 0; i < worldMngr.length; i++) ++ for (World world : DimensionManager.getWorlds()) + { +- WorldServer worldserver = worldMngr[i]; ++ WorldServer worldserver = (WorldServer)world; + worldserver.saveWorld(true, null); + worldserver.func_30006_w(); + } +@@ -293,12 +296,12 @@ + { + configManager.savePlayerStates(); + } +- for (int i = 0; i < worldMngr.length; i++) ++ for (World worldserver : DimensionManager.getWorlds()) + { +- WorldServer worldserver = worldMngr[i]; + if (worldserver != null) + { + saveServerWorld(); ++ break; + } + } + } +@@ -333,7 +336,7 @@ + } + l1 += l3; + l = l2; +- if (worldMngr[0].isAllPlayersFullyAsleep()) ++ if (((WorldServer)DimensionManager.getWorld(0)).isAllPlayersFullyAsleep()) + { + doTick(); + l1 = 0L; +@@ -426,12 +429,12 @@ + AxisAlignedBB.clearBoundingBoxPool(); + Vec3D.initialize(); + deathTime++; +- for (int j = 0; j < worldMngr.length; j++) ++ for (Integer j : DimensionManager.getIDs()) + { + long l1 = System.nanoTime(); + if (j == 0 || propertyManagerObj.getBooleanProperty("allow-nether", true)) + { +- WorldServer worldserver = worldMngr[j]; ++ WorldServer worldserver = (WorldServer)DimensionManager.getWorld(j); + if (deathTime % 20 == 0) + { + configManager.sendPacketToAllPlayersInDimension(new Packet4UpdateTime(worldserver.getWorldTime()), worldserver.worldProvider.worldType); +@@ -440,14 +443,14 @@ + while (worldserver.updatingLighting()) ; + worldserver.updateEntities(); + } +- field_40028_g[j][deathTime % 100] = System.nanoTime() - l1; ++ worldTickTimes.get(j)[deathTime % 100] = System.nanoTime() - l1; + } + + networkServer.handleNetworkListenThread(); + configManager.onTick(); +- for (int k = 0; k < entityTracker.length; k++) ++ for (World world : DimensionManager.getWorlds()) + { +- entityTracker[k].updateTrackedEntities(); ++ ((WorldServer)world).entityTracker.updateTrackedEntities(); + } + + for (int i1 = 0; i1 < playersOnline.size(); i1++) +@@ -525,34 +528,17 @@ + + public WorldServer getWorldManager(int i) + { +- if (i == -1) +- { +- return worldMngr[1]; +- } +- if (i == 1) +- { +- return worldMngr[2]; +- } +- else ++ WorldServer ret = (WorldServer)DimensionManager.getWorld(i); ++ if (ret == null) + { +- return worldMngr[0]; ++ ret = (WorldServer)DimensionManager.getWorld(0); + } ++ return ret; + } + + public EntityTracker getEntityTracker(int i) + { +- if (i == -1) +- { +- return entityTracker[1]; +- } +- if (i == 1) +- { +- return entityTracker[2]; +- } +- else +- { +- return entityTracker[0]; +- } ++ return getWorldManager(i).entityTracker; + } + + public int getIntProperty(String s, int i) diff --git a/forge/patches/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java.patch new file mode 100644 index 000000000..3af34583b --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java.patch @@ -0,0 +1,81 @@ +--- ../src_base/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java 0000-00-00 00:00:00.000000000 -0000 +@@ -3,6 +3,7 @@ + import java.util.*; + import java.util.logging.Logger; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.src.forge.DimensionManager; + + public class ConsoleCommandHandler + { +@@ -40,10 +41,9 @@ + { + serverconfigurationmanager.savePlayerStates(); + } +- for (int i = 0; i < minecraftServer.worldMngr.length; i++) ++ for (World world : DimensionManager.getWorlds()) + { +- WorldServer worldserver = minecraftServer.worldMngr[i]; +- worldserver.saveWorld(true, null); ++ world.saveWorld(true, null); + } + + sendNoticeToOps(s1, "Save complete."); +@@ -51,19 +51,17 @@ + else if (s.toLowerCase().startsWith("save-off")) + { + sendNoticeToOps(s1, "Disabling level saving.."); +- for (int j = 0; j < minecraftServer.worldMngr.length; j++) ++ for (World world : DimensionManager.getWorlds()) + { +- WorldServer worldserver1 = minecraftServer.worldMngr[j]; +- worldserver1.levelSaving = true; ++ ((WorldServer)world).levelSaving = true; + } + } + else if (s.toLowerCase().startsWith("save-on")) + { + sendNoticeToOps(s1, "Enabling level saving.."); +- for (int k = 0; k < minecraftServer.worldMngr.length; k++) ++ for (World world : DimensionManager.getWorlds()) + { +- WorldServer worldserver2 = minecraftServer.worldMngr[k]; +- worldserver2.levelSaving = false; ++ ((WorldServer)world).levelSaving = false; + } + } + else if (s.toLowerCase().startsWith("op ")) +@@ -291,20 +289,18 @@ + int i1 = Integer.parseInt(as4[2]); + if ("add".equalsIgnoreCase(s12)) + { +- for (int i2 = 0; i2 < minecraftServer.worldMngr.length; i2++) ++ for (World world : DimensionManager.getWorlds()) + { +- WorldServer worldserver3 = minecraftServer.worldMngr[i2]; +- worldserver3.advanceTime(worldserver3.getWorldTime() + (long)i1); ++ world.advanceTime(world.getWorldTime() + (long)i1); + } + + sendNoticeToOps(s1, (new StringBuilder()).append("Added ").append(i1).append(" to time").toString()); + } + else if ("set".equalsIgnoreCase(s12)) + { +- for (int j2 = 0; j2 < minecraftServer.worldMngr.length; j2++) ++ for (World world : DimensionManager.getWorlds()) + { +- WorldServer worldserver4 = minecraftServer.worldMngr[j2]; +- worldserver4.advanceTime(i1); ++ world.advanceTime(i1); + } + + sendNoticeToOps(s1, (new StringBuilder()).append("Set time to ").append(i1).toString()); +@@ -347,7 +343,7 @@ + } + else if (s.toLowerCase().startsWith("toggledownfall")) + { +- minecraftServer.worldMngr[0].commandToggleDownfall(); ++ ((WorldServer)DimensionManager.getWorld(0)).commandToggleDownfall(); + icommandlistener.log("Toggling rain and snow, hold on..."); + } + else if (s.toLowerCase().startsWith("banlist")) diff --git a/forge/patches/minecraft_server/net/minecraft/src/GuiStatsComponent.java.patch b/forge/patches/minecraft_server/net/minecraft/src/GuiStatsComponent.java.patch new file mode 100644 index 000000000..ecf3f0b8d --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/GuiStatsComponent.java.patch @@ -0,0 +1,51 @@ +--- ../src_base/minecraft_server/net/minecraft/src/GuiStatsComponent.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/GuiStatsComponent.java 0000-00-00 00:00:00.000000000 -0000 +@@ -5,6 +5,7 @@ + import javax.swing.JComponent; + import javax.swing.Timer; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.src.forge.DimensionManager; + + public class GuiStatsComponent extends JComponent + { +@@ -31,15 +32,25 @@ + { + long l = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); + System.gc(); ++ if (displayStrings.length < DimensionManager.getIDs().length + 3) ++ { ++ displayStrings = new String[DimensionManager.getIDs().length + 3]; ++ } ++ for(int x = 0; x < displayStrings.length; x++) ++ { ++ displayStrings[x] = ""; ++ } + displayStrings[0] = (new StringBuilder()).append("Memory use: ").append(l / 1024L / 1024L).append(" mb (").append((Runtime.getRuntime().freeMemory() * 100L) / Runtime.getRuntime().maxMemory()).append("% free)").toString(); + displayStrings[1] = (new StringBuilder()).append("Threads: ").append(NetworkManager.numReadThreads).append(" + ").append(NetworkManager.numWriteThreads).toString(); + displayStrings[2] = (new StringBuilder()).append("Avg tick: ").append(field_40573_a.format(func_40571_a(field_40572_e.field_40027_f) * 9.9999999999999995E-007D)).append(" ms").toString(); +- for (int i = 0; i < field_40572_e.worldMngr.length; i++) ++ int x = 0; ++ for (Integer id : DimensionManager.getIDs()) + { +- displayStrings[3 + i] = (new StringBuilder()).append("Lvl ").append(i).append(" tick: ").append(field_40573_a.format(func_40571_a(field_40572_e.field_40028_g[i]) * 9.9999999999999995E-007D)).append(" ms").toString(); +- if (field_40572_e.worldMngr[i] != null && field_40572_e.worldMngr[i].chunkProviderServer != null) ++ displayStrings[2 + ++x] = "Lvl " + id + " tick: " + field_40573_a.format(func_40571_a(field_40572_e.worldTickTimes.get(id)) * 10E-007D) + " ms"; ++ WorldServer world = (WorldServer)DimensionManager.getWorld(id); ++ if (world != null && world.chunkProviderServer != null) + { +- displayStrings[3 + i] += ", " + field_40572_e.worldMngr[i].chunkProviderServer.func_46040_d(); ++ displayStrings[2 + x] += ", " + world.chunkProviderServer.func_46040_d(); + } + } + memoryUse[updateCounter++ & 0xff] = (int)((l * 100L) / Runtime.getRuntime().maxMemory()); +@@ -48,6 +59,10 @@ + + private double func_40571_a(long al[]) + { ++ if (al == null) ++ { ++ return 0; ++ } + long l = 0L; + for (int i = 0; i < al.length; i++) + { diff --git a/forge/patches/minecraft_server/net/minecraft/src/ModLoader.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ModLoader.java.patch index 97c3e2980..b46eeb29d 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/ModLoader.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/ModLoader.java.patch @@ -1,15 +1,16 @@ --- ../src_base/minecraft_server/net/minecraft/src/ModLoader.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/ModLoader.java 0000-00-00 00:00:00.000000000 -0000 -@@ -10,6 +10,8 @@ +@@ -10,6 +10,9 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import net.minecraft.server.MinecraftServer; ++import net.minecraft.src.forge.DimensionManager; +import net.minecraft.src.forge.ForgeHooks; +import net.minecraft.src.forge.NetworkMod; public final class ModLoader { -@@ -626,6 +628,17 @@ +@@ -626,6 +629,17 @@ readFromClassPath(file); System.out.println("Done."); props.setProperty("loggingLevel", cfgLoggingLevel.getName()); @@ -27,7 +28,20 @@ Iterator iterator = modList.iterator(); do { -@@ -1325,6 +1338,7 @@ +@@ -793,9 +807,10 @@ + logger.fine("Initialized"); + } + long l = 0L; +- if (minecraftserver.worldMngr != null && minecraftserver.worldMngr[0] != null) ++ WorldServer world = (WorldServer)DimensionManager.getWorld(0); ++ if (world != null) + { +- l = minecraftserver.worldMngr[0].getWorldTime(); ++ l = world.getWorldTime(); + Iterator iterator = inGameHooks.entrySet().iterator(); + do + { +@@ -1325,6 +1340,7 @@ { method_getNextWindowId.invoke(entityplayermp, new Object[0]); int j = field_currentWindowId.getInt(entityplayermp); diff --git a/forge/patches/minecraft_server/net/minecraft/src/ModLoaderMp.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ModLoaderMp.java.patch new file mode 100644 index 000000000..eadd5a9a9 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/ModLoaderMp.java.patch @@ -0,0 +1,26 @@ +--- ../src_base/minecraft_server/net/minecraft/src/ModLoaderMp.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/ModLoaderMp.java 0000-00-00 00:00:00.000000000 -0000 +@@ -6,6 +6,7 @@ + import java.util.*; + import java.util.logging.Logger; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.src.forge.DimensionManager; + + public class ModLoaderMp + { +@@ -220,12 +221,11 @@ + + public static World GetPlayerWorld(EntityPlayer entityplayer) + { +- WorldServer aworldserver[] = ModLoader.getMinecraftServerInstance().worldMngr; +- for (int i = 0; i < aworldserver.length; i++) ++ for (World world : DimensionManager.getWorlds()) + { +- if (((World) (aworldserver[i])).playerEntities.contains(entityplayer)) ++ if (world.playerEntities.contains(entityplayer)) + { +- return aworldserver[i]; ++ return world; + } + } + diff --git a/forge/patches/minecraft_server/net/minecraft/src/PlayerNBTManager.java.patch b/forge/patches/minecraft_server/net/minecraft/src/PlayerNBTManager.java.patch new file mode 100644 index 000000000..3a22bdf39 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/PlayerNBTManager.java.patch @@ -0,0 +1,24 @@ +--- ../src_base/minecraft_server/net/minecraft/src/PlayerNBTManager.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/PlayerNBTManager.java 0000-00-00 00:00:00.000000000 -0000 +@@ -82,17 +82,11 @@ + + public IChunkLoader getChunkLoader(WorldProvider worldprovider) + { +- if (worldprovider instanceof WorldProviderHell) ++ if (worldprovider.getSaveFolder() != null) + { +- File file = new File(worldDirectory, "DIM-1"); +- file.mkdirs(); +- return new ChunkLoader(file, true); +- } +- if (worldprovider instanceof WorldProviderEnd) +- { +- File file1 = new File(worldDirectory, "DIM1"); +- file1.mkdirs(); +- return new ChunkLoader(file1, true); ++ File dir = new File(worldDirectory, worldprovider.getSaveFolder()); ++ dir.mkdirs(); ++ return new ChunkLoader(dir, true); + } + else + { diff --git a/forge/patches/minecraft_server/net/minecraft/src/SaveOldDir.java.patch b/forge/patches/minecraft_server/net/minecraft/src/SaveOldDir.java.patch new file mode 100644 index 000000000..d383a354d --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/SaveOldDir.java.patch @@ -0,0 +1,30 @@ +--- ../src_base/minecraft_server/net/minecraft/src/SaveOldDir.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/SaveOldDir.java 0000-00-00 00:00:00.000000000 -0000 +@@ -12,22 +12,15 @@ + + public IChunkLoader getChunkLoader(WorldProvider worldprovider) + { +- File file = getWorldDirectory(); +- if (worldprovider instanceof WorldProviderHell) ++ if (worldprovider.getSaveFolder() != null) + { +- File file1 = new File(file, "DIM-1"); +- file1.mkdirs(); +- return new ThreadedChunkLoader(file1); +- } +- if (worldprovider instanceof WorldProviderEnd) +- { +- File file2 = new File(file, "DIM1"); +- file2.mkdirs(); +- return new ThreadedChunkLoader(file2); ++ File dir = new File(getWorldDirectory(), worldprovider.getSaveFolder()); ++ dir.mkdirs(); ++ return new ThreadedChunkLoader(dir); + } + else + { +- return new ThreadedChunkLoader(file); ++ return new ThreadedChunkLoader(getWorldDirectory()); + } + } + diff --git a/forge/patches/minecraft_server/net/minecraft/src/ServerConfigurationManager.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ServerConfigurationManager.java.patch new file mode 100644 index 000000000..69ecceb50 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/ServerConfigurationManager.java.patch @@ -0,0 +1,147 @@ +--- ../src_base/minecraft_server/net/minecraft/src/ServerConfigurationManager.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/ServerConfigurationManager.java 0000-00-00 00:00:00.000000000 -0000 +@@ -4,13 +4,14 @@ + import java.util.*; + import java.util.logging.Logger; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.src.forge.DimensionManager; + + public class ServerConfigurationManager + { + public static Logger logger = Logger.getLogger("Minecraft"); + public List playerEntities; + private MinecraftServer mcServer; +- private PlayerManager playerManagerObj[]; ++ //private PlayerManager playerManagerObj[]; + private int maxPlayers; + private Set bannedPlayers; + private Set bannedIPs; +@@ -32,16 +33,18 @@ + ops = new HashSet(); + whiteListedIPs = new HashSet(); + field_35482_p = 0; +- playerManagerObj = new PlayerManager[3]; ++ //playerManagerObj = new PlayerManager[3]; + mcServer = minecraftserver; + bannedPlayersFile = minecraftserver.getFile("banned-players.txt"); + ipBanFile = minecraftserver.getFile("banned-ips.txt"); + opFile = minecraftserver.getFile("ops.txt"); + whitelistPlayersFile = minecraftserver.getFile("white-list.txt"); + int i = minecraftserver.propertyManagerObj.getIntProperty("view-distance", 10); ++ /* + playerManagerObj[0] = new PlayerManager(minecraftserver, 0, i); + playerManagerObj[1] = new PlayerManager(minecraftserver, -1, i); + playerManagerObj[2] = new PlayerManager(minecraftserver, 1, i); ++ */ + maxPlayers = minecraftserver.propertyManagerObj.getIntProperty("max-players", 20); + whiteListEnforced = minecraftserver.propertyManagerObj.getBooleanProperty("white-list", false); + readBannedPlayers(); +@@ -61,9 +64,10 @@ + + public void joinNewPlayerManager(EntityPlayerMP entityplayermp) + { +- playerManagerObj[0].removePlayer(entityplayermp); +- playerManagerObj[1].removePlayer(entityplayermp); +- playerManagerObj[2].removePlayer(entityplayermp); ++ for (World world : DimensionManager.getWorlds()) ++ { ++ ((WorldServer)world).playerManager.removePlayer(entityplayermp); ++ } + getPlayerManager(entityplayermp.dimension).addPlayer(entityplayermp); + WorldServer worldserver = mcServer.getWorldManager(entityplayermp.dimension); + worldserver.chunkProviderServer.loadChunk((int)entityplayermp.posX >> 4, (int)entityplayermp.posZ >> 4); +@@ -71,27 +75,18 @@ + + public int getMaxTrackingDistance() + { +- return playerManagerObj[0].getMaxTrackingDistance(); ++ WorldServer world = (WorldServer)DimensionManager.getWorld(0); ++ return world.playerManager.getMaxTrackingDistance(); + } + + private PlayerManager getPlayerManager(int i) + { +- if (i == -1) +- { +- return playerManagerObj[1]; +- } +- if (i == 0) +- { +- return playerManagerObj[0]; +- } +- if (i == 1) +- { +- return playerManagerObj[2]; +- } +- else ++ WorldServer world = (WorldServer)DimensionManager.getWorld(i); ++ if (world == null) + { + return null; + } ++ return world.playerManager; + } + + public void readPlayerDataFromFile(EntityPlayerMP entityplayermp) +@@ -213,6 +208,10 @@ + + public void sendPlayerToOtherDimension(EntityPlayerMP entityplayermp, int i) + { ++ sendPlayerToOtherDimension(entityplayermp, i, new Teleporter()); ++ } ++ public void sendPlayerToOtherDimension(EntityPlayerMP entityplayermp, int i, Teleporter teleporter) ++ { + int j = entityplayermp.dimension; + WorldServer worldserver = mcServer.getWorldManager(entityplayermp.dimension); + entityplayermp.dimension = i; +@@ -220,30 +219,14 @@ + entityplayermp.playerNetServerHandler.sendPacket(new Packet9Respawn((byte)entityplayermp.dimension, (byte)entityplayermp.worldObj.difficultySetting, worldserver1.getSeed(), worldserver1.getWorldInfo().getTerrainType(), worldserver1.worldHeight, entityplayermp.itemInWorldManager.getGameType())); + worldserver.removePlayer(entityplayermp); + entityplayermp.isDead = false; +- double d = entityplayermp.posX; +- double d1 = entityplayermp.posZ; +- double d2 = 8D; +- if (entityplayermp.dimension == -1) +- { +- d /= d2; +- d1 /= d2; +- entityplayermp.setLocationAndAngles(d, entityplayermp.posY, d1, entityplayermp.rotationYaw, entityplayermp.rotationPitch); +- if (entityplayermp.isEntityAlive()) +- { +- worldserver.updateEntityWithOptionalForce(entityplayermp, false); +- } +- } +- else if (entityplayermp.dimension == 0) +- { +- d *= d2; +- d1 *= d2; +- entityplayermp.setLocationAndAngles(d, entityplayermp.posY, d1, entityplayermp.rotationYaw, entityplayermp.rotationPitch); +- if (entityplayermp.isEntityAlive()) +- { +- worldserver.updateEntityWithOptionalForce(entityplayermp, false); +- } +- } +- else ++ ++ WorldProvider pOld = DimensionManager.getProvider(j); ++ WorldProvider pNew = DimensionManager.getProvider(i); ++ double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor(); ++ double d = entityplayermp.posX * moveFactor; ++ double d1 = entityplayermp.posZ * moveFactor; ++ ++ if (entityplayermp.dimension == 1) + { + ChunkCoordinates chunkcoordinates = worldserver1.getEntrancePortalLocation(); + d = chunkcoordinates.posX; +@@ -283,9 +266,9 @@ + EntityPlayerMP entityplayermp = (EntityPlayerMP)playerEntities.get(field_35482_p); + sendPacketToAllPlayers(new Packet201PlayerInfo(entityplayermp.username, true, entityplayermp.ping)); + } +- for (int i = 0; i < playerManagerObj.length; i++) ++ for (World world : DimensionManager.getWorlds()) + { +- playerManagerObj[i].updatePlayerInstances(); ++ ((WorldServer)world).playerManager.updatePlayerInstances(); + } + } + diff --git a/forge/patches/minecraft_server/net/minecraft/src/WorldProvider.java.patch b/forge/patches/minecraft_server/net/minecraft/src/WorldProvider.java.patch new file mode 100644 index 000000000..8b77e9391 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/WorldProvider.java.patch @@ -0,0 +1,71 @@ +--- ../src_base/minecraft_server/net/minecraft/src/WorldProvider.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/WorldProvider.java 0000-00-00 00:00:00.000000000 -0000 +@@ -1,5 +1,7 @@ + package net.minecraft.src; + ++import net.minecraft.src.forge.DimensionManager; ++ + public abstract class WorldProvider + { + public World worldObj; +@@ -95,22 +97,7 @@ + + public static WorldProvider getProviderForDimension(int i) + { +- if (i == -1) +- { +- return new WorldProviderHell(); +- } +- if (i == 0) +- { +- return new WorldProviderSurface(); +- } +- if (i == 1) +- { +- return new WorldProviderEnd(); +- } +- else +- { +- return null; +- } ++ return DimensionManager.getProvider(i); + } + + public ChunkCoordinates getEntrancePortalLocation() +@@ -129,4 +116,36 @@ + return worldObj.worldHeight / 2; + } + } ++ ++ /** ++ * Returns the sub-folder of the world folder that this WorldProvider saves to. ++ * EXA: DIM1, DIM-1 ++ * @return The sub-folder name to save this worlds chunks to. ++ */ ++ public abstract String getSaveFolder(); ++ ++ /** ++ * A message to display to the user when they transfer to this dimension. ++ * ++ * @return The message to be displayed ++ */ ++ public abstract String getWelcomeMessage(); ++ ++ /** ++ * A Message to display to the user when they transfer out of this dismension. ++ * ++ * @return The message to be displayed ++ */ ++ public abstract String getDepartMessage(); ++ ++ /** ++ * The dimensions movement factor. Relative to normal overworld. ++ * It is applied to the players position when they transfer dimensions. ++ * Exa: Nether movement is 8.0 ++ * @return The movement factor ++ */ ++ public double getMovementFactor() ++ { ++ return 1.0; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/WorldProviderEnd.java.patch b/forge/patches/minecraft_server/net/minecraft/src/WorldProviderEnd.java.patch new file mode 100644 index 000000000..4ee5eb1ae --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/WorldProviderEnd.java.patch @@ -0,0 +1,25 @@ +--- ../src_base/minecraft_server/net/minecraft/src/WorldProviderEnd.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/WorldProviderEnd.java 0000-00-00 00:00:00.000000000 -0000 +@@ -51,4 +51,22 @@ + { + return 50; + } ++ ++ @Override ++ public String getSaveFolder() ++ { ++ return "DIM1"; ++ } ++ ++ @Override ++ public String getWelcomeMessage() ++ { ++ return "Entering the End"; ++ } ++ ++ @Override ++ public String getDepartMessage() ++ { ++ return "Leaving the End"; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/WorldProviderHell.java.patch b/forge/patches/minecraft_server/net/minecraft/src/WorldProviderHell.java.patch new file mode 100644 index 000000000..f81aefa88 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/WorldProviderHell.java.patch @@ -0,0 +1,31 @@ +--- ../src_base/minecraft_server/net/minecraft/src/WorldProviderHell.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/WorldProviderHell.java 0000-00-00 00:00:00.000000000 -0000 +@@ -44,4 +44,28 @@ + { + return false; + } ++ ++ @Override ++ public String getSaveFolder() ++ { ++ return "DIM-1"; ++ } ++ ++ @Override ++ public String getWelcomeMessage() ++ { ++ return "Entering the Nether"; ++ } ++ ++ @Override ++ public String getDepartMessage() ++ { ++ return "Leaving the Nether"; ++ } ++ ++ @Override ++ public double getMovementFactor() ++ { ++ return 8.0; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/WorldProviderSurface.java.patch b/forge/patches/minecraft_server/net/minecraft/src/WorldProviderSurface.java.patch new file mode 100644 index 000000000..755c33b8d --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/WorldProviderSurface.java.patch @@ -0,0 +1,25 @@ +--- ../src_base/minecraft_server/net/minecraft/src/WorldProviderSurface.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/WorldProviderSurface.java 0000-00-00 00:00:00.000000000 -0000 +@@ -5,4 +5,22 @@ + public WorldProviderSurface() + { + } ++ ++ @Override ++ public String getSaveFolder() ++ { ++ return null; ++ } ++ ++ @Override ++ public String getWelcomeMessage() ++ { ++ return null; ++ } ++ ++ @Override ++ public String getDepartMessage() ++ { ++ return null; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/WorldServer.java.patch b/forge/patches/minecraft_server/net/minecraft/src/WorldServer.java.patch index e73149a0c..f3cdcc644 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/WorldServer.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/WorldServer.java.patch @@ -1,6 +1,33 @@ --- ../src_base/minecraft_server/net/minecraft/src/WorldServer.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/WorldServer.java 0000-00-00 00:00:00.000000000 -0000 -@@ -54,15 +54,30 @@ +@@ -3,6 +3,7 @@ + import java.util.ArrayList; + import java.util.List; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.src.forge.DimensionManager; + + public class WorldServer extends World + { +@@ -11,6 +12,8 @@ + public boolean levelSaving; + private MinecraftServer mcServer; + private IntHashMap entityInstanceIdMap; ++ public EntityTracker entityTracker; ++ public PlayerManager playerManager; + + public WorldServer(MinecraftServer minecraftserver, ISaveHandler isavehandler, String s, int i, WorldSettings worldsettings) + { +@@ -21,6 +24,9 @@ + { + entityInstanceIdMap = new IntHashMap(); + } ++ DimensionManager.setWorld(i, this); ++ playerManager = new PlayerManager(mcServer, i, mcServer.propertyManagerObj.getIntProperty("view-distance", 10)); ++ entityTracker = new EntityTracker(mcServer, i); + } + + public void updateEntityWithOptionalForce(Entity entity, boolean flag) +@@ -54,15 +60,30 @@ public List getTileEntityList(int i, int j, int k, int l, int i1, int j1) { ArrayList arraylist = new ArrayList();