From 76557bf312c8db78799914f7d96521a5fcefceec Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Thu, 2 Dec 2021 22:18:03 -0600 Subject: [PATCH] Biome shading fixes for 1.18 (Spigot, Fabric, Forge) --- .../main/java/org/dynmap/common/BiomeMap.java | 41 +++++++++++-------- .../v118/BukkitVersionHelperSpigot118.java | 8 +++- .../bukkit/helper/v118/MapChunkCache118.java | 2 +- .../bukkit/helper/BukkitVersionHelper.java | 4 ++ .../org/dynmap/fabric_1_18/ChunkSnapshot.java | 2 +- .../org/dynmap/fabric_1_18/DynmapPlugin.java | 5 ++- .../org/dynmap/forge_1_18/ChunkSnapshot.java | 2 +- .../org/dynmap/forge_1_18/DynmapPlugin.java | 7 ++-- .../java/org/dynmap/bukkit/DynmapPlugin.java | 11 ++--- 9 files changed, 51 insertions(+), 31 deletions(-) diff --git a/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java b/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java index e4745b43..06289183 100644 --- a/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java +++ b/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java @@ -3,13 +3,14 @@ package org.dynmap.common; import java.util.HashMap; import java.util.Map; +import org.dynmap.Log; import org.dynmap.hdmap.HDBlockModels; /* Generic biome mapping */ public class BiomeMap { private static BiomeMap[] biome_by_index = new BiomeMap[1025]; - private static Map biome_by_name = new HashMap<>(); - public static final BiomeMap NULL = new BiomeMap(-1, "NULL", 0.5, 0.5, 0xFFFFFF, 0, 0); + private static Map biome_by_rl = new HashMap(); + public static final BiomeMap NULL = new BiomeMap(-1, "NULL", 0.5, 0.5, 0xFFFFFF, 0, 0, null); public static final BiomeMap OCEAN = new BiomeMap(0, "OCEAN"); public static final BiomeMap PLAINS = new BiomeMap(1, "PLAINS", 0.8, 0.4); @@ -17,7 +18,7 @@ public class BiomeMap { public static final BiomeMap EXTREME_HILLS = new BiomeMap(3, "EXTREME_HILLS", 0.2, 0.3); public static final BiomeMap FOREST = new BiomeMap(4, "FOREST", 0.7, 0.8); public static final BiomeMap TAIGA = new BiomeMap(5, "TAIGA", 0.05, 0.8); - public static final BiomeMap SWAMPLAND = new BiomeMap(6, "SWAMPLAND", 0.8, 0.9, 0xE0FFAE, 0x4E0E4E, 0x4E0E4E); + public static final BiomeMap SWAMPLAND = new BiomeMap(6, "SWAMPLAND", 0.8, 0.9, 0xE0FFAE, 0x4E0E4E, 0x4E0E4E, null); public static final BiomeMap RIVER = new BiomeMap(7, "RIVER"); public static final BiomeMap HELL = new BiomeMap(8, "HELL", 2.0, 0.0); public static final BiomeMap SKY = new BiomeMap(9, "SKY"); @@ -43,6 +44,7 @@ public class BiomeMap { private int grassmult; private int foliagemult; private final String id; + private final String resourcelocation; private final int index; private int biomeindex256; // Standard biome mapping index (for 256 x 256) private boolean isDef; @@ -51,6 +53,11 @@ public class BiomeMap { public static void loadWellKnownByVersion(String mcver) { if (loadDone) return; + // Don't do this for 1.18 and on + if (HDBlockModels.checkVersionRange(mcver, "1.18.0-")) { + loadDone = true; + return; + } if (HDBlockModels.checkVersionRange(mcver, "1.7.0-")) { new BiomeMap(23, "JUNGLE_EDGE", 0.95, 0.8); new BiomeMap(24, "DEEP_OCEAN"); @@ -74,7 +81,7 @@ public class BiomeMap { new BiomeMap(131, "EXTREME_HILLS_MOUNTAINS", 0.2, 0.3); new BiomeMap(132, "FLOWER_FOREST", 0.7, 0.8); new BiomeMap(133, "TAIGA_MOUNTAINS", 0.05, 0.8); - new BiomeMap(134, "SWAMPLAND_MOUNTAINS", 0.8, 0.9, 0xE0FFAE, 0x4E0E4E, 0x4E0E4E); + new BiomeMap(134, "SWAMPLAND_MOUNTAINS", 0.8, 0.9, 0xE0FFAE, 0x4E0E4E, 0x4E0E4E, null); new BiomeMap(140, "ICE_PLAINS_SPIKES", 0.0, 0.5); new BiomeMap(149, "JUNGLE_MOUNTAINS", 1.2, 0.9); new BiomeMap(151, "JUNGLE_EDGE_MOUNTAINS", 0.95, 0.8); @@ -138,7 +145,7 @@ public class BiomeMap { } return true; } - private BiomeMap(int idx, String id, double tmp, double rain, int waterColorMultiplier, int grassmult, int foliagemult) { + private BiomeMap(int idx, String id, double tmp, double rain, int waterColorMultiplier, int grassmult, int foliagemult, String rl) { /* Clamp values : we use raw values from MC code, which are clamped during color mapping only */ setTemperature(tmp); setRainfall(rain); @@ -157,14 +164,21 @@ public class BiomeMap { if(idx >= 0) { biome_by_index[idx] = this; } - biome_by_name.put(id, this); + this.resourcelocation = rl; + if (rl != null) { + biome_by_rl.put(rl, this); + } } public BiomeMap(int idx, String id) { - this(idx, id, 0.5, 0.5, 0xFFFFFF, 0, 0); + this(idx, id, 0.5, 0.5, 0xFFFFFF, 0, 0, null); } public BiomeMap(int idx, String id, double tmp, double rain) { - this(idx, id, tmp, rain, 0xFFFFFF, 0, 0); + this(idx, id, tmp, rain, 0xFFFFFF, 0, 0, null); + } + + public BiomeMap(int idx, String id, double tmp, double rain, String rl) { + this(idx, id, tmp, rain, 0xFFFFFF, 0, 0, rl); } private final int biomeLookup(int width) { @@ -208,14 +222,9 @@ public class BiomeMap { else return NULL; } - public static final BiomeMap byBiomeName(String name) { - if (name.startsWith("minecraft:")) { - name = name.substring(10); - } - name = name.toUpperCase(); - if (biome_by_name.containsKey(name)) - return biome_by_name.get(name); - return NULL; + public static final BiomeMap byBiomeResourceLocation(String resloc) { + BiomeMap b = biome_by_rl.get(resloc); + return (b != null) ? b : NULL; } public int getBiomeID() { return index - 1; // Index of biome in MC biome table diff --git a/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/BukkitVersionHelperSpigot118.java b/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/BukkitVersionHelperSpigot118.java index 3b7a266e..f5d3f93f 100644 --- a/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/BukkitVersionHelperSpigot118.java +++ b/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/BukkitVersionHelperSpigot118.java @@ -92,9 +92,9 @@ public class BukkitVersionHelperSpigot118 extends BukkitVersionHelper { return names.toArray(new String[0]); } - private static Registry reg = null; + private static IRegistry reg = null; - private static Registry getBiomeReg() { + private static IRegistry getBiomeReg() { if (reg == null) { reg = MinecraftServer.getServer().aV().d(IRegistry.aR); } @@ -288,6 +288,10 @@ public class BukkitVersionHelperSpigot118 extends BukkitVersionHelper { } return null; } + @Override + public String getBiomeBaseResourceLocsation(Object bb) { + return getBiomeReg().b((BiomeBase)bb).toString(); + } @Override public Object getUnloadQueue(World world) { diff --git a/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/MapChunkCache118.java b/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/MapChunkCache118.java index 970a1f0a..ee759f15 100644 --- a/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/MapChunkCache118.java +++ b/bukkit-helper-118/src/main/java/org/dynmap/bukkit/helper/v118/MapChunkCache118.java @@ -325,7 +325,7 @@ public class MapChunkCache118 extends AbstractMapChunkCache { bdata = new SimpleBitStorage(bdataPacked.length, 64, bdataPacked); for (int j = 0; j < 64; j++) { int b = bdata != null ? bdata.a(j) : 0; - cursect.biomes[j] = b < bpalette.size() ? BiomeMap.byBiomeName(bpalette.j(b)).getBiomeID() : -1; + cursect.biomes[j] = b < bpalette.size() ? BiomeMap.byBiomeResourceLocation(bpalette.j(b)).getBiomeID() : -1; } // Favor the Y=64 version if ((secnum == 4) || (lastsectwithbiome == null)) { diff --git a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java index 0c4d7182..58f6db8f 100644 --- a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java +++ b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java @@ -48,6 +48,10 @@ public abstract class BukkitVersionHelper { * Get ID string from biomebase */ public abstract String getBiomeBaseIDString(Object bb); + /** + * Get resource location from biomebase (1.18+) + */ + public String getBiomeBaseResourceLocsation(Object bb) { return null; } /** * Get ID from biomebase */ diff --git a/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/ChunkSnapshot.java b/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/ChunkSnapshot.java index 8171918a..a0a1d13d 100644 --- a/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/ChunkSnapshot.java +++ b/fabric-1.18/src/main/java/org/dynmap/fabric_1_18/ChunkSnapshot.java @@ -285,7 +285,7 @@ public class ChunkSnapshot { bdata = new PackedIntegerArray(bdataPacked.length, 64, bdataPacked); for (int j = 0; j < 64; j++) { int b = bdata != null ? bdata.get(j) : 0; - biomes[j] = b < bpalette.size() ? BiomeMap.byBiomeName(bpalette.getString(b)).getBiomeID() : -1; + biomes[j] = b < bpalette.size() ? BiomeMap.byBiomeResourceLocation(bpalette.getString(b)).getBiomeID() : -1; } } } 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 9cdc46bf..1da0c241 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 @@ -376,13 +376,14 @@ public class DynmapPlugin { Biome bb = list[i]; if (bb != null) { String id = biomeRegistry.getId(bb).getPath(); + String rl = biomeRegistry.getId(bb).toString(); float tmp = bb.getTemperature(), hum = bb.getDownfall(); int watermult = ((BiomeEffectsAccessor) bb.getEffects()).getWaterColor(); Log.verboseinfo("biome[" + i + "]: hum=" + hum + ", tmp=" + tmp + ", mult=" + Integer.toHexString(watermult)); BiomeMap bmap = BiomeMap.byBiomeID(i); - if (bmap.isDefault()) { - bmap = new BiomeMap(i, id, tmp, hum); + if ((rl != null) || bmap.isDefault()) { + bmap = new BiomeMap(i, id, tmp, hum, rl); Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ")"); cnt++; } else { diff --git a/forge-1.18/src/main/java/org/dynmap/forge_1_18/ChunkSnapshot.java b/forge-1.18/src/main/java/org/dynmap/forge_1_18/ChunkSnapshot.java index 4cf2aa01..e1692c2f 100644 --- a/forge-1.18/src/main/java/org/dynmap/forge_1_18/ChunkSnapshot.java +++ b/forge-1.18/src/main/java/org/dynmap/forge_1_18/ChunkSnapshot.java @@ -298,7 +298,7 @@ public class ChunkSnapshot bdata = new SimpleBitStorage(bdataPacked.length, 64, bdataPacked); for (int j = 0; j < 64; j++) { int b = bdata != null ? bdata.get(j) : 0; - cursect.biomes[j] = b < bpalette.size() ? BiomeMap.byBiomeName(bpalette.getString(b)).getBiomeID() : -1; + cursect.biomes[j] = b < bpalette.size() ? BiomeMap.byBiomeResourceLocation(bpalette.getString(b)).getBiomeID() : -1; } // Favor the Y=64 version if ((secnum == 4) || (lastsectwithbiome == null)) { 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 3bfb560d..dbaf6b8f 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 @@ -1394,14 +1394,15 @@ public class DynmapPlugin for (int i = 0; i < list.length; i++) { Biome bb = list[i]; if (bb != null) { - String id = bb.toString(); + String id = bb.getRegistryName().getPath(); + String rl = bb.getRegistryName().toString(); float tmp = bb.getBaseTemperature(), hum = bb.getDownfall(); int watermult = bb.getWaterColor(); Log.verboseinfo("biome[" + i + "]: hum=" + hum + ", tmp=" + tmp + ", mult=" + Integer.toHexString(watermult)); BiomeMap bmap = BiomeMap.byBiomeID(i); - if (bmap.isDefault()) { - bmap = new BiomeMap(i, id, tmp, hum); + if ((rl != null) || bmap.isDefault()) { + bmap = new BiomeMap(i, id, tmp, hum, rl); Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ")"); cnt++; } diff --git a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index a745a779..8c742797 100644 --- a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -818,19 +818,20 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { for(int i = 0; i < biomelist.length; i++) { Object bb = biomelist[i]; if(bb != null) { + String rl = helper.getBiomeBaseResourceLocsation(bb); float tmp = helper.getBiomeBaseTemperature(bb); float hum = helper.getBiomeBaseHumidity(bb); int watermult = helper.getBiomeBaseWaterMult(bb); - //Log.info("biome[" + i + "]: hum=" + hum + ", tmp=" + tmp + ", mult=" + Integer.toHexString(watermult)); + Log.verboseinfo("biome[" + i + "]: hum=" + hum + ", tmp=" + tmp + ", mult=" + Integer.toHexString(watermult)); BiomeMap bmap = BiomeMap.byBiomeID(i); - if (bmap.isDefault()) { + if ((rl != null) || bmap.isDefault()) { String id = helper.getBiomeBaseIDString(bb); if(id == null) { id = "BIOME_" + i; } - bmap = new BiomeMap(i, id, tmp, hum); - //Log.info("Add custom biome [" + bmap.toString() + "] (" + i + ")"); + bmap = new BiomeMap(i, id, tmp, hum, rl); + Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ") rl=" + rl); cnt++; } else { @@ -839,7 +840,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { } if (watermult != -1) { bmap.setWaterColorMultiplier(watermult); - //Log.info("Set watercolormult for " + bmap.toString() + " (" + i + ") to " + Integer.toHexString(watermult)); + Log.verboseinfo("Set watercolormult for " + bmap.toString() + " (" + i + ") to " + Integer.toHexString(watermult)); } } }