2020-11-03 21:49:40 +01:00
|
|
|
package org.dynmap.bukkit.helper.v116_4;
|
|
|
|
|
|
|
|
import net.minecraft.server.v1_16_R3.*;
|
2021-12-08 01:49:51 +01:00
|
|
|
|
2020-11-03 21:49:40 +01:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
|
|
|
import org.dynmap.DynmapChunk;
|
2021-12-08 01:49:51 +01:00
|
|
|
import org.dynmap.bukkit.helper.BukkitWorld;
|
2022-10-22 13:24:49 +02:00
|
|
|
import org.dynmap.common.BiomeMap;
|
2021-12-08 01:49:51 +01:00
|
|
|
import org.dynmap.common.chunk.GenericChunk;
|
|
|
|
import org.dynmap.common.chunk.GenericChunkCache;
|
|
|
|
import org.dynmap.common.chunk.GenericMapChunkCache;
|
2020-11-03 21:49:40 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2021-12-08 01:49:51 +01:00
|
|
|
import java.util.List;
|
2022-10-22 13:24:49 +02:00
|
|
|
import java.util.Optional;
|
2020-11-03 21:49:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
|
|
|
|
*/
|
2021-12-08 01:49:51 +01:00
|
|
|
public class MapChunkCache116_4 extends GenericMapChunkCache {
|
|
|
|
private World w;
|
|
|
|
/**
|
|
|
|
* Construct empty cache
|
|
|
|
*/
|
|
|
|
public MapChunkCache116_4(GenericChunkCache cc) {
|
|
|
|
super(cc);
|
2020-11-03 21:49:40 +01:00
|
|
|
}
|
2021-12-08 01:49:51 +01:00
|
|
|
|
|
|
|
// Load generic chunk from existing and already loaded chunk
|
|
|
|
protected GenericChunk getLoadedChunk(DynmapChunk chunk) {
|
2020-11-03 21:49:40 +01:00
|
|
|
CraftWorld cw = (CraftWorld) w;
|
|
|
|
NBTTagCompound nbt = null;
|
2021-12-08 01:49:51 +01:00
|
|
|
GenericChunk gc = null;
|
|
|
|
if (cw.isChunkLoaded(chunk.x, chunk.z)) {
|
|
|
|
Chunk c = cw.getHandle().getChunkAt(chunk.x, chunk.z);
|
2020-11-03 21:49:40 +01:00
|
|
|
if ((c != null) && c.loaded) {
|
|
|
|
nbt = ChunkRegionLoader.saveChunk(cw.getHandle(), c);
|
|
|
|
}
|
|
|
|
if (nbt != null) {
|
2021-12-08 01:49:51 +01:00
|
|
|
gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
|
2020-11-03 21:49:40 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 01:49:51 +01:00
|
|
|
return gc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load generic chunk from unloaded chunk
|
|
|
|
protected GenericChunk loadChunk(DynmapChunk chunk) {
|
2020-11-03 21:49:40 +01:00
|
|
|
CraftWorld cw = (CraftWorld) w;
|
|
|
|
NBTTagCompound nbt = null;
|
2021-12-08 01:49:51 +01:00
|
|
|
ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
|
|
|
|
GenericChunk gc = null;
|
2020-11-03 21:49:40 +01:00
|
|
|
try {
|
|
|
|
nbt = cw.getHandle().getChunkProvider().playerChunkMap.read(cc);
|
|
|
|
} catch (IOException iox) {
|
|
|
|
}
|
2021-12-08 01:49:51 +01:00
|
|
|
if (nbt != null) {
|
|
|
|
gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
|
2020-11-03 21:49:40 +01:00
|
|
|
}
|
2021-12-08 01:49:51 +01:00
|
|
|
return gc;
|
|
|
|
}
|
2020-11-03 21:49:40 +01:00
|
|
|
|
2021-12-08 01:49:51 +01:00
|
|
|
public void setChunks(BukkitWorld dw, List<DynmapChunk> chunks) {
|
|
|
|
this.w = dw.getWorld();
|
|
|
|
super.setChunks(dw, chunks);
|
|
|
|
}
|
2022-10-22 13:24:49 +02:00
|
|
|
@Override
|
|
|
|
public int getFoliageColor(BiomeMap bm, int[] colormap, int x, int z) {
|
|
|
|
if (bm.getResourcelocation() == null) return colormap[bm.biomeLookup()];
|
|
|
|
BiomeBase base = BukkitVersionHelperSpigot116_4.getBiomeReg().get(MinecraftKey.a(bm.getResourcelocation()));
|
|
|
|
return BukkitVersionHelperSpigot116_4.getBiomeBaseFoliageMult(base).orElse(colormap[bm.biomeLookup()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getGrassColor(BiomeMap bm, int[] colormap, int x, int z) {
|
|
|
|
if (bm.getResourcelocation() == null) return colormap[bm.biomeLookup()];
|
|
|
|
BiomeBase base = BukkitVersionHelperSpigot116_4.getBiomeReg().get(MinecraftKey.a(bm.getResourcelocation()));
|
|
|
|
int grassMult = BukkitVersionHelperSpigot116_4.getBiomeBaseGrassMult(base).orElse(colormap[bm.biomeLookup()]);
|
|
|
|
BiomeFog.GrassColor modifier = BukkitVersionHelperSpigot116_4.getBiomeBaseGrassModifier(base);
|
|
|
|
if (modifier == BiomeFog.GrassColor.DARK_FOREST) {
|
|
|
|
return ((grassMult & 0xfefefe) + 0x28340a) >> 1;
|
|
|
|
} else if (modifier == BiomeFog.GrassColor.SWAMP) {
|
|
|
|
double var5 = BiomeBase.f.a(x * 0.0225, z * 0.0225, false);
|
|
|
|
return var5 < -0.1 ? 0x4c763c : 0x6a7039;
|
|
|
|
} else {
|
|
|
|
return grassMult;
|
|
|
|
}
|
|
|
|
}
|
2020-11-03 21:49:40 +01:00
|
|
|
}
|
2021-12-08 01:49:51 +01:00
|
|
|
|