Merge pull request #91 from cpw/multiversefix

Fix world provider behaviour: WorldProvider.byDimension should always return a new instance- otherwise you can end up with worlds overwriting one another
This commit is contained in:
LexManos 2012-06-27 14:37:01 -07:00
commit 0e6e8b87aa
3 changed files with 31 additions and 16 deletions

View File

@ -1,6 +1,9 @@
package net.minecraft.src.forge; package net.minecraft.src.forge;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.logging.Level;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.src.*; import net.minecraft.src.*;
@ -67,4 +70,16 @@ public class DimensionManager
{ {
init(); 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);
}
}
} }

View File

@ -13,7 +13,7 @@
public static WorldProvider getProviderForDimension(int par0) public static WorldProvider getProviderForDimension(int par0)
{ {
- return (WorldProvider)(par0 == -1 ? new WorldProviderHell() : (par0 == 0 ? new WorldProviderSurface() : (par0 == 1 ? new WorldProviderEnd() : null))); - return (WorldProvider)(par0 == -1 ? new WorldProviderHell() : (par0 == 0 ? new WorldProviderSurface() : (par0 == 1 ? new WorldProviderEnd() : null)));
+ return DimensionManager.getProvider(par0); + return DimensionManager.createProviderFor(par0);
} }
/** /**
@ -21,30 +21,30 @@
{ {
return false; return false;
} }
+ +
+ /** + /**
+ * Returns the sub-folder of the world folder that this WorldProvider saves to. + * Returns the sub-folder of the world folder that this WorldProvider saves to.
+ * EXA: DIM1, DIM-1 + * EXA: DIM1, DIM-1
+ * @return The sub-folder name to save this world's chunks to. + * @return The sub-folder name to save this world's chunks to.
+ */ + */
+ public abstract String getSaveFolder(); + public abstract String getSaveFolder();
+ +
+ /** + /**
+ * A message to display to the user when they transfer to this dimension. + * A message to display to the user when they transfer to this dimension.
+ * + *
+ * @return The message to be displayed + * @return The message to be displayed
+ */ + */
+ public abstract String getWelcomeMessage(); + public abstract String getWelcomeMessage();
+ +
+ /** + /**
+ * A Message to display to the user when they transfer out of this dismension. + * A Message to display to the user when they transfer out of this dismension.
+ * + *
+ * @return The message to be displayed + * @return The message to be displayed
+ */ + */
+ public abstract String getDepartMessage(); + public abstract String getDepartMessage();
+ +
+ /** + /**
+ * The dimensions movement factor. Relative to normal overworld. + * The dimensions movement factor. Relative to normal overworld.
+ * It is applied to the players position when they transfer dimensions. + * It is applied to the players position when they transfer dimensions.
+ * Exa: Nether movement is 8.0 + * Exa: Nether movement is 8.0
+ * @return The movement factor + * @return The movement factor

View File

@ -13,7 +13,7 @@
public static WorldProvider getProviderForDimension(int par0) public static WorldProvider getProviderForDimension(int par0)
{ {
- return (WorldProvider)(par0 == -1 ? new WorldProviderHell() : (par0 == 0 ? new WorldProviderSurface() : (par0 == 1 ? new WorldProviderEnd() : null))); - return (WorldProvider)(par0 == -1 ? new WorldProviderHell() : (par0 == 0 ? new WorldProviderSurface() : (par0 == 1 ? new WorldProviderEnd() : null)));
+ return DimensionManager.getProvider(par0); + return DimensionManager.createProviderFor(par0);
} }
/** /**
@ -21,30 +21,30 @@
{ {
return this.terrainType.getMinimumSpawnHeight(worldObj); return this.terrainType.getMinimumSpawnHeight(worldObj);
} }
+ +
+ /** + /**
+ * Returns the sub-folder of the world folder that this WorldProvider saves to. + * Returns the sub-folder of the world folder that this WorldProvider saves to.
+ * EXA: DIM1, DIM-1 + * EXA: DIM1, DIM-1
+ * @return The sub-folder name to save this world's chunks to. + * @return The sub-folder name to save this world's chunks to.
+ */ + */
+ public abstract String getSaveFolder(); + public abstract String getSaveFolder();
+ +
+ /** + /**
+ * A message to display to the user when they transfer to this dimension. + * A message to display to the user when they transfer to this dimension.
+ * + *
+ * @return The message to be displayed + * @return The message to be displayed
+ */ + */
+ public abstract String getWelcomeMessage(); + public abstract String getWelcomeMessage();
+ +
+ /** + /**
+ * A Message to display to the user when they transfer out of this dismension. + * A Message to display to the user when they transfer out of this dismension.
+ * + *
+ * @return The message to be displayed + * @return The message to be displayed
+ */ + */
+ public abstract String getDepartMessage(); + public abstract String getDepartMessage();
+ +
+ /** + /**
+ * The dimensions movement factor. Relative to normal overworld. + * The dimensions movement factor. Relative to normal overworld.
+ * It is applied to the players position when they transfer dimensions. + * It is applied to the players position when they transfer dimensions.
+ * Exa: Nether movement is 8.0 + * Exa: Nether movement is 8.0
+ * @return The movement factor + * @return The movement factor