use of org.dynmap.forge_1_15_2.SnapshotCache.SnapshotRec in project dynmap by webbukkit.
the class ForgeMapChunkCache method prepChunkSnapshot.
// Prep snapshot and add to cache
private SnapshotRec prepChunkSnapshot(DynmapChunk chunk, CompoundNBT nbt) {
ChunkSnapshot ss = new ChunkSnapshot(nbt, dw.worldheight);
DynIntHashMap tileData = new DynIntHashMap();
ListNBT tiles = nbt.getList("TileEntities", 10);
if (tiles == null)
tiles = new ListNBT();
/* Get tile entity data */
List<Object> vals = new ArrayList<Object>();
for (int tid = 0; tid < tiles.size(); tid++) {
CompoundNBT tc = tiles.getCompound(tid);
int tx = tc.getInt("x");
int ty = tc.getInt("y");
int tz = tc.getInt("z");
int cx = tx & 0xF;
int cz = tz & 0xF;
DynmapBlockState blk = ss.getBlockType(cx, ty, cz);
String[] te_fields = HDBlockModels.getTileEntityFieldsNeeded(blk);
if (te_fields != null) {
vals.clear();
for (String id : te_fields) {
INBT v = tc.get(id);
/* Get field */
if (v != null) {
Object val = getNBTValue(v);
if (val != null) {
vals.add(id);
vals.add(val);
}
}
}
if (vals.size() > 0) {
Object[] vlist = vals.toArray(new Object[vals.size()]);
tileData.put(getIndexInChunk(cx, ty, cz), vlist);
}
}
}
SnapshotRec ssr = new SnapshotRec();
ssr.ss = ss;
ssr.tileData = tileData;
DynmapPlugin.plugin.sscache.putSnapshot(dw.getName(), chunk.x, chunk.z, ssr, blockdata, biome, biomeraw, highesty);
return ssr;
}
use of org.dynmap.forge_1_15_2.SnapshotCache.SnapshotRec in project dynmap by webbukkit.
the class ForgeMapChunkCache method getLoadedChunks.
/**
* Read NBT data from loaded chunks - needs to be called from server/world thread to be safe
* @returns number loaded
*/
public int getLoadedChunks() {
int cnt = 0;
if (!dw.isLoaded()) {
isempty = true;
unloadChunks();
return 0;
}
ListIterator<DynmapChunk> iter = chunks.listIterator();
while (iter.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iter.next();
int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
// Skip if already processed
if (snaparray[chunkindex] != null)
continue;
boolean vis = isChunkVisible(chunk);
/* Check if cached chunk snapshot found */
if (tryChunkCache(chunk, vis)) {
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
cnt++;
} else // If chunk is loaded and not being unloaded, we're grabbing its NBT data
if (cps.chunkExists(chunk.x, chunk.z)) {
ChunkSnapshot ss;
DynIntHashMap tileData;
if (vis) {
// If visible
CompoundNBT nbt = ChunkSerializer.write((ServerWorld) w, cps.getChunk(chunk.x, chunk.z, false));
if (nbt != null)
nbt = nbt.getCompound("Level");
SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} else {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
tileData = new DynIntHashMap();
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
cnt++;
}
}
return cnt;
}
use of org.dynmap.forge_1_15_2.SnapshotCache.SnapshotRec in project dynmap by webbukkit.
the class ForgeMapChunkCache method getLoadedChunks.
/**
* Read NBT data from loaded chunks - needs to be called from server/world thread to be safe
* @returns number loaded
*/
public int getLoadedChunks() {
int cnt = 0;
if (!dw.isLoaded()) {
isempty = true;
unloadChunks();
return 0;
}
ListIterator<DynmapChunk> iter = chunks.listIterator();
while (iter.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iter.next();
int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
// Skip if already processed
if (snaparray[chunkindex] != null)
continue;
boolean vis = isChunkVisible(chunk);
/* Check if cached chunk snapshot found */
if (tryChunkCache(chunk, vis)) {
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
cnt++;
} else // If chunk is loaded and not being unloaded, we're grabbing its NBT data
if (cps.chunkExists(chunk.x, chunk.z)) {
ChunkSnapshot ss;
DynIntHashMap tileData;
if (vis) {
// If visible
CompoundNBT nbt = ChunkSerializer.write((ServerWorld) w, cps.getChunk(chunk.x, chunk.z, false));
if (nbt != null)
nbt = nbt.getCompound("Level");
SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} else {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
tileData = new DynIntHashMap();
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
cnt++;
}
}
return cnt;
}
use of org.dynmap.forge_1_15_2.SnapshotCache.SnapshotRec in project dynmap by webbukkit.
the class ForgeMapChunkCache method tryChunkCache.
private boolean tryChunkCache(DynmapChunk chunk, boolean vis) {
/* Check if cached chunk snapshot found */
ChunkSnapshot ss = null;
SnapshotRec ssr = DynmapPlugin.plugin.sscache.getSnapshot(dw.getName(), chunk.x, chunk.z, blockdata, biome, biomeraw, highesty);
if (ssr != null) {
ss = ssr.ss;
if (!vis) {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
}
int idx = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
snaparray[idx] = ss;
snaptile[idx] = ssr.tileData;
}
return (ssr != null);
}
use of org.dynmap.forge_1_15_2.SnapshotCache.SnapshotRec in project dynmap by webbukkit.
the class ForgeMapChunkCache method getLoadedChunks.
/**
* Read NBT data from loaded chunks - needs to be called from server/world thread to be safe
* @returns number loaded
*/
public int getLoadedChunks() {
int cnt = 0;
if (!dw.isLoaded()) {
isempty = true;
unloadChunks();
return 0;
}
ListIterator<DynmapChunk> iter = chunks.listIterator();
while (iter.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iter.next();
int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
// Skip if already processed
if (snaparray[chunkindex] != null)
continue;
boolean vis = isChunkVisible(chunk);
/* Check if cached chunk snapshot found */
if (tryChunkCache(chunk, vis)) {
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
cnt++;
} else // If chunk is loaded and not being unloaded, we're grabbing its NBT data
if (cps.chunkExists(chunk.x, chunk.z) && (!isChunkUnloadPending(chunk))) {
ChunkSnapshot ss;
DynIntHashMap tileData;
if (vis) {
// If visible
NBTTagCompound nbt = new NBTTagCompound();
try {
writechunktonbt.invoke(cps.chunkLoader, cps.loadChunk(chunk.x, chunk.z), w, nbt);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}
SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} else {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
tileData = new DynIntHashMap();
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
cnt++;
}
}
return cnt;
}
Aggregations