Fixed bug in DimensionManager that would cause Index error for custom dimensions, also made WorldProviders aware of what dimension they are.

This commit is contained in:
LexManos 2012-08-14 23:59:15 -07:00
parent 57dcfc5dd0
commit 393852920c
2 changed files with 30 additions and 22 deletions

View File

@ -1,5 +1,6 @@
package net.minecraftforge.common;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map.Entry;
import java.util.logging.Level;
@ -78,13 +79,11 @@ public class DimensionManager
{
worlds.put(id, world);
WorldServer[] tmp = new WorldServer[worlds.size() > 3 ? worlds.size() : 3];
for (int x = -1; x <= 1; x++)
{
tmp[(x == 0 ? 0 : x == -1 ? 1 : 2)] = worlds.get(x);
}
ArrayList<WorldServer> tmp = new ArrayList<WorldServer>();
tmp.add(worlds.get( 0));
tmp.add(worlds.get(-1));
tmp.add(worlds.get( 1));
int x = 3;
for (Entry<Integer, WorldServer> entry : worlds.entrySet())
{
int dim = entry.getKey();
@ -92,10 +91,10 @@ public class DimensionManager
{
continue;
}
tmp[x++] = entry.getValue();
tmp.add(entry.getValue());
}
MinecraftServer.getServer().theWorldServer = tmp;
MinecraftServer.getServer().theWorldServer = tmp.toArray(new WorldServer[0]);
MinecraftServer.getServer().worldTickTimes.put(id, new long[100]);
}
@ -126,7 +125,9 @@ public class DimensionManager
{
if (dimensions.containsKey(dim))
{
return providers.get(getProviderType(dim)).newInstance();
WorldProvider provider = providers.get(getProviderType(dim)).newInstance();
provider.setDimension(dim);
return provider;
}
else
{

View File

@ -16,10 +16,25 @@
}
@SideOnly(Side.CLIENT)
@@ -249,4 +250,73 @@
{
return false;
@@ -251,4 +252,79 @@
}
public abstract String func_80004_l();
-}
+
+ /*======================================= Forge Start =========================================*/
+ private int dimensionID = 0;
+
+ /**
+ * Sets the providers current dimension ID, used in default getSaveFolder()
+ * Added to allow default providers to be registered for multiple dimensions.
+ *
+ * @param dim Dimension ID
+ */
+ public void setDimension(int dim)
+ {
+ this.dimensionID = dim;
+ }
+
+ /**
+ * Returns the sub-folder of the world folder that this WorldProvider saves to.
@ -28,15 +43,7 @@
+ */
+ public String getSaveFolder()
+ {
+ if (this instanceof WorldProviderEnd)
+ {
+ return "DIM1";
+ }
+ else if (this instanceof WorldProviderHell)
+ {
+ return "DIM-1";
+ }
+ return null;
+ return (dimensionID == 0 ? null : "DIM" + dimensionID);
+ }
+
+ /**
@ -89,4 +96,4 @@
+ }
+ return 1.0;
+ }
}
+}