Fix handling of new, additional buiomes

This commit is contained in:
Mike Primm 2021-12-05 05:01:59 -06:00
parent 37fd064434
commit f56f4378c5
8 changed files with 40 additions and 20 deletions

View File

@ -150,7 +150,7 @@ public class BiomeMap {
private static void resizeIfNeeded(int idx) { private static void resizeIfNeeded(int idx) {
if ((idx >= biome_by_index.length) ) { if ((idx >= biome_by_index.length) ) {
int oldlen = biome_by_index.length; int oldlen = biome_by_index.length;
biome_by_index = Arrays.copyOf(biome_by_index, biome_by_index.length * 3 / 2); biome_by_index = Arrays.copyOf(biome_by_index, idx * 3 / 2);
for (int i = oldlen; i < biome_by_index.length; i++) { for (int i = oldlen; i < biome_by_index.length; i++) {
if (biome_by_index[i] == null) { if (biome_by_index[i] == null) {
BiomeMap bm = new BiomeMap(i, "BIOME_" + i); BiomeMap bm = new BiomeMap(i, "BIOME_" + i);
@ -176,15 +176,18 @@ public class BiomeMap {
this.id = id; this.id = id;
// If index is NO_INDEX, find one after the well known ones // If index is NO_INDEX, find one after the well known ones
if (idx == NO_INDEX) { if (idx == NO_INDEX) {
idx = LAST_WELL_KNOWN + 1; idx = LAST_WELL_KNOWN;
while (true) { while (true) {
resizeIfNeeded(idx); idx++;
resizeIfNeeded(idx);
if (biome_by_index[idx].isDef) { if (biome_by_index[idx].isDef) {
break; break;
} }
} }
} }
idx++; /* Insert one after ID value - null is zero index */ else {
idx++; /* Insert one after ID value - null is zero index */
}
this.index = idx; this.index = idx;
if (idx >= 0) { if (idx >= 0) {
resizeIfNeeded(idx); resizeIfNeeded(idx);
@ -262,9 +265,6 @@ public class BiomeMap {
public int getBiomeID() { public int getBiomeID() {
return index - 1; // Index of biome in MC biome table return index - 1; // Index of biome in MC biome table
} }
public final String toString() {
return id;
}
public static final BiomeMap[] values() { public static final BiomeMap[] values() {
return biome_by_index; return biome_by_index;
} }
@ -298,4 +298,7 @@ public class BiomeMap {
public boolean isDefault() { public boolean isDefault() {
return isDef; return isDef;
} }
public String toString() {
return String.format("%s[%d]:t%f,h%f,w%x,g%x,f%x,rl=%s", id, index, tmp, rain, watercolormult, grassmult, foliagemult, resourcelocation);
}
} }

View File

@ -64,7 +64,10 @@ public class GenericChunk {
public final long getInhabitedTicks() { public final long getInhabitedTicks() {
return inhabitedTicks; return inhabitedTicks;
} }
public String toString() {
return String.format("chunk(%d,%d:%s,off=%d", cx, cz, Arrays.deepToString((sections)), cy_min);
}
// Generic empty (coordinates are wrong, but safe otherwise // Generic empty (coordinates are wrong, but safe otherwise
public static final GenericChunk EMPTY = new GenericChunk(0, 0, -4, new GenericChunkSection[24], 0); public static final GenericChunk EMPTY = new GenericChunk(0, 0, -4, new GenericChunkSection[24], 0);

View File

@ -61,6 +61,9 @@ public class GenericChunkSection {
public final BiomeMap getBiome(GenericChunkPos pos) { public final BiomeMap getBiome(GenericChunkPos pos) {
return biomes[pos.soffset & 0xFF]; // Just ZX portion return biomes[pos.soffset & 0xFF]; // Just ZX portion
} }
public String toString() {
return String.format("Biome2D(%s)", Arrays.deepToString(biomes));
}
} }
// For 3D biome map // For 3D biome map
private static class BiomeAccess3D implements BiomeAccess { private static class BiomeAccess3D implements BiomeAccess {
@ -75,6 +78,9 @@ public class GenericChunkSection {
public final BiomeMap getBiome(GenericChunkPos pos) { public final BiomeMap getBiome(GenericChunkPos pos) {
return biomes[pos.sdiv4offset]; return biomes[pos.sdiv4offset];
} }
public String toString() {
return String.format("Biome3D(%s)", Arrays.deepToString(biomes));
}
} }
// For single biome map // For single biome map
private static class BiomeAccessSingle implements BiomeAccess { private static class BiomeAccessSingle implements BiomeAccess {
@ -88,6 +94,9 @@ public class GenericChunkSection {
public final BiomeMap getBiome(GenericChunkPos pos) { public final BiomeMap getBiome(GenericChunkPos pos) {
return biome; return biome;
} }
public String toString() {
return String.format("Biome1(%s)", biome);
}
} }
// Lighting access interface // Lighting access interface
public interface LightingAccess { public interface LightingAccess {
@ -132,6 +141,9 @@ public class GenericChunkSection {
emitted = emitac; emitted = emitac;
isEmpty = empty; isEmpty = empty;
} }
public String toString() {
return String.format("sect(bip:%s)", biomes);
}
private static BiomeAccess defaultBiome = new BiomeAccessSingle(BiomeMap.NULL); private static BiomeAccess defaultBiome = new BiomeAccessSingle(BiomeMap.NULL);
private static BlockStateAccess defaultBlockState = new BlockStateAccessSingle(DynmapBlockState.AIR); private static BlockStateAccess defaultBlockState = new BlockStateAccessSingle(DynmapBlockState.AIR);
private static LightingAccess defaultLight = new LightingAccessSingle(0); private static LightingAccess defaultLight = new LightingAccessSingle(0);

View File

@ -56,6 +56,7 @@ import java.util.IdentityHashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
@ -283,12 +284,7 @@ public class BukkitVersionHelperSpigot118 extends BukkitVersionHelper {
@Override @Override
/** Get ID string from biomebase */ /** Get ID string from biomebase */
public String getBiomeBaseIDString(Object bb) { public String getBiomeBaseIDString(Object bb) {
String s = ((BiomeBase)bb).toString(); return getBiomeReg().b((BiomeBase)bb).a();
if (s != null) {
String[] ss = s.split("\\.");
return ss[ss.length-1];
}
return null;
} }
@Override @Override
public String getBiomeBaseResourceLocsation(Object bb) { public String getBiomeBaseResourceLocsation(Object bb) {

View File

@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import org.dynmap.Log;
/** /**
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread * Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
@ -56,7 +57,9 @@ public class MapChunkCache118 extends GenericMapChunkCache {
if (nbt == null) return null; if (nbt == null) return null;
// Start generic chunk builder // Start generic chunk builder
GenericChunk.Builder bld = new GenericChunk.Builder(dw.minY, dw.worldheight); GenericChunk.Builder bld = new GenericChunk.Builder(dw.minY, dw.worldheight);
bld.coords(nbt.h("xPos"), nbt.h("zPos")); int cx = nbt.h("xPos");
int cz = nbt.h("zPos");
bld.coords(cx, cz);
if (nbt.e("InhabitedTime")) { if (nbt.e("InhabitedTime")) {
bld.inhabitedTicks(nbt.i("InhabitedTime")); bld.inhabitedTicks(nbt.i("InhabitedTime"));
} }
@ -213,7 +216,9 @@ public class MapChunkCache118 extends GenericMapChunkCache {
bdata = new SimpleBitStorage(bdataPacked.length, 64, bdataPacked); bdata = new SimpleBitStorage(bdataPacked.length, 64, bdataPacked);
for (int j = 0; j < 64; j++) { for (int j = 0; j < 64; j++) {
int b = bdata != null ? bdata.a(j) : 0; int b = bdata != null ? bdata.a(j) : 0;
sbld.xyzBiome(j & 0x3, (j & 0x30) >> 4, (j & 0xC) >> 2, BiomeMap.byBiomeResourceLocation(bpalette.j(b))); String rl = bpalette.j(b);
BiomeMap bm = BiomeMap.byBiomeResourceLocation(rl);
sbld.xyzBiome(j & 0x3, (j & 0x30) >> 4, (j & 0xC) >> 2, bm);
} }
} }
else { // Else, apply legacy biomes else { // Else, apply legacy biomes

View File

@ -388,7 +388,7 @@ public class DynmapPlugin {
else { else {
bmap = BiomeMap.byBiomeID(i); bmap = BiomeMap.byBiomeID(i);
} }
if (bmap.isDefault()) { if (bmap.isDefault() || (bmap == BiomeMap.NULL)) {
bmap = new BiomeMap((rl != null) ? BiomeMap.NO_INDEX : i, id, tmp, hum, rl); bmap = new BiomeMap((rl != null) ? BiomeMap.NO_INDEX : i, id, tmp, hum, rl);
Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ")"); Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ")");
cnt++; cnt++;

View File

@ -1403,7 +1403,7 @@ public class DynmapPlugin
else { else {
bmap = BiomeMap.byBiomeID(i); bmap = BiomeMap.byBiomeID(i);
} }
if (bmap.isDefault()) { // If matched default, replace with new one if (bmap.isDefault() || (bmap == BiomeMap.NULL)) {
bmap = new BiomeMap((rl != null) ? BiomeMap.NO_INDEX : i, id, tmp, hum, rl); bmap = new BiomeMap((rl != null) ? BiomeMap.NO_INDEX : i, id, tmp, hum, rl);
Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ")"); Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ")");
cnt++; cnt++;

View File

@ -837,13 +837,14 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
else { else {
bmap = BiomeMap.byBiomeID(i); bmap = BiomeMap.byBiomeID(i);
} }
if (bmap.isDefault()) { if (bmap.isDefault() || (bmap == BiomeMap.NULL)) {
String id = helper.getBiomeBaseIDString(bb); String id = helper.getBiomeBaseIDString(bb);
if(id == null) { if (id == null) {
id = "BIOME_" + i; id = "BIOME_" + i;
} }
bmap = new BiomeMap((rl != null) ? BiomeMap.NO_INDEX : i, id, tmp, hum, rl); bmap = new BiomeMap((rl != null) ? BiomeMap.NO_INDEX : i, id, tmp, hum, rl);
Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ") rl=" + rl); Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ") rl=" + rl);
//Log.info(String.format("rl=%s, bmap=%s", rl, bmap));
cnt++; cnt++;
} }
else { else {