2019-05-14 06:40:18 +02:00
|
|
|
package org.dynmap.bukkit.helper.v114_1;
|
|
|
|
|
|
|
|
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2021-12-17 05:23:13 +01:00
|
|
|
import java.util.List;
|
2019-05-14 06:40:18 +02:00
|
|
|
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.dynmap.DynmapChunk;
|
2021-12-17 05:23:13 +01:00
|
|
|
import org.dynmap.bukkit.helper.BukkitWorld;
|
|
|
|
import org.dynmap.common.chunk.GenericChunk;
|
|
|
|
import org.dynmap.common.chunk.GenericChunkCache;
|
|
|
|
import org.dynmap.common.chunk.GenericMapChunkCache;
|
2019-05-14 06:40:18 +02:00
|
|
|
|
2019-05-15 02:51:42 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.Chunk;
|
2019-05-14 06:40:18 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.ChunkCoordIntPair;
|
2019-05-15 02:51:42 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.ChunkRegionLoader;
|
2019-05-14 06:40:18 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
|
|
|
|
*/
|
2021-12-17 05:23:13 +01:00
|
|
|
public class MapChunkCache114_1 extends GenericMapChunkCache {
|
|
|
|
private World w;
|
|
|
|
/**
|
|
|
|
* Construct empty cache
|
|
|
|
*/
|
|
|
|
public MapChunkCache114_1(GenericChunkCache cc) {
|
|
|
|
super(cc);
|
2019-05-14 06:40:18 +02:00
|
|
|
}
|
2021-12-17 05:23:13 +01:00
|
|
|
|
|
|
|
// Load generic chunk from existing and already loaded chunk
|
|
|
|
protected GenericChunk getLoadedChunk(DynmapChunk chunk) {
|
2019-05-15 02:51:42 +02:00
|
|
|
CraftWorld cw = (CraftWorld) w;
|
|
|
|
NBTTagCompound nbt = null;
|
2021-12-17 05:23:13 +01:00
|
|
|
GenericChunk gc = null;
|
|
|
|
if (cw.isChunkLoaded(chunk.x, chunk.z)) {
|
|
|
|
Chunk c = cw.getHandle().getChunkAt(chunk.x, chunk.z);
|
2019-05-15 02:51:42 +02:00
|
|
|
if ((c != null) && c.loaded) {
|
|
|
|
nbt = ChunkRegionLoader.saveChunk(cw.getHandle(), c);
|
|
|
|
}
|
2019-06-09 16:59:08 +02:00
|
|
|
if (nbt != null) {
|
2021-12-17 05:23:13 +01:00
|
|
|
gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
|
2019-06-09 16:59:08 +02:00
|
|
|
}
|
2019-05-15 02:51:42 +02:00
|
|
|
}
|
2021-12-17 05:23:13 +01:00
|
|
|
return gc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load generic chunk from unloaded chunk
|
|
|
|
protected GenericChunk loadChunk(DynmapChunk chunk) {
|
2019-05-15 02:51:42 +02:00
|
|
|
CraftWorld cw = (CraftWorld) w;
|
|
|
|
NBTTagCompound nbt = null;
|
2021-12-17 05:23:13 +01:00
|
|
|
ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
|
|
|
|
GenericChunk gc = null;
|
2019-05-15 02:51:42 +02:00
|
|
|
try {
|
|
|
|
nbt = cw.getHandle().getChunkProvider().playerChunkMap.read(cc);
|
|
|
|
} catch (IOException iox) {
|
|
|
|
}
|
|
|
|
if (nbt != null) {
|
2021-12-17 05:23:13 +01:00
|
|
|
gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
|
2019-05-14 06:40:18 +02:00
|
|
|
}
|
2021-12-17 05:23:13 +01:00
|
|
|
return gc;
|
|
|
|
}
|
2019-05-14 06:40:18 +02:00
|
|
|
|
2021-12-17 05:23:13 +01:00
|
|
|
public void setChunks(BukkitWorld dw, List<DynmapChunk> chunks) {
|
|
|
|
this.w = dw.getWorld();
|
|
|
|
super.setChunks(dw, chunks);
|
|
|
|
}
|
2019-05-14 06:40:18 +02:00
|
|
|
}
|
2021-12-17 05:23:13 +01:00
|
|
|
|