File chunkDir = worldServer.getChunkSaveLocation();
File chunkLoaderData = new File(chunkDir, "forcedchunks.dat");
if (chunkLoaderData.exists() && chunkLoaderData.isFile()) {
// MCPC+ force chunks later to help guarantee Forge event ordering
ChunkProviderServer chunkProviderServer = worldServer.theChunkProviderServer;
ArrayListMultimap<String, Ticket> loadedTickets = ArrayListMultimap.create();
Map<String, ListMultimap<String, Ticket>> playerLoadedTickets = Maps.newHashMap();
NBTTagCompound forcedChunkData;
try {
forcedChunkData = CompressedStreamTools.read(chunkLoaderData);
} catch (IOException e) {
FMLLog.log(Level.WARNING, e, "Unable to read forced chunk data at %s - it will be ignored", chunkLoaderData.getAbsolutePath());
return;
}
NBTTagList ticketList = forcedChunkData.getTagList("TicketList");
for (int i = 0; i < ticketList.tagCount(); i++) {
NBTTagCompound ticketHolder = (NBTTagCompound) ticketList.tagAt(i);
String modId = ticketHolder.getString("Owner");
boolean isPlayer = "Forge".equals(modId);
if (!isPlayer && !Loader.isModLoaded(modId)) {
FMLLog.warning("Found chunkloading data for mod %s which is currently not available or active - it will be removed from the world save", modId);
continue;
}
if (!isPlayer && !callbacks.containsKey(modId)) {
FMLLog.warning("The mod %s has registered persistent chunkloading data but doesn't seem to want to be called back with it - it will be removed from the world save", modId);
continue;
}
NBTTagList tickets = ticketHolder.getTagList("Tickets");
for (int j = 0; j < tickets.tagCount(); j++) {
NBTTagCompound ticket = (NBTTagCompound) tickets.tagAt(j);
modId = ticket.hasKey("ModId") ? ticket.getString("ModId") : modId;
Type type = Type.values()[ticket.getByte("Type")];
byte ticketChunkDepth = ticket.getByte("ChunkListDepth");
Ticket tick = new Ticket(modId, type, world);
if (ticket.hasKey("ModData")) {
tick.modData = ticket.getCompoundTag("ModData");
}
if (ticket.hasKey("Player")) {
tick.player = ticket.getString("Player");
ListMultimap<String, Ticket> playerLoadedTicket = playerLoadedTickets.get(tick.modId);
if (playerLoadedTicket == null) {
playerLoadedTickets.put(modId, playerLoadedTicket = ArrayListMultimap.<String, Ticket>create());
}
playerLoadedTicket.put(tick.player, tick);
} else {
loadedTickets.put(modId, tick);
}
if (type == Type.ENTITY) {
tick.entityChunkX = ticket.getInteger("chunkX");
tick.entityChunkZ = ticket.getInteger("chunkZ");
UUID uuid = new UUID(ticket.getLong("PersistentIDMSB"), ticket.getLong("PersistentIDLSB"));
pendingEntities.put(uuid, tick);
// add the ticket to the "pending entity" list
}
// MCPC+ start - save the chunks forced by this ticket (fix for chunkloaders)
NBTTagList ticketChunks = ticket.getTagList("Chunks");
for (int k = 0; k < ticketChunks.tagCount(); k++) {
NBTTagCompound nbtChunk = (NBTTagCompound) ticketChunks.tagAt(k);
int chunkX = nbtChunk.getInteger("chunkX");
int chunkZ = nbtChunk.getInteger("chunkZ");
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);
forceChunkInternal(tick, chunkCoordIntPair);
chunkProviderServer.cacheChunk(chunkX, chunkZ);
}
// MCPC+ end
}
}