Simple chunkloading implementation

This commit is contained in:
Christian committed 2012-09-23 23:08:38 -04:00
1 parent a9e3a4dbb9
commit d21e3ae218
6 files changed
+199 -1

No files matched your search

@@ -1,8 +1,13 @@
package net.minecraftforge.common;
import java.util.*;
import java.util.Map.Entry;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import net.minecraft.src.*;
import net.minecraftforge.event.entity.item.ItemTossEvent;
@@ -354,4 +359,55 @@ public class ForgeHooks
player.joinEntityItemWithWorld(event.entityItem);
return event.entityItem;
}
public static void dumpPersistentChunks(WorldInfo worldInfo, ListMultimap<ChunkCoordIntPair, String> persistentChunks)
{
worldInfo.forgeWorldData = new NBTTagCompound();
NBTTagList chunkDataList = new NBTTagList();
for (Entry<ChunkCoordIntPair, Collection<String>> entry : persistentChunks.asMap().entrySet())
{
NBTTagCompound dataList = new NBTTagCompound();
dataList.setIntArray("Chunk", new int[] { entry.getKey().chunkXPos, entry.getKey().chunkZPos });
NBTTagList modList = new NBTTagList();
for (String modId : entry.getValue())
{
modList.appendTag(new NBTTagString(modId, ""));
}
dataList.setTag("Mods", modList);
chunkDataList.appendTag(dataList);
}
worldInfo.forgeWorldData.setTag("PersistentChunks", chunkDataList);
}
public static ListMultimap<ChunkCoordIntPair, String> loadPersistentChunkData(WorldInfo worldInfo)
{
ArrayListMultimap<ChunkCoordIntPair, String> chunkList = ArrayListMultimap.<ChunkCoordIntPair, String>create();
if (worldInfo == null || worldInfo.forgeWorldData == null)
{
return chunkList;
}
NBTTagList chunkDataList = worldInfo.forgeWorldData.getTagList("PersistentChunks");
for (int i = 0; i < chunkDataList.tagCount(); i++)
{
NBTTagCompound dataList = (NBTTagCompound) chunkDataList.tagAt(i);
int[] ccpairint = dataList.getIntArray("Chunk");
ChunkCoordIntPair ccpair = new ChunkCoordIntPair(ccpairint[0], ccpairint[1]);
NBTTagList modList = dataList.getTagList("Mods");
for (int j = 0; j < modList.tagCount(); j++)
{
String modId = modList.tagAt(j).getName();
if (Loader.isModLoaded(modId))
{
chunkList.put(ccpair, modId);
}
else
{
FMLLog.warning("The mod %s is not present - it's chunks will not be persisted any longer", modId);
}
}
}
return chunkList;
}
}