Remove dead WorldInfo patch. Tweak dimension code a bit for better naming, and use the new FML world loading facilities

Update FML: d0e7c9e
d0e7c9e Update patches *sigh*
f3e1cac Add in a savehandler strategy for reading and writing data to the world save. This service is only available to coremods via the WorldAccessConta
51fb513 Add in some bukkit supporting code. Most of this is unimplemented until the bukkit coremod is complete.
65c9fdd New stuff on the ModLoader! Risu has been busy. Closes #114
c1d4458 Mods can now declare a range of minecraft versions they will run against
This commit is contained in:
Christian committed 2012-10-03 01:54:40 -04:00
1 parent b7febbbff7
commit 0162519347
4 files changed
+93 -15

No files matched your search

@@ -1,6 +1,7 @@
package net.minecraftforge.common;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Map.Entry;
@@ -26,7 +27,7 @@ public class DimensionManager
private static Hashtable<Integer, Integer> dimensions = new Hashtable<Integer, Integer>();
private static Map<World, ListMultimap<ChunkCoordIntPair, String>> persistentChunkStore = Maps.newHashMap(); //FIXME: Unused?
private static ArrayList<Integer> unloadQueue = new ArrayList<Integer>();
private static int nextFree;
private static BitSet dimensionMap = new BitSet(Long.SIZE << 4);
public static boolean registerProviderType(int id, Class<? extends WorldProvider> provider, boolean keepLoaded)
{
@@ -45,7 +46,6 @@ public class DimensionManager
{
return;
}
nextFree = 0; //FIXME: Load/store nextFree from/in file in world dir, since other dims could have been registered in previous sessions by a now uninstalled mod
registerProviderType( 0, WorldProviderSurface.class, true);
registerProviderType(-1, WorldProviderHell.class, true);
registerProviderType( 1, WorldProviderEnd.class, false);
@@ -65,8 +65,10 @@ public class DimensionManager
throw new IllegalArgumentException(String.format("Failed to register dimension for id %d, One is already registered", id));
}
dimensions.put(id, providerType);
if (id >= nextFree)
nextFree = id+1;
if (id >= 0)
{
dimensionMap.set(id);
}
}
/**
@@ -222,7 +224,67 @@ public class DimensionManager
unloadQueue.clear();
}
/**
* Return the next free dimension ID. Note: you are not guaranteed a contiguous
* block of free ids. Always call for each individual ID you wish to get.
* @return
*/
public static int getNextFreeDimId() {
return nextFree;
int next = 0;
while (true)
{
next = dimensionMap.nextClearBit(next);
if (dimensions.containsKey(next))
{
dimensionMap.set(next);
}
else
{
return next;
}
}
}
public static NBTTagCompound saveDimensionDataMap()
{
int[] data = new int[(dimensionMap.length() + Integer.SIZE - 1 )/ Integer.SIZE];
NBTTagCompound dimMap = new NBTTagCompound();
for (int i = 0; i < data.length; i++)
{
int val = 0;
for (int j = 0; j < Integer.SIZE; j++)
{
val |= dimensionMap.get(i * Integer.SIZE + j) ? (1 << j) : 0;
}
data[i] = val;
}
dimMap.setIntArray("DimensionArray", data);
return dimMap;
}
public static void loadDimensionDataMap(NBTTagCompound compoundTag)
{
if (compoundTag == null)
{
dimensionMap.clear();
for (Integer id : dimensions.keySet())
{
if (id >= 0)
{
dimensionMap.set(id);
}
}
}
else
{
int[] intArray = compoundTag.getIntArray("DimensionArray");
for (int i = 0; i < intArray.length; i++)
{
for (int j = 0; j < Integer.SIZE; j++)
{
dimensionMap.set(i * Integer.SIZE + j, (intArray[i] & (1 << j)) != 0);
}
}
}
}
}
@@ -1,6 +1,12 @@
package net.minecraftforge.common;
import java.util.Arrays;
import java.util.Map;
import net.minecraft.src.NBTBase;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.SaveHandler;
import net.minecraft.src.WorldInfo;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
@@ -9,12 +15,13 @@ import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.WorldAccessContainer;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import static net.minecraftforge.common.ForgeVersion.*;
public class ForgeDummyContainer extends DummyModContainer
public class ForgeDummyContainer extends DummyModContainer implements WorldAccessContainer
{
public ForgeDummyContainer()
{
@@ -51,4 +58,22 @@ public class ForgeDummyContainer extends DummyModContainer
{
ForgeChunkManager.loadConfiguration();
}
@Override
public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info)
{
NBTTagCompound forgeData = new NBTTagCompound();
NBTTagCompound dimData = DimensionManager.saveDimensionDataMap();
forgeData.setCompoundTag("DimensionData", dimData);
return forgeData;
}
@Override
public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag)
{
if (tag.hasKey("DimensionData"))
{
DimensionManager.loadDimensionDataMap(tag.hasKey("DimensionData") ? tag.getCompoundTag("DimensionData") : null);
}
}
}
Binary file not shown.
@@ -1,9 +0,0 @@
--- ../src_base/common/net/minecraft/src/WorldInfo.java
+++ ../src_work/common/net/minecraft/src/WorldInfo.java
@@ -1,5 +1,6 @@
package net.minecraft.src;
+import net.minecraftforge.common.ForgeHooks;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;