mirror of https://github.com/webbukkit/dynmap.git
Abstract for easier multiversion support, reduce diff
This commit is contained in:
parent
1f1a342777
commit
8a8e2ecfcf
|
@ -55,7 +55,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
private final int worldheight;
|
private final int worldheight;
|
||||||
private final int ymin;
|
private final int ymin;
|
||||||
|
|
||||||
protected OurMapIterator(int x0, int y0, int z0) {
|
OurMapIterator(int x0, int y0, int z0) {
|
||||||
initialize(x0, y0, z0);
|
initialize(x0, y0, z0);
|
||||||
worldheight = dw.worldheight;
|
worldheight = dw.worldheight;
|
||||||
ymin = dw.minY;
|
ymin = dw.minY;
|
||||||
|
@ -157,7 +157,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final BiomeMap getBiomeRel(int dx, int dz) {
|
private final BiomeMap getBiomeRel(int dx, int dz) {
|
||||||
int nx = x + dx;
|
int nx = x + dx;
|
||||||
int nz = z + dz;
|
int nz = z + dz;
|
||||||
int nchunkindex = ((nx >> 4) - x_min) + (((nz >> 4) - z_min) * x_dim);
|
int nchunkindex = ((nx >> 4) - x_min) + (((nz >> 4) - z_min) * x_dim);
|
||||||
|
@ -169,7 +169,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSmoothGrassColorMultiplier(int[] colormap) {
|
public final int getSmoothGrassColorMultiplier(int[] colormap) {
|
||||||
int mult = 0xFFFFFF;
|
int mult = 0xFFFFFF;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -181,7 +181,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
for (int dz = -1; dz <= 1; dz++) {
|
for (int dz = -1; dz <= 1; dz++) {
|
||||||
BiomeMap bm = getBiomeRel(dx, dz);
|
BiomeMap bm = getBiomeRel(dx, dz);
|
||||||
if (bm == BiomeMap.NULL) continue;
|
if (bm == BiomeMap.NULL) continue;
|
||||||
int rmult = bm.getModifiedGrassMultiplier(colormap[bm.biomeLookup()]);
|
int rmult = getGrassColor(bm, colormap, getX() + dx, getZ() + dz);
|
||||||
raccum += (rmult >> 16) & 0xFF;
|
raccum += (rmult >> 16) & 0xFF;
|
||||||
gaccum += (rmult >> 8) & 0xFF;
|
gaccum += (rmult >> 8) & 0xFF;
|
||||||
baccum += rmult & 0xFF;
|
baccum += rmult & 0xFF;
|
||||||
|
@ -200,7 +200,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSmoothFoliageColorMultiplier(int[] colormap) {
|
public final int getSmoothFoliageColorMultiplier(int[] colormap) {
|
||||||
int mult = 0xFFFFFF;
|
int mult = 0xFFFFFF;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -212,7 +212,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
for (int dz = -1; dz <= 1; dz++) {
|
for (int dz = -1; dz <= 1; dz++) {
|
||||||
BiomeMap bm = getBiomeRel(dx, dz);
|
BiomeMap bm = getBiomeRel(dx, dz);
|
||||||
if (bm == BiomeMap.NULL) continue;
|
if (bm == BiomeMap.NULL) continue;
|
||||||
int rmult = bm.getModifiedFoliageMultiplier(colormap[bm.biomeLookup()]);
|
int rmult = getFoliageColor(bm, colormap, getX() + dx, getZ() + dz);
|
||||||
raccum += (rmult >> 16) & 0xFF;
|
raccum += (rmult >> 16) & 0xFF;
|
||||||
gaccum += (rmult >> 8) & 0xFF;
|
gaccum += (rmult >> 8) & 0xFF;
|
||||||
baccum += rmult & 0xFF;
|
baccum += rmult & 0xFF;
|
||||||
|
@ -546,6 +546,14 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getGrassColor(BiomeMap bm, int[] colormap, int x, int z) {
|
||||||
|
return bm.getModifiedGrassMultiplier(colormap[bm.biomeLookup()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFoliageColor(BiomeMap bm, int[] colormap, int x, int z) {
|
||||||
|
return bm.getModifiedFoliageMultiplier(colormap[bm.biomeLookup()]);
|
||||||
|
}
|
||||||
|
|
||||||
private class OurEndMapIterator extends OurMapIterator {
|
private class OurEndMapIterator extends OurMapIterator {
|
||||||
OurEndMapIterator(int x0, int y0, int z0) {
|
OurEndMapIterator(int x0, int y0, int z0) {
|
||||||
super(x0, y0, z0);
|
super(x0, y0, z0);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.dynmap.bukkit.helper.v119;
|
package org.dynmap.bukkit.helper.v119;
|
||||||
|
|
||||||
import net.minecraft.core.IRegistry;
|
|
||||||
import net.minecraft.resources.MinecraftKey;
|
import net.minecraft.resources.MinecraftKey;
|
||||||
import net.minecraft.world.level.biome.BiomeBase;
|
import net.minecraft.world.level.biome.BiomeBase;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -17,7 +16,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||||
import net.minecraft.world.level.chunk.storage.ChunkRegionLoader;
|
import net.minecraft.world.level.chunk.storage.ChunkRegionLoader;
|
||||||
import net.minecraft.world.level.chunk.Chunk;
|
import net.minecraft.world.level.chunk.Chunk;
|
||||||
import org.dynmap.utils.MapIterator;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,7 +30,7 @@ import java.util.function.Supplier;
|
||||||
*/
|
*/
|
||||||
public class MapChunkCache119 extends GenericMapChunkCache {
|
public class MapChunkCache119 extends GenericMapChunkCache {
|
||||||
private static final AsyncChunkProvider119 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider119();
|
private static final AsyncChunkProvider119 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider119();
|
||||||
private CraftWorld w;
|
private World w;
|
||||||
/**
|
/**
|
||||||
* Construct empty cache
|
* Construct empty cache
|
||||||
*/
|
*/
|
||||||
|
@ -43,14 +41,14 @@ public class MapChunkCache119 extends GenericMapChunkCache {
|
||||||
// Load generic chunk from existing and already loaded chunk
|
// Load generic chunk from existing and already loaded chunk
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<GenericChunk> getLoadedChunkAsync(DynmapChunk chunk) {
|
protected Supplier<GenericChunk> getLoadedChunkAsync(DynmapChunk chunk) {
|
||||||
Supplier<NBTTagCompound> supplier = provider.getLoadedChunk(w, chunk.x, chunk.z);
|
Supplier<NBTTagCompound> supplier = provider.getLoadedChunk((CraftWorld) w, chunk.x, chunk.z);
|
||||||
return () -> {
|
return () -> {
|
||||||
NBTTagCompound nbt = supplier.get();
|
NBTTagCompound nbt = supplier.get();
|
||||||
return nbt != null ? parseChunkFromNBT(new NBT.NBTCompound(nbt)) : null;
|
return nbt != null ? parseChunkFromNBT(new NBT.NBTCompound(nbt)) : null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
protected GenericChunk getLoadedChunk(DynmapChunk chunk) {
|
protected GenericChunk getLoadedChunk(DynmapChunk chunk) {
|
||||||
CraftWorld cw = w;
|
CraftWorld cw = (CraftWorld) w;
|
||||||
if (!cw.isChunkLoaded(chunk.x, chunk.z)) return null;
|
if (!cw.isChunkLoaded(chunk.x, chunk.z)) return null;
|
||||||
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z);
|
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z);
|
||||||
if (c == null || !c.o) return null; // c.loaded
|
if (c == null || !c.o) return null; // c.loaded
|
||||||
|
@ -62,7 +60,7 @@ public class MapChunkCache119 extends GenericMapChunkCache {
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<GenericChunk> loadChunkAsync(DynmapChunk chunk){
|
protected Supplier<GenericChunk> loadChunkAsync(DynmapChunk chunk){
|
||||||
try {
|
try {
|
||||||
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(w.getHandle(), chunk.x, chunk.z);
|
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
|
||||||
return () -> {
|
return () -> {
|
||||||
NBTTagCompound compound;
|
NBTTagCompound compound;
|
||||||
try {
|
try {
|
||||||
|
@ -80,7 +78,7 @@ public class MapChunkCache119 extends GenericMapChunkCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GenericChunk loadChunk(DynmapChunk chunk) {
|
protected GenericChunk loadChunk(DynmapChunk chunk) {
|
||||||
CraftWorld cw = w;
|
CraftWorld cw = (CraftWorld) w;
|
||||||
NBTTagCompound nbt = null;
|
NBTTagCompound nbt = null;
|
||||||
ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
|
ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
|
||||||
GenericChunk gc = null;
|
GenericChunk gc = null;
|
||||||
|
@ -96,86 +94,21 @@ public class MapChunkCache119 extends GenericMapChunkCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChunks(BukkitWorld dw, List<DynmapChunk> chunks) {
|
public void setChunks(BukkitWorld dw, List<DynmapChunk> chunks) {
|
||||||
this.w = (CraftWorld) dw.getWorld();
|
this.w = dw.getWorld();
|
||||||
super.setChunks(dw, chunks);
|
super.setChunks(dw, chunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MapIterator119 extends OurMapIterator {
|
@Override
|
||||||
int light;
|
public int getFoliageColor(BiomeMap bm, int[] colormap, int x, int z) {
|
||||||
MapIterator119(int x, int y, int z) {
|
if (bm.getResourcelocation() == null) return colormap[bm.biomeLookup()];
|
||||||
super(x, y, z);
|
BiomeBase base = BukkitVersionHelperSpigot119.getBiomeReg().a(MinecraftKey.a(bm.getResourcelocation()));
|
||||||
light = dw.getEnvironment().equals("the_end") ? 15 : -1;
|
return base == null ? colormap[bm.biomeLookup()] : base.j().e().orElse(colormap[bm.biomeLookup()]);
|
||||||
}
|
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public MapIterator getIterator(int x, int y, int z) {
|
public int getGrassColor(BiomeMap bm, int[] colormap, int x, int z) {
|
||||||
return new MapIterator119(x, y, z);
|
if (bm.getResourcelocation() == null) return colormap[bm.biomeLookup()];
|
||||||
|
BiomeBase base = BukkitVersionHelperSpigot119.getBiomeReg().a(MinecraftKey.a(bm.getResourcelocation()));
|
||||||
|
return base == null ? colormap[bm.biomeLookup()] : base.j().g().a(x, z, base.j().f().orElse(colormap[bm.biomeLookup()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue