1.19 support

This commit is contained in:
mastermc05 2022-10-14 12:57:23 +03:00
parent 66fe5d4a8b
commit 1f1a342777
6 changed files with 108 additions and 13 deletions

1
.gitignore vendored
View File

@ -37,3 +37,4 @@
/fabric-1.16.1_server.launch
/fabric-1.16.2_client.launch
/fabric-1.16.2_server.launch
/spigot/run/

View File

@ -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);
}

View File

@ -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 {

View File

@ -111,7 +111,7 @@ public class BukkitVersionHelperSpigot119 extends BukkitVersionHelper {
private static IRegistry<BiomeBase> reg = null;
private static IRegistry<BiomeBase> getBiomeReg() {
public static IRegistry<BiomeBase> getBiomeReg() {
if (reg == null) {
reg = MinecraftServer.getServer().aX().d(IRegistry.aR);
}

View File

@ -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<GenericChunk> getLoadedChunkAsync(DynmapChunk chunk) {
Supplier<NBTTagCompound> supplier = provider.getLoadedChunk((CraftWorld) w, chunk.x, chunk.z);
Supplier<NBTTagCompound> 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<GenericChunk> loadChunkAsync(DynmapChunk chunk){
try {
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
CompletableFuture<NBTTagCompound> 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<DynmapChunk> 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<BiomeBase> 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<BiomeBase> 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);
}
}

View File

@ -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::'))