diff --git a/.gitignore b/.gitignore index 0eeb19b4..69d02691 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ /fabric-1.16.1_server.launch /fabric-1.16.2_client.launch /fabric-1.16.2_server.launch +/spigot/run/ diff --git a/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java b/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java index 1902c4d4..7611c514 100644 --- a/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java +++ b/DynmapCore/src/main/java/org/dynmap/common/BiomeMap.java @@ -300,6 +300,9 @@ public class BiomeMap { public String getId() { return id; } + public String getResourcelocation() { + return resourcelocation; + } public String toString() { return String.format("%s(%s)", id, resourcelocation); } diff --git a/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java b/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java index 18aaaad6..f22fb840 100644 --- a/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java +++ b/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java @@ -55,7 +55,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache { private final int worldheight; private final int ymin; - OurMapIterator(int x0, int y0, int z0) { + protected OurMapIterator(int x0, int y0, int z0) { initialize(x0, y0, z0); worldheight = dw.worldheight; ymin = dw.minY; @@ -157,7 +157,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache { } } - private final BiomeMap getBiomeRel(int dx, int dz) { + public final BiomeMap getBiomeRel(int dx, int dz) { int nx = x + dx; int nz = z + dz; int nchunkindex = ((nx >> 4) - x_min) + (((nz >> 4) - z_min) * x_dim); @@ -169,7 +169,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache { } @Override - public final int getSmoothGrassColorMultiplier(int[] colormap) { + public int getSmoothGrassColorMultiplier(int[] colormap) { int mult = 0xFFFFFF; try { @@ -200,7 +200,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache { } @Override - public final int getSmoothFoliageColorMultiplier(int[] colormap) { + public int getSmoothFoliageColorMultiplier(int[] colormap) { int mult = 0xFFFFFF; try { diff --git a/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/BukkitVersionHelperSpigot119.java b/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/BukkitVersionHelperSpigot119.java index d4d5daf9..b27b8008 100644 --- a/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/BukkitVersionHelperSpigot119.java +++ b/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/BukkitVersionHelperSpigot119.java @@ -111,7 +111,7 @@ public class BukkitVersionHelperSpigot119 extends BukkitVersionHelper { private static IRegistry reg = null; - private static IRegistry getBiomeReg() { + public static IRegistry getBiomeReg() { if (reg == null) { reg = MinecraftServer.getServer().aX().d(IRegistry.aR); } diff --git a/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/MapChunkCache119.java b/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/MapChunkCache119.java index 5ecbc277..62b855e1 100644 --- a/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/MapChunkCache119.java +++ b/bukkit-helper-119/src/main/java/org/dynmap/bukkit/helper/v119/MapChunkCache119.java @@ -1,10 +1,14 @@ package org.dynmap.bukkit.helper.v119; +import net.minecraft.core.IRegistry; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.world.level.biome.BiomeBase; import org.bukkit.World; import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.dynmap.DynmapChunk; import org.dynmap.bukkit.helper.BukkitVersionHelper; import org.dynmap.bukkit.helper.BukkitWorld; +import org.dynmap.common.BiomeMap; import org.dynmap.common.chunk.GenericChunk; import org.dynmap.common.chunk.GenericChunkCache; import org.dynmap.common.chunk.GenericMapChunkCache; @@ -13,6 +17,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.level.ChunkCoordIntPair; import net.minecraft.world.level.chunk.storage.ChunkRegionLoader; import net.minecraft.world.level.chunk.Chunk; +import org.dynmap.utils.MapIterator; import java.lang.reflect.InvocationTargetException; import java.util.List; @@ -27,7 +32,7 @@ import java.util.function.Supplier; */ public class MapChunkCache119 extends GenericMapChunkCache { private static final AsyncChunkProvider119 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider119(); - private World w; + private CraftWorld w; /** * Construct empty cache */ @@ -38,14 +43,14 @@ public class MapChunkCache119 extends GenericMapChunkCache { // Load generic chunk from existing and already loaded chunk @Override protected Supplier getLoadedChunkAsync(DynmapChunk chunk) { - Supplier supplier = provider.getLoadedChunk((CraftWorld) w, chunk.x, chunk.z); + Supplier supplier = provider.getLoadedChunk(w, chunk.x, chunk.z); return () -> { NBTTagCompound nbt = supplier.get(); return nbt != null ? parseChunkFromNBT(new NBT.NBTCompound(nbt)) : null; }; } protected GenericChunk getLoadedChunk(DynmapChunk chunk) { - CraftWorld cw = (CraftWorld) w; + CraftWorld cw = w; if (!cw.isChunkLoaded(chunk.x, chunk.z)) return null; Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z); if (c == null || !c.o) return null; // c.loaded @@ -57,7 +62,7 @@ public class MapChunkCache119 extends GenericMapChunkCache { @Override protected Supplier loadChunkAsync(DynmapChunk chunk){ try { - CompletableFuture nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z); + CompletableFuture nbt = provider.getChunk(w.getHandle(), chunk.x, chunk.z); return () -> { NBTTagCompound compound; try { @@ -75,7 +80,7 @@ public class MapChunkCache119 extends GenericMapChunkCache { } protected GenericChunk loadChunk(DynmapChunk chunk) { - CraftWorld cw = (CraftWorld) w; + CraftWorld cw = w; NBTTagCompound nbt = null; ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z); GenericChunk gc = null; @@ -91,7 +96,86 @@ public class MapChunkCache119 extends GenericMapChunkCache { } public void setChunks(BukkitWorld dw, List chunks) { - this.w = dw.getWorld(); + this.w = (CraftWorld) dw.getWorld(); super.setChunks(dw, chunks); } + + private class MapIterator119 extends OurMapIterator { + int light; + MapIterator119(int x, int y, int z) { + super(x, y, z); + light = dw.getEnvironment().equals("the_end") ? 15 : -1; + } + + @Override + public int getBlockSkyLight() { + return light == -1 ? super.getBlockSkyLight() : light; + } + + @Override + public int getSmoothGrassColorMultiplier(int[] colormap) { + int r = 0; + int g = 0; + int b = 0; + int cnt = 0; + IRegistry reg = BukkitVersionHelperSpigot119.getBiomeReg(); + for (int x = -2; x <= 2; x++) { + for (int z = -2; z <= 2; z++) { + BiomeMap map = this.getBiomeRel(x, z); + if (map.getResourcelocation() == null) continue; + BiomeBase base = reg.a(MinecraftKey.a(map.getResourcelocation())); + int rgb = 0; + if (base != null) { + rgb = base.j().f().orElse(colormap[map.biomeLookup()]); + rgb = base.j().g().a(x + getX(), z + getZ(), rgb); + } + if (rgb == 0) rgb = colormap[map.biomeLookup()]; + b += rgb & 0xFF; + rgb >>= 8; + g += rgb & 0xFF; + rgb >>= 8; + r += rgb & 0xFF; + cnt++; + } + } + if (cnt < 1) return 0; + r /= cnt; + g /= cnt; + b /= cnt; + return r << 16 | g << 8 | b; + } + + @Override + public int getSmoothFoliageColorMultiplier(int[] colormap) { + int r = 0; + int g = 0; + int b = 0; + int cnt = 0; + IRegistry reg = BukkitVersionHelperSpigot119.getBiomeReg(); + for (int x = -2; x <= 2; x++) { + for (int z = -2; z <= 2; z++) { + BiomeMap map = this.getBiomeRel(x, z); + if (map.getResourcelocation() == null) continue; + BiomeBase base = reg.a(MinecraftKey.a(map.getResourcelocation())); + int rgb = base == null ? colormap[map.biomeLookup()] : base.j().e().orElse(colormap[map.biomeLookup()]); + b += rgb & 0xFF; + rgb >>= 8; + g += rgb & 0xFF; + rgb >>= 8; + r += rgb & 0xFF; + cnt++; + } + } + if (cnt < 1) return 0; + r /= cnt; + g /= cnt; + b /= cnt; + return r << 16 | g << 8 | b; + } + } + + @Override + public MapIterator getIterator(int x, int y, int z) { + return new MapIterator119(x, y, z); + } } diff --git a/spigot/build.gradle b/spigot/build.gradle index 8f1da35a..b2c99fde 100644 --- a/spigot/build.gradle +++ b/spigot/build.gradle @@ -1,4 +1,6 @@ - +plugins { + id "xyz.jpenilla.run-paper" version "1.0.6" +} description = 'dynmap' eclipse { @@ -82,7 +84,12 @@ processResources { jar { classifier = 'unshaded' } - +runServer { + // Configure the Minecraft version for our task. + // This is the only required configuration besides applying the plugin. + // Your plugin's jar (or shadowJar if present) will be used automatically. + minecraftVersion("1.19.2") +} shadowJar { dependencies { include(dependency('org.bstats::'))