mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-25 10:07:37 +01:00
Add getInhabitedTime()
This commit is contained in:
parent
17174c177c
commit
3b79890166
@ -88,6 +88,10 @@ public abstract class BukkitVersionHelper {
|
||||
* Remove entities from given chunk
|
||||
*/
|
||||
public abstract void removeEntitiesFromChunk(Chunk c);
|
||||
/**
|
||||
* Get inhabited ticks count from chunk
|
||||
*/
|
||||
public abstract long getInhabitedTicks(Chunk c);
|
||||
/**
|
||||
* Get tile entities map from chunk
|
||||
*/
|
||||
|
@ -81,7 +81,11 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
||||
/** n.m.s.Chunk */
|
||||
nmschunk = getNMSClass("net.minecraft.server.Chunk");
|
||||
nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, new Class[0]);
|
||||
nmsc_tileentities = getField(nmschunk, new String[] { "tileEntities" }, Map.class);
|
||||
nmsc_tileentities = getField(nmschunk, new String[] { "tileEntities" }, Map.class);
|
||||
nmsc_inhabitedticks = getFieldNoFail(nmschunk, new String[] { "s", "q" }, Long.class);
|
||||
if (nmsc_inhabitedticks == null) {
|
||||
Log.info("inhabitedTicks field not found - inhabited shader not functional");
|
||||
}
|
||||
/** nbt classes */
|
||||
nbttagcompound = getNMSClass("net.minecraft.server.NBTTagCompound");
|
||||
nbttagbyte = getNMSClass("net.minecraft.server.NBTTagByte");
|
||||
|
@ -51,6 +51,7 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
|
||||
protected Class<?> nmschunk;
|
||||
protected Method nmsc_removeentities;
|
||||
protected Field nmsc_tileentities;
|
||||
protected Field nmsc_inhabitedticks;
|
||||
/** nbt classes */
|
||||
protected Class<?> nbttagcompound;
|
||||
protected Class<?> nbttagbyte;
|
||||
@ -291,6 +292,21 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
|
||||
callMethod(omsc, nmsc_removeentities, nullargs, null);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get inhabited ticks count from chunk
|
||||
*/
|
||||
private static final Long zero = new Long(0);
|
||||
public long getInhabitedTicks(Chunk c) {
|
||||
if (nmsc_inhabitedticks == null) {
|
||||
return 0;
|
||||
}
|
||||
Object omsc = callMethod(c, cc_gethandle, nullargs, null);
|
||||
if(omsc != null) {
|
||||
return (Long)getFieldValue(omsc, nmsc_inhabitedticks, zero);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Get tile entities map from chunk */
|
||||
public Map getTileEntitiesForChunk(Chunk c) {
|
||||
Object omsc = callMethod(c, cc_gethandle, nullargs, null);
|
||||
|
@ -49,6 +49,7 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
private byte[][] sameneighborbiomecnt;
|
||||
private BiomeMap[][] biomemap;
|
||||
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */
|
||||
private long[] inhabitedTicks; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
|
||||
|
||||
private int chunks_read; /* Number of chunks actually loaded */
|
||||
private int chunks_attempted; /* Number of chunks attempted to load */
|
||||
@ -593,6 +594,14 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
int yoff, int zoff) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public long getInhabitedTicks() {
|
||||
try {
|
||||
return inhabitedTicks[chunkindex];
|
||||
} catch (Exception x) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class OurEndMapIterator extends OurMapIterator {
|
||||
@ -779,6 +788,7 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
|
||||
snapcnt = x_dim * (z_max-z_min+1);
|
||||
snaparray = new ChunkSnapshot[snapcnt];
|
||||
inhabitedTicks = new long[snapcnt];
|
||||
snaptile = new DynIntHashMap[snapcnt];
|
||||
isSectionNotEmpty = new boolean[snapcnt][];
|
||||
}
|
||||
@ -829,10 +839,12 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
}
|
||||
/* Check if cached chunk snapshot found */
|
||||
ChunkSnapshot ss = null;
|
||||
long inhabited_ticks = 0;
|
||||
DynIntHashMap tileData = null;
|
||||
SnapshotRec ssr = DynmapPlugin.plugin.sscache.getSnapshot(dw.getName(), chunk.x, chunk.z, blockdata, biome, biomeraw, highesty);
|
||||
if(ssr != null) {
|
||||
ss = ssr.ss;
|
||||
inhabited_ticks = ssr.inhabitedTicks;
|
||||
if(!vis) {
|
||||
if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN)
|
||||
ss = STONE;
|
||||
@ -844,6 +856,7 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
int idx = (chunk.x-x_min) + (chunk.z - z_min)*x_dim;
|
||||
snaparray[idx] = ss;
|
||||
snaptile[idx] = ssr.tileData;
|
||||
inhabitedTicks[idx] = inhabited_ticks;
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -870,6 +883,8 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
tileData = new DynIntHashMap();
|
||||
|
||||
Chunk c = w.getChunkAt(chunk.x, chunk.z); /* Get the chunk */
|
||||
/* Get inhabited ticks count */
|
||||
inhabited_ticks = helper.getInhabitedTicks(c);
|
||||
if(!vis) {
|
||||
if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN)
|
||||
ss = STONE;
|
||||
@ -919,12 +934,15 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
if(ss != null) {
|
||||
ssr = new SnapshotRec();
|
||||
ssr.ss = ss;
|
||||
ssr.inhabitedTicks = inhabited_ticks;
|
||||
ssr.tileData = tileData;
|
||||
DynmapPlugin.plugin.sscache.putSnapshot(dw.getName(), chunk.x, chunk.z, ssr, blockdata, biome, biomeraw, highesty);
|
||||
}
|
||||
}
|
||||
snaparray[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = ss;
|
||||
snaptile[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = tileData;
|
||||
int chunkIndex = (chunk.x-x_min) + (chunk.z - z_min)*x_dim;
|
||||
snaparray[chunkIndex] = ss;
|
||||
snaptile[chunkIndex] = tileData;
|
||||
inhabitedTicks[chunkIndex] = inhabited_ticks;
|
||||
|
||||
/* If wasn't loaded before, we need to do unload */
|
||||
if (!wasLoaded) {
|
||||
@ -987,6 +1005,7 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
snaparray[i] = null;
|
||||
}
|
||||
snaparray = null;
|
||||
inhabitedTicks = null;
|
||||
}
|
||||
}
|
||||
private void initSectionData(int idx) {
|
||||
|
@ -14,6 +14,7 @@ import org.dynmap.utils.DynIntHashMap;
|
||||
public class SnapshotCache {
|
||||
public static class SnapshotRec {
|
||||
public ChunkSnapshot ss;
|
||||
public long inhabitedTicks;
|
||||
public DynIntHashMap tileData;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user