Handle negative Y for chunk generation driven updates

This commit is contained in:
Mike Primm 2021-12-25 19:09:02 -06:00
parent edb2993af4
commit 57d02007ab
7 changed files with 77 additions and 50 deletions

View File

@ -682,19 +682,22 @@ public class DynmapPlugin {
ChunkPos cp = chunk.getPos(); ChunkPos cp = chunk.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
ChunkSection[] sections = chunk.getSectionArray(); ChunkSection[] sections = chunk.getSectionArray();
for (int i = 0; i < sections.length; i++) { for (int i = 0; i < sections.length; i++) {
if ((sections[i] != null) && (!sections[i].isEmpty())) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // 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()); 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); removeKnownChunk(fw, cp);
@ -710,18 +713,21 @@ public class DynmapPlugin {
ChunkPos cp = chunk.getPos(); ChunkPos cp = chunk.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
ChunkSection[] sections = chunk.getSectionArray(); ChunkSection[] sections = chunk.getSectionArray();
for (int i = 0; i < sections.length; i++) { for (int i = 0; i < sections.length; i++) {
if ((sections[i] != null) && (!sections[i].isEmpty())) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // If not empty AND not initial scan
if (ymax > 0) { if (ymax != Integer.MIN_VALUE) {
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");
} }
addKnownChunk(fw, cp); addKnownChunk(fw, cp);
} }

View File

@ -683,19 +683,22 @@ public class DynmapPlugin {
ChunkPos cp = chunk.getPos(); ChunkPos cp = chunk.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
ChunkSection[] sections = chunk.getSectionArray(); ChunkSection[] sections = chunk.getSectionArray();
for (int i = 0; i < sections.length; i++) { for (int i = 0; i < sections.length; i++) {
if ((sections[i] != null) && (!sections[i].isEmpty())) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // 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()); 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); removeKnownChunk(fw, cp);

View File

@ -629,17 +629,20 @@ public class DynmapPlugin {
FabricWorld fw = getWorld(world, false); FabricWorld fw = getWorld(world, false);
ChunkPos chunkPos = chunk.getPos(); ChunkPos chunkPos = chunk.getPos();
int yMax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
ChunkSection[] sections = chunk.getSectionArray(); ChunkSection[] sections = chunk.getSectionArray();
for (int i = 0; i < sections.length; i++) { for (int i = 0; i < sections.length; i++) {
if ((sections[i] != null) && (!sections[i].isEmpty())) { 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(), mapManager.touchVolume(fw.getName(),
chunkPos.getStartX(), 0, chunkPos.getStartZ(), chunkPos.getStartX(), ymin, chunkPos.getStartZ(),
chunkPos.getEndX(), yMax, chunkPos.getEndZ(), chunkPos.getEndX(), ymax, chunkPos.getEndZ(),
"chunkgenerate"); "chunkgenerate");
//Log.info("New generated chunk detected at %s[%s]".formatted(fw.getName(), chunkPos.getStartPos())); //Log.info("New generated chunk detected at %s[%s]".formatted(fw.getName(), chunkPos.getStartPos()));
} }

View File

@ -1751,19 +1751,22 @@ public class DynmapPlugin
ChunkPos cp = c.getPos(); ChunkPos cp = c.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
ChunkSection[] sections = c.getSections(); ChunkSection[] sections = c.getSections();
for(int i = 0; i < sections.length; i++) { for(int i = 0; i < sections.length; i++) {
if((sections[i] != null) && (sections[i].isEmpty() == false)) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // 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()); //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); removeKnownChunk(fw, cp);
@ -1782,18 +1785,21 @@ public class DynmapPlugin
ChunkPos cp = c.getPos(); ChunkPos cp = c.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
ChunkSection[] sections = c.getSections(); ChunkSection[] sections = c.getSections();
for(int i = 0; i < sections.length; i++) { for(int i = 0; i < sections.length; i++) {
if((sections[i] != null) && (sections[i].isEmpty() == false)) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // If not empty AND not initial scan
if (ymax > 0) { if (ymax != Integer.MIN_VALUE) {
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");
} }
addKnownChunk(fw, cp); addKnownChunk(fw, cp);
} }

View File

@ -1722,19 +1722,22 @@ public class DynmapPlugin
ChunkPos cp = c.getPos(); ChunkPos cp = c.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
LevelChunkSection[] sections = c.getSections(); LevelChunkSection[] sections = c.getSections();
for(int i = 0; i < sections.length; i++) { for(int i = 0; i < sections.length; i++) {
if((sections[i] != null) && (sections[i].isEmpty() == false)) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // 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()); //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); removeKnownChunk(fw, cp);
@ -1753,18 +1756,21 @@ public class DynmapPlugin
ChunkPos cp = c.getPos(); ChunkPos cp = c.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
LevelChunkSection[] sections = c.getSections(); LevelChunkSection[] sections = c.getSections();
for(int i = 0; i < sections.length; i++) { for(int i = 0; i < sections.length; i++) {
if((sections[i] != null) && (sections[i].isEmpty() == false)) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // If not empty AND not initial scan
if (ymax > 0) { if (ymax != Integer.MIN_VALUE) {
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");
} }
addKnownChunk(fw, cp); addKnownChunk(fw, cp);
} }

View File

@ -1723,19 +1723,22 @@ public class DynmapPlugin
ChunkPos cp = c.getPos(); ChunkPos cp = c.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
LevelChunkSection[] sections = c.getSections(); LevelChunkSection[] sections = c.getSections();
for(int i = 0; i < sections.length; i++) { for(int i = 0; i < sections.length; i++) {
if((sections[i] != null) && (sections[i].hasOnlyAir() == false)) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // 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()); 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, 0, z, x+15, ymax, z+16, "chunkgenerate"); mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+15, "chunkgenerate");
} }
} }
removeKnownChunk(fw, cp); removeKnownChunk(fw, cp);
@ -1754,18 +1757,22 @@ public class DynmapPlugin
ChunkPos cp = c.getPos(); ChunkPos cp = c.getPos();
if (fw != null) { if (fw != null) {
if (!checkIfKnownChunk(fw, cp)) { if (!checkIfKnownChunk(fw, cp)) {
int ymax = 0; int ymax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
LevelChunkSection[] sections = c.getSections(); LevelChunkSection[] sections = c.getSections();
for(int i = 0; i < sections.length; i++) { for(int i = 0; i < sections.length; i++) {
if((sections[i] != null) && (sections[i].hasOnlyAir() == false)) { 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 x = cp.x << 4;
int z = cp.z << 4; int z = cp.z << 4;
// If not empty AND not initial scan // If not empty AND not initial scan
if (ymax > 0) { if (ymax != Integer.MIN_VALUE) {
mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); 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); addKnownChunk(fw, cp);
} }

View File

@ -1665,18 +1665,14 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
Listener chunkTrigger = new Listener() { Listener chunkTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onChunkPopulate(ChunkPopulateEvent event) { public void onChunkPopulate(ChunkPopulateEvent event) {
DynmapWorld dw = getWorld(event.getWorld());
Chunk c = event.getChunk(); 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 */ /* Touch extreme corners */
int x = c.getX() << 4; int x = c.getX() << 4;
int z = c.getZ() << 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); pm.registerEvents(chunkTrigger, this);