From 57d02007ab276db64fa400929e5eb29b9b811713 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 25 Dec 2021 19:09:02 -0600 Subject: [PATCH] Handle negative Y for chunk generation driven updates --- .../dynmap/fabric_1_16_4/DynmapPlugin.java | 22 ++++++++++------ .../dynmap/fabric_1_17_1/DynmapPlugin.java | 11 +++++--- .../org/dynmap/fabric_1_18/DynmapPlugin.java | 13 ++++++---- .../org/dynmap/forge_1_16_5/DynmapPlugin.java | 22 ++++++++++------ .../org/dynmap/forge_1_17_1/DynmapPlugin.java | 22 ++++++++++------ .../org/dynmap/forge_1_18/DynmapPlugin.java | 25 ++++++++++++------- .../java/org/dynmap/bukkit/DynmapPlugin.java | 12 +++------ 7 files changed, 77 insertions(+), 50 deletions(-) diff --git a/fabric-1.16.4/src/main/java/org/dynmap/fabric_1_16_4/DynmapPlugin.java b/fabric-1.16.4/src/main/java/org/dynmap/fabric_1_16_4/DynmapPlugin.java index e800c0e3..8529f873 100644 --- a/fabric-1.16.4/src/main/java/org/dynmap/fabric_1_16_4/DynmapPlugin.java +++ b/fabric-1.16.4/src/main/java/org/dynmap/fabric_1_16_4/DynmapPlugin.java @@ -682,19 +682,22 @@ public class DynmapPlugin { ChunkPos cp = chunk.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; ChunkSection[] sections = chunk.getSectionArray(); for (int i = 0; i < sections.length; i++) { if ((sections[i] != null) && (!sections[i].isEmpty())) { - ymax = 16 * (i + 1); + int sy = sections[i].getYOffset(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { + if (ymax != Integer.MIN_VALUE) { Log.info("New generated chunk detected at " + cp + " for " + fw.getName()); - mapManager.touchVolume(fw.getName(), x, 0, z, x + 15, ymax, z + 16, "chunkgenerate"); + mapManager.touchVolume(fw.getName(), x, ymin, z, x + 15, ymax, z + 15, "chunkgenerate"); } } removeKnownChunk(fw, cp); @@ -710,18 +713,21 @@ public class DynmapPlugin { ChunkPos cp = chunk.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; ChunkSection[] sections = chunk.getSectionArray(); for (int i = 0; i < sections.length; i++) { if ((sections[i] != null) && (!sections[i].isEmpty())) { - ymax = 16 * (i + 1); + int sy = sections[i].getYOffset(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { - mapManager.touchVolume(fw.getName(), x, 0, z, x + 15, ymax, z + 16, "chunkgenerate"); + if (ymax != Integer.MIN_VALUE) { + mapManager.touchVolume(fw.getName(), x, ymin, z, x + 15, ymax, z + 15, "chunkgenerate"); } addKnownChunk(fw, cp); } diff --git a/fabric-1.17.1/src/main/java/org/dynmap/fabric_1_17_1/DynmapPlugin.java b/fabric-1.17.1/src/main/java/org/dynmap/fabric_1_17_1/DynmapPlugin.java index 6ec2b2a5..19fc5d0a 100644 --- a/fabric-1.17.1/src/main/java/org/dynmap/fabric_1_17_1/DynmapPlugin.java +++ b/fabric-1.17.1/src/main/java/org/dynmap/fabric_1_17_1/DynmapPlugin.java @@ -683,19 +683,22 @@ public class DynmapPlugin { ChunkPos cp = chunk.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; ChunkSection[] sections = chunk.getSectionArray(); for (int i = 0; i < sections.length; i++) { if ((sections[i] != null) && (!sections[i].isEmpty())) { - ymax = 16 * (i + 1); + int sy = sections[i].getYOffset(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { + if (ymax != Integer.MIN_VALUE) { Log.info("New generated chunk detected at " + cp + " for " + fw.getName()); - mapManager.touchVolume(fw.getName(), x, 0, z, x + 15, ymax, z + 16, "chunkgenerate"); + mapManager.touchVolume(fw.getName(), x, ymin, z, x + 15, ymax, z + 15, "chunkgenerate"); } } removeKnownChunk(fw, cp); diff --git a/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/DynmapPlugin.java b/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/DynmapPlugin.java index 2c602d48..dbc9a61f 100644 --- a/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/DynmapPlugin.java +++ b/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/DynmapPlugin.java @@ -629,17 +629,20 @@ public class DynmapPlugin { FabricWorld fw = getWorld(world, false); ChunkPos chunkPos = chunk.getPos(); - int yMax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; ChunkSection[] sections = chunk.getSectionArray(); for (int i = 0; i < sections.length; i++) { if ((sections[i] != null) && (!sections[i].isEmpty())) { - yMax = 16 * (i + 1); + int sy = sections[i].getYOffset(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } - if (yMax > 0) { + if (ymax != Integer.MIN_VALUE) { mapManager.touchVolume(fw.getName(), - chunkPos.getStartX(), 0, chunkPos.getStartZ(), - chunkPos.getEndX(), yMax, chunkPos.getEndZ(), + chunkPos.getStartX(), ymin, chunkPos.getStartZ(), + chunkPos.getEndX(), ymax, chunkPos.getEndZ(), "chunkgenerate"); //Log.info("New generated chunk detected at %s[%s]".formatted(fw.getName(), chunkPos.getStartPos())); } diff --git a/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java b/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java index 1b4f14bb..893c57d2 100644 --- a/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java +++ b/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java @@ -1751,19 +1751,22 @@ public class DynmapPlugin ChunkPos cp = c.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; ChunkSection[] sections = c.getSections(); for(int i = 0; i < sections.length; i++) { if((sections[i] != null) && (sections[i].isEmpty() == false)) { - ymax = 16*(i+1); + int sy = sections[i].getYLocation() >> 4; + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { + if (ymax != Integer.MIN_VALUE) { //Log.info("New generated chunk detected at " + cp + " for " + fw.getName()); - mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); + mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+15, "chunkgenerate"); } } removeKnownChunk(fw, cp); @@ -1782,18 +1785,21 @@ public class DynmapPlugin ChunkPos cp = c.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; ChunkSection[] sections = c.getSections(); for(int i = 0; i < sections.length; i++) { if((sections[i] != null) && (sections[i].isEmpty() == false)) { - ymax = 16*(i+1); + int sy = sections[i].getYLocation() >> 4; + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { - mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); + if (ymax != Integer.MIN_VALUE) { + mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+15, "chunkgenerate"); } addKnownChunk(fw, cp); } diff --git a/forge-1.17.1/src/main/java/org/dynmap/forge_1_17_1/DynmapPlugin.java b/forge-1.17.1/src/main/java/org/dynmap/forge_1_17_1/DynmapPlugin.java index 03cb32a5..2cd6adac 100644 --- a/forge-1.17.1/src/main/java/org/dynmap/forge_1_17_1/DynmapPlugin.java +++ b/forge-1.17.1/src/main/java/org/dynmap/forge_1_17_1/DynmapPlugin.java @@ -1722,19 +1722,22 @@ public class DynmapPlugin ChunkPos cp = c.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; LevelChunkSection[] sections = c.getSections(); for(int i = 0; i < sections.length; i++) { if((sections[i] != null) && (sections[i].isEmpty() == false)) { - ymax = 16*(i+1); + int sy = sections[i].bottomBlockY(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { + if (ymax != Integer.MIN_VALUE) { //Log.info("New generated chunk detected at " + cp + " for " + fw.getName()); - mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); + mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+15, "chunkgenerate"); } } removeKnownChunk(fw, cp); @@ -1753,18 +1756,21 @@ public class DynmapPlugin ChunkPos cp = c.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; LevelChunkSection[] sections = c.getSections(); for(int i = 0; i < sections.length; i++) { if((sections[i] != null) && (sections[i].isEmpty() == false)) { - ymax = 16*(i+1); + int sy = sections[i].bottomBlockY(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { - mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); + if (ymax != Integer.MIN_VALUE) { + mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+15, "chunkgenerate"); } addKnownChunk(fw, cp); } diff --git a/forge-1.18/src/main/java/org/dynmap/forge_1_18/DynmapPlugin.java b/forge-1.18/src/main/java/org/dynmap/forge_1_18/DynmapPlugin.java index 734ab245..ba9c8e9d 100644 --- a/forge-1.18/src/main/java/org/dynmap/forge_1_18/DynmapPlugin.java +++ b/forge-1.18/src/main/java/org/dynmap/forge_1_18/DynmapPlugin.java @@ -1723,19 +1723,22 @@ public class DynmapPlugin ChunkPos cp = c.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; LevelChunkSection[] sections = c.getSections(); for(int i = 0; i < sections.length; i++) { if((sections[i] != null) && (sections[i].hasOnlyAir() == false)) { - ymax = 16*(i+1); + int sy = sections[i].bottomBlockY(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { - //Log.info("New generated chunk detected at " + cp + " for " + fw.getName()); - mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); + if (ymax != Integer.MIN_VALUE) { + Log.info(String.format("chunkkeyerate(unload)(%s,%d,%d,%d,%d,%d,%s)", fw.getName(), x, ymin, z, x+15, ymax, z+15)); + mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+15, "chunkgenerate"); } } removeKnownChunk(fw, cp); @@ -1754,18 +1757,22 @@ public class DynmapPlugin ChunkPos cp = c.getPos(); if (fw != null) { if (!checkIfKnownChunk(fw, cp)) { - int ymax = 0; + int ymax = Integer.MIN_VALUE; + int ymin = Integer.MAX_VALUE; LevelChunkSection[] sections = c.getSections(); for(int i = 0; i < sections.length; i++) { if((sections[i] != null) && (sections[i].hasOnlyAir() == false)) { - ymax = 16*(i+1); + int sy = sections[i].bottomBlockY(); + if (sy < ymin) ymin = sy; + if ((sy+16) > ymax) ymax = sy + 16; } } int x = cp.x << 4; int z = cp.z << 4; // If not empty AND not initial scan - if (ymax > 0) { - mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); + if (ymax != Integer.MIN_VALUE) { + Log.info(String.format("chunkkeyerate(save)(%s,%d,%d,%d,%d,%d,%s)", fw.getName(), x, ymin, z, x+15, ymax, z+15)); + mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+15, "chunkgenerate"); } addKnownChunk(fw, cp); } diff --git a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index dd52e7fd..11b44823 100644 --- a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -1665,18 +1665,14 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { Listener chunkTrigger = new Listener() { @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onChunkPopulate(ChunkPopulateEvent event) { + DynmapWorld dw = getWorld(event.getWorld()); Chunk c = event.getChunk(); - ChunkSnapshot cs = c.getChunkSnapshot(); - int ymax = 0; - for(int i = 0; i < c.getWorld().getMaxHeight() / 16; i++) { - if(!cs.isSectionEmpty(i)) { - ymax = (i+1)*16; - } - } /* Touch extreme corners */ int x = c.getX() << 4; int z = c.getZ() << 4; - mapManager.touchVolume(getWorld(event.getWorld()).getName(), x, 0, z, x+15, ymax, z+16, "chunkpopulate"); + int ymin = dw.minY; + int ymax = dw.worldheight; + mapManager.touchVolume(getWorld(event.getWorld()).getName(), x, ymin, z, x+15, ymax, z+16, "chunkpopulate"); } }; pm.registerEvents(chunkTrigger, this);