Add getInhabitedTime()

This commit is contained in:
Mike Primm 2014-01-17 17:40:39 -06:00
parent 17174c177c
commit 3b79890166
5 changed files with 47 additions and 3 deletions

View File

@ -88,6 +88,10 @@ public abstract class BukkitVersionHelper {
* Remove entities from given chunk * Remove entities from given chunk
*/ */
public abstract void removeEntitiesFromChunk(Chunk c); public abstract void removeEntitiesFromChunk(Chunk c);
/**
* Get inhabited ticks count from chunk
*/
public abstract long getInhabitedTicks(Chunk c);
/** /**
* Get tile entities map from chunk * Get tile entities map from chunk
*/ */

View File

@ -81,7 +81,11 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
/** n.m.s.Chunk */ /** n.m.s.Chunk */
nmschunk = getNMSClass("net.minecraft.server.Chunk"); nmschunk = getNMSClass("net.minecraft.server.Chunk");
nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, new Class[0]); 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 */ /** nbt classes */
nbttagcompound = getNMSClass("net.minecraft.server.NBTTagCompound"); nbttagcompound = getNMSClass("net.minecraft.server.NBTTagCompound");
nbttagbyte = getNMSClass("net.minecraft.server.NBTTagByte"); nbttagbyte = getNMSClass("net.minecraft.server.NBTTagByte");

View File

@ -51,6 +51,7 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
protected Class<?> nmschunk; protected Class<?> nmschunk;
protected Method nmsc_removeentities; protected Method nmsc_removeentities;
protected Field nmsc_tileentities; protected Field nmsc_tileentities;
protected Field nmsc_inhabitedticks;
/** nbt classes */ /** nbt classes */
protected Class<?> nbttagcompound; protected Class<?> nbttagcompound;
protected Class<?> nbttagbyte; protected Class<?> nbttagbyte;
@ -291,6 +292,21 @@ public abstract class BukkitVersionHelperGeneric extends BukkitVersionHelper {
callMethod(omsc, nmsc_removeentities, nullargs, null); 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 */ /** Get tile entities map from chunk */
public Map getTileEntitiesForChunk(Chunk c) { public Map getTileEntitiesForChunk(Chunk c) {
Object omsc = callMethod(c, cc_gethandle, nullargs, null); Object omsc = callMethod(c, cc_gethandle, nullargs, null);

View File

@ -49,6 +49,7 @@ public class NewMapChunkCache implements MapChunkCache {
private byte[][] sameneighborbiomecnt; private byte[][] sameneighborbiomecnt;
private BiomeMap[][] biomemap; private BiomeMap[][] biomemap;
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */ 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_read; /* Number of chunks actually loaded */
private int chunks_attempted; /* Number of chunks attempted to load */ private int chunks_attempted; /* Number of chunks attempted to load */
@ -593,6 +594,14 @@ public class NewMapChunkCache implements MapChunkCache {
int yoff, int zoff) { int yoff, int zoff) {
return null; return null;
} }
@Override
public long getInhabitedTicks() {
try {
return inhabitedTicks[chunkindex];
} catch (Exception x) {
return 0;
}
}
} }
private class OurEndMapIterator extends OurMapIterator { private class OurEndMapIterator extends OurMapIterator {
@ -779,6 +788,7 @@ public class NewMapChunkCache implements MapChunkCache {
snapcnt = x_dim * (z_max-z_min+1); snapcnt = x_dim * (z_max-z_min+1);
snaparray = new ChunkSnapshot[snapcnt]; snaparray = new ChunkSnapshot[snapcnt];
inhabitedTicks = new long[snapcnt];
snaptile = new DynIntHashMap[snapcnt]; snaptile = new DynIntHashMap[snapcnt];
isSectionNotEmpty = new boolean[snapcnt][]; isSectionNotEmpty = new boolean[snapcnt][];
} }
@ -829,10 +839,12 @@ public class NewMapChunkCache implements MapChunkCache {
} }
/* Check if cached chunk snapshot found */ /* Check if cached chunk snapshot found */
ChunkSnapshot ss = null; ChunkSnapshot ss = null;
long inhabited_ticks = 0;
DynIntHashMap tileData = null; DynIntHashMap tileData = null;
SnapshotRec ssr = DynmapPlugin.plugin.sscache.getSnapshot(dw.getName(), chunk.x, chunk.z, blockdata, biome, biomeraw, highesty); SnapshotRec ssr = DynmapPlugin.plugin.sscache.getSnapshot(dw.getName(), chunk.x, chunk.z, blockdata, biome, biomeraw, highesty);
if(ssr != null) { if(ssr != null) {
ss = ssr.ss; ss = ssr.ss;
inhabited_ticks = ssr.inhabitedTicks;
if(!vis) { if(!vis) {
if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN)
ss = STONE; ss = STONE;
@ -844,6 +856,7 @@ public class NewMapChunkCache implements MapChunkCache {
int idx = (chunk.x-x_min) + (chunk.z - z_min)*x_dim; int idx = (chunk.x-x_min) + (chunk.z - z_min)*x_dim;
snaparray[idx] = ss; snaparray[idx] = ss;
snaptile[idx] = ssr.tileData; snaptile[idx] = ssr.tileData;
inhabitedTicks[idx] = inhabited_ticks;
continue; continue;
} }
@ -870,6 +883,8 @@ public class NewMapChunkCache implements MapChunkCache {
tileData = new DynIntHashMap(); tileData = new DynIntHashMap();
Chunk c = w.getChunkAt(chunk.x, chunk.z); /* Get the chunk */ Chunk c = w.getChunkAt(chunk.x, chunk.z); /* Get the chunk */
/* Get inhabited ticks count */
inhabited_ticks = helper.getInhabitedTicks(c);
if(!vis) { if(!vis) {
if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN)
ss = STONE; ss = STONE;
@ -919,12 +934,15 @@ public class NewMapChunkCache implements MapChunkCache {
if(ss != null) { if(ss != null) {
ssr = new SnapshotRec(); ssr = new SnapshotRec();
ssr.ss = ss; ssr.ss = ss;
ssr.inhabitedTicks = inhabited_ticks;
ssr.tileData = tileData; ssr.tileData = tileData;
DynmapPlugin.plugin.sscache.putSnapshot(dw.getName(), chunk.x, chunk.z, ssr, blockdata, biome, biomeraw, highesty); 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; int chunkIndex = (chunk.x-x_min) + (chunk.z - z_min)*x_dim;
snaptile[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = tileData; snaparray[chunkIndex] = ss;
snaptile[chunkIndex] = tileData;
inhabitedTicks[chunkIndex] = inhabited_ticks;
/* If wasn't loaded before, we need to do unload */ /* If wasn't loaded before, we need to do unload */
if (!wasLoaded) { if (!wasLoaded) {
@ -987,6 +1005,7 @@ public class NewMapChunkCache implements MapChunkCache {
snaparray[i] = null; snaparray[i] = null;
} }
snaparray = null; snaparray = null;
inhabitedTicks = null;
} }
} }
private void initSectionData(int idx) { private void initSectionData(int idx) {

View File

@ -14,6 +14,7 @@ import org.dynmap.utils.DynIntHashMap;
public class SnapshotCache { public class SnapshotCache {
public static class SnapshotRec { public static class SnapshotRec {
public ChunkSnapshot ss; public ChunkSnapshot ss;
public long inhabitedTicks;
public DynIntHashMap tileData; public DynIntHashMap tileData;
}; };