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 feb29208a6
commit 809e45631c
17 changed files with 152 additions and 109 deletions

View file

@ -1537,11 +1537,6 @@ public class DynmapPlugin
/* Initialized the currently loaded worlds */
for (ServerLevel world : server.getAllLevels()) {
ForgeWorld w = this.getWorld(world);
/*NOTYET - need rest of forge
if(DimensionManager.getWorld(world.provider.getDimensionId()) == null) { // If not loaded
w.setWorldUnloaded();
}
*/
}
for(ForgeWorld w : worlds.values()) {
if (core.processWorldLoad(w)) { /* Have core process load first - fire event listeners if good load after */
@ -1858,6 +1853,7 @@ public class DynmapPlugin
if(fw.isLoaded() == false) {
fw.setWorldLoaded(w);
}
fw.updateWorld(w);
return fw;
}
}
@ -1880,6 +1876,7 @@ public class DynmapPlugin
HashMap<String, Object> vals = new HashMap<String, Object>();
vals.put("name", fw.getRawName());
vals.put("height", fw.worldheight);
vals.put("miny", fw.minY);
vals.put("sealevel", fw.sealevel);
vals.put("nether", fw.isNether());
vals.put("the_end", ((ForgeWorld)fw).isTheEnd());
@ -1917,12 +1914,13 @@ public class DynmapPlugin
try {
String name = (String)world.get("name");
int height = (Integer)world.get("height");
Integer miny = (Integer) world.get("miny");
int sealevel = (Integer)world.get("sealevel");
boolean nether = (Boolean)world.get("nether");
boolean theend = (Boolean)world.get("the_end");
String title = (String)world.get("title");
if(name != null) {
ForgeWorld fw = new ForgeWorld(name, height, sealevel, nether, theend, title);
ForgeWorld fw = new ForgeWorld(name, height, sealevel, nether, theend, title, (miny != null) ? miny : 0);
fw.setWorldUnloaded();
core.processWorldLoad(fw);
worlds.put(fw.getName(), fw);

View file

@ -53,6 +53,7 @@ public class ForgeMapChunkCache extends MapChunkCache {
private DynmapWorld dw;
private ServerChunkCache cps;
private int nsect;
private int sectoff; // Offset for sake of negative section indexes
private List<DynmapChunk> chunks;
private ListIterator<DynmapChunk> iterator;
private int x_min, x_max, z_min, z_max;
@ -87,6 +88,7 @@ public class ForgeMapChunkCache extends MapChunkCache {
private BlockStep laststep;
private DynmapBlockState blk;
private final int worldheight;
private final int ymin;
private final int x_base;
private final int z_base;
@ -100,6 +102,7 @@ public class ForgeMapChunkCache extends MapChunkCache {
initialize(x0, y0, z0);
worldheight = w.getHeight();
ymin = dw.minY;
}
@Override
@ -119,7 +122,7 @@ public class ForgeMapChunkCache extends MapChunkCache {
laststep = BlockStep.Y_MINUS;
if ((y >= 0) && (y < worldheight)) {
if ((y >= ymin) && (y < worldheight)) {
blk = null;
} else {
blk = DynmapBlockState.AIR;
@ -481,7 +484,7 @@ public class ForgeMapChunkCache extends MapChunkCache {
case 4:
y--;
if (y < 0) {
if (y < ymin) {
blk = DynmapBlockState.AIR;
}
@ -535,7 +538,7 @@ public class ForgeMapChunkCache extends MapChunkCache {
this.y = y;
if ((y < 0) || (y >= worldheight)) {
if ((y < ymin) || (y >= worldheight)) {
blk = DynmapBlockState.AIR;
} else {
blk = null;
@ -560,7 +563,7 @@ public class ForgeMapChunkCache 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) {
@ -591,17 +594,17 @@ public class ForgeMapChunkCache 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
@ -778,7 +781,7 @@ public class ForgeMapChunkCache extends MapChunkCache {
@Override
public boolean isSectionEmpty(int sy) {
return (sy < 4);
return (sy > 3);
}
}
@ -808,7 +811,8 @@ public class ForgeMapChunkCache extends MapChunkCache {
} else {
chunks = new ArrayList<DynmapChunk>();
}
nsect = dw.worldheight >> 4;
nsect = (dw.worldheight - dw.minY) >> 4;
sectoff = (-dw.minY) >> 4;
this.chunks = chunks;
/* Compute range */
@ -1227,22 +1231,22 @@ public class ForgeMapChunkCache extends MapChunkCache {
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;
}
}
}
}
public boolean isEmptySection(int sx, int sy, int sz) {
int idx = (sx - x_min) + (sz - z_min) * x_dim;
if (isSectionNotEmpty[idx] == null) {
initSectionData(idx);
}
return !isSectionNotEmpty[idx][sy];
}
public boolean isEmptySection(int sx, int sy, int sz) {
int idx = (sx - x_min) + (sz - z_min) * x_dim;
boolean[] flags = isSectionNotEmpty[idx];
if(flags == null) {
initSectionData(idx);
flags = isSectionNotEmpty[idx];
}
return !flags[sy + sectoff];
}
/**
* Get cache iterator

View file

@ -18,7 +18,6 @@ import org.dynmap.DynmapLocation;
import org.dynmap.DynmapWorld;
import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.Polygon;
//import org.dynmap.Log;
public class ForgeWorld extends DynmapWorld
{
@ -28,7 +27,7 @@ public class ForgeWorld extends DynmapWorld
private final boolean istheend;
private final String env;
private DynmapLocation spawnloc = new DynmapLocation();
private static int maxWorldHeight = 256; // Maximum allows world height
private static int maxWorldHeight = 320; // Maximum allows world height
public static int getMaxWorldHeight() {
return maxWorldHeight;
@ -50,6 +49,10 @@ public class ForgeWorld extends DynmapWorld
}
}
public void updateWorld(ServerLevelAccessor w) {
this.updateWorldHeights(w.getLevel().getHeight(), w.getLevel().dimensionType().minY(), w.getLevel().getSeaLevel());
}
public ForgeWorld(ServerLevelAccessor w)
{
this(getWorldName(w),
@ -57,12 +60,13 @@ public class ForgeWorld extends DynmapWorld
w.getLevel().getSeaLevel(),
w.getLevel().dimension() == Level.NETHER,
w.getLevel().dimension() == Level.END,
getWorldName(w));
getWorldName(w),
w.getLevel().dimensionType().minY());
setWorldLoaded(w);
}
public ForgeWorld(String name, int height, int sealevel, boolean nether, boolean the_end, String deftitle)
public ForgeWorld(String name, int height, int sealevel, boolean nether, boolean the_end, String deftitle, int miny)
{
super(name, (height > maxWorldHeight)?maxWorldHeight:height, sealevel);
super(name, (height > maxWorldHeight)?maxWorldHeight:height, sealevel, miny);
world = null;
setTitle(deftitle);
isnether = nether;