Add support for experimental Caves and Caverns data pack

This commit is contained in:
Mike Primm 2021-08-21 18:03:07 -05:00
parent 3276134c5e
commit 0f655e8414
17 changed files with 152 additions and 109 deletions

View file

@ -48,6 +48,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
protected World w;
protected DynmapWorld dw;
private int nsect;
private int sectoff;
protected List<DynmapChunk> chunks;
protected ListIterator<DynmapChunk> iterator;
protected int x_min;
@ -98,6 +99,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
private BlockStep laststep;
private DynmapBlockState type = null;
private final int worldheight;
private final int ymin;
private final int x_base;
private final int z_base;
@ -108,6 +110,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
biomePrep();
initialize(x0, y0, z0);
worldheight = w.getMaxHeight();
ymin = dw.minY;
}
@Override
@ -126,7 +129,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
snap = snaparray[chunkindex];
}
laststep = BlockStep.Y_MINUS;
if((y >= 0) && (y < worldheight))
if((y >= ymin) && (y < worldheight))
type = null;
else
type = DynmapBlockState.AIR;
@ -452,7 +455,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
break;
case 4:
y--;
if(y < 0) {
if(y < ymin) {
type = DynmapBlockState.AIR;
}
break;
@ -498,7 +501,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
else
laststep = BlockStep.Y_MINUS;
this.y = y;
if((y < 0) || (y >= worldheight)) {
if((y < ymin) || (y >= worldheight)) {
type = DynmapBlockState.AIR;
}
else {
@ -520,7 +523,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
@Override
public final DynmapBlockState getBlockTypeAt(BlockStep s) {
if(s == BlockStep.Y_MINUS) {
if(y > 0)
if(y > ymin)
return snap.getBlockType(bx, y-1, bz);
}
else if(s == BlockStep.Y_PLUS) {
@ -547,16 +550,16 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
}
@Override
public long getBlockKey() {
return (((chunkindex * worldheight) + y) << 8) | (bx << 4) | bz;
return (((chunkindex * (worldheight - ymin)) + (y - ymin)) << 8) | (bx << 4) | bz;
}
@Override
public final boolean isEmptySection() {
try {
return !isSectionNotEmpty[chunkindex][y >> 4];
} catch (Exception x) {
boolean[] flags = isSectionNotEmpty[chunkindex];
if (flags == null) {
initSectionData(chunkindex);
return !isSectionNotEmpty[chunkindex][y >> 4];
}
flags = isSectionNotEmpty[chunkindex];
}
return !flags[(y >> 4) + sectoff];
}
@Override
public RenderPatchFactory getPatchFactory() {
@ -677,7 +680,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
}
@Override
public boolean isSectionEmpty(int sy) {
return (sy < 4);
return (sy >= 4);
}
@Override
public Object[] getBiomeBaseFromSnapshot() {
@ -705,7 +708,8 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
if(this.w == null) {
this.chunks = new ArrayList<DynmapChunk>();
}
nsect = dw.worldheight >> 4;
nsect = (dw.worldheight - dw.minY) >> 4;
sectoff = (-dw.minY) >> 4;
this.chunks = chunks;
/* Compute range */
if(chunks.size() == 0) {
@ -966,7 +970,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
isSectionNotEmpty[idx] = new boolean[nsect + 1];
if(snaparray[idx] != EMPTY) {
for(int i = 0; i < nsect; i++) {
if(snaparray[idx].isSectionEmpty(i) == false) {
if(snaparray[idx].isSectionEmpty(i - sectoff) == false) {
isSectionNotEmpty[idx][i] = true;
}
}
@ -974,10 +978,12 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
}
public boolean isEmptySection(int sx, int sy, int sz) {
int idx = (sx - x_min) + (sz - z_min) * x_dim;
if(isSectionNotEmpty[idx] == null) {
boolean[] flags = isSectionNotEmpty[idx];
if(flags == null) {
initSectionData(idx);
flags = isSectionNotEmpty[idx];
}
return !isSectionNotEmpty[idx][sy];
return !flags[sy + sectoff];
}
/**

View file

@ -120,6 +120,10 @@ public abstract class BukkitVersionHelper {
* Get world border
*/
public Polygon getWorldBorder(World world) { return null; }
/**
* Get world minY
*/
public int getWorldMinY(World world) { return 0; }
/**
* Test if broken unloadChunk
*/

View file

@ -27,12 +27,13 @@ public class BukkitWorld extends DynmapWorld {
private DynmapLocation spawnloc = new DynmapLocation();
public BukkitWorld(World w) {
this(w.getName(), w.getMaxHeight(), w.getSeaLevel(), w.getEnvironment());
this(w.getName(), w.getMaxHeight(), w.getSeaLevel(), w.getEnvironment(),
BukkitVersionHelper.helper.getWorldMinY(w));
setWorldLoaded(w);
new Permission("dynmap.world." + getName(), "Dynmap access for world " + getName(), PermissionDefault.OP);
}
public BukkitWorld(String name, int height, int sealevel, World.Environment env) {
super(name, height, sealevel);
public BukkitWorld(String name, int height, int sealevel, World.Environment env, int miny) {
super(name, height, sealevel, miny);
world = null;
this.env = env;
skylight = (env == World.Environment.NORMAL);
@ -125,7 +126,7 @@ public class BukkitWorld extends DynmapWorld {
@Override
public int getLightLevel(int x, int y, int z) {
if(world != null) {
if ((y >= 0) && (y < this.worldheight)) {
if ((y >= minY) && (y < this.worldheight)) {
return world.getBlockAt(x, y, z).getLightLevel();
}
return 0;
@ -153,7 +154,7 @@ public class BukkitWorld extends DynmapWorld {
@Override
public int getSkyLightLevel(int x, int y, int z) {
if(world != null) {
if ((y >= 0) && (y < this.worldheight)) {
if ((y >= minY) && (y < this.worldheight)) {
return world.getBlockAt(x, y, z).getLightFromSky();
}
else {