mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 05:05:16 +01:00
Merge pull request #3516 from ajmadsen/v3.0
Initial pass at 1.18 snapshot support
This commit is contained in:
commit
e1696928fb
@ -6,7 +6,9 @@ import net.minecraft.util.collection.PackedIntegerArray;
|
|||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.WordPackedArray;
|
import net.minecraft.util.math.WordPackedArray;
|
||||||
import org.dynmap.Log;
|
import org.dynmap.Log;
|
||||||
|
import org.dynmap.common.BiomeMap;
|
||||||
import org.dynmap.renderer.DynmapBlockState;
|
import org.dynmap.renderer.DynmapBlockState;
|
||||||
|
import net.fabricmc.fabric.api.util.NbtType;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -24,18 +26,20 @@ public class ChunkSnapshot {
|
|||||||
public int getBlockEmittedLight(int x, int y, int z);
|
public int getBlockEmittedLight(int x, int y, int z);
|
||||||
|
|
||||||
public boolean isEmpty();
|
public boolean isEmpty();
|
||||||
|
|
||||||
|
public int getBiome(int x, int y, int z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int x, z;
|
private final int x, z;
|
||||||
private final Section[] section;
|
private final Section[] section;
|
||||||
private final int sectionOffset;
|
private final int sectionOffset;
|
||||||
private final int[] hmap; // Height map
|
private final int[] hmap; // Height map
|
||||||
private final int[] biome;
|
|
||||||
private final long captureFulltime;
|
private final long captureFulltime;
|
||||||
private final int sectionCnt;
|
private final int sectionCnt;
|
||||||
private final long inhabitedTicks;
|
private final long inhabitedTicks;
|
||||||
|
|
||||||
private static final int BLOCKS_PER_SECTION = 16 * 16 * 16;
|
private static final int BLOCKS_PER_SECTION = 16 * 16 * 16;
|
||||||
|
private static final int BIOMES_PER_SECTION = 4 * 4 * 4;
|
||||||
private static final int COLUMNS_PER_CHUNK = 16 * 16;
|
private static final int COLUMNS_PER_CHUNK = 16 * 16;
|
||||||
private static final byte[] emptyData = new byte[BLOCKS_PER_SECTION / 2];
|
private static final byte[] emptyData = new byte[BLOCKS_PER_SECTION / 2];
|
||||||
private static final byte[] fullData = new byte[BLOCKS_PER_SECTION / 2];
|
private static final byte[] fullData = new byte[BLOCKS_PER_SECTION / 2];
|
||||||
@ -64,17 +68,25 @@ public class ChunkSnapshot {
|
|||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBiome(int x, int y, int z) {
|
||||||
|
return BiomeMap.PLAINS.getBiomeID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final EmptySection empty_section = new EmptySection();
|
private static final EmptySection empty_section = new EmptySection();
|
||||||
|
|
||||||
private static class StdSection implements Section {
|
private static class StdSection implements Section {
|
||||||
DynmapBlockState[] states;
|
DynmapBlockState[] states;
|
||||||
|
int[] biomes;
|
||||||
byte[] skylight;
|
byte[] skylight;
|
||||||
byte[] emitlight;
|
byte[] emitlight;
|
||||||
|
|
||||||
public StdSection() {
|
public StdSection() {
|
||||||
states = new DynmapBlockState[BLOCKS_PER_SECTION];
|
states = new DynmapBlockState[BLOCKS_PER_SECTION];
|
||||||
|
biomes = new int[BIOMES_PER_SECTION];
|
||||||
|
Arrays.fill(biomes, BiomeMap.PLAINS.getBiomeID());
|
||||||
Arrays.fill(states, DynmapBlockState.AIR);
|
Arrays.fill(states, DynmapBlockState.AIR);
|
||||||
skylight = emptyData;
|
skylight = emptyData;
|
||||||
emitlight = emptyData;
|
emitlight = emptyData;
|
||||||
@ -101,6 +113,12 @@ public class ChunkSnapshot {
|
|||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBiome(int x, int y, int z) {
|
||||||
|
int off = (((y & 0xF) >> 2) << 4) | ((z >> 2) << 2) | (x >> 2);
|
||||||
|
return biomes[off];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,10 +131,9 @@ public class ChunkSnapshot {
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.captureFulltime = captime;
|
this.captureFulltime = captime;
|
||||||
this.biome = new int[COLUMNS_PER_CHUNK];
|
|
||||||
this.sectionCnt = worldheight / 16;
|
this.sectionCnt = worldheight / 16;
|
||||||
/* Allocate arrays indexed by section */
|
/* Allocate arrays indexed by section */
|
||||||
this.section = new Section[this.sectionCnt+1];
|
this.section = new Section[this.sectionCnt + 1];
|
||||||
this.sectionOffset = 0;
|
this.sectionOffset = 0;
|
||||||
/* Fill with empty data */
|
/* Fill with empty data */
|
||||||
for (int i = 0; i <= this.sectionCnt; i++) {
|
for (int i = 0; i <= this.sectionCnt; i++) {
|
||||||
@ -124,7 +141,7 @@ public class ChunkSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create empty height map */
|
/* Create empty height map */
|
||||||
this.hmap = new int[16 * 16];
|
this.hmap = new int[COLUMNS_PER_CHUNK];
|
||||||
|
|
||||||
this.inhabitedTicks = inhabitedTime;
|
this.inhabitedTicks = inhabitedTime;
|
||||||
}
|
}
|
||||||
@ -148,13 +165,22 @@ public class ChunkSnapshot {
|
|||||||
this.x = nbt.getInt("xPos");
|
this.x = nbt.getInt("xPos");
|
||||||
this.z = nbt.getInt("zPos");
|
this.z = nbt.getInt("zPos");
|
||||||
this.captureFulltime = 0;
|
this.captureFulltime = 0;
|
||||||
this.hmap = nbt.getIntArray("HeightMap");
|
|
||||||
this.sectionCnt = worldheight / 16;
|
this.sectionCnt = worldheight / 16;
|
||||||
if (nbt.contains("InhabitedTime")) {
|
if (nbt.contains("InhabitedTime")) {
|
||||||
this.inhabitedTicks = nbt.getLong("InhabitedTime");
|
this.inhabitedTicks = nbt.getLong("InhabitedTime");
|
||||||
} else {
|
} else {
|
||||||
this.inhabitedTicks = 0;
|
this.inhabitedTicks = 0;
|
||||||
}
|
}
|
||||||
|
this.hmap = new int[COLUMNS_PER_CHUNK];
|
||||||
|
if (nbt.contains("Heightmaps")) {
|
||||||
|
NbtCompound hmaps = nbt.getCompound("Heightmaps");
|
||||||
|
long[] phmap = hmaps.getLongArray("WORLD_SURFACE");
|
||||||
|
PackedIntegerArray hmap = new PackedIntegerArray((phmap.length * 64) / COLUMNS_PER_CHUNK, COLUMNS_PER_CHUNK,
|
||||||
|
phmap);
|
||||||
|
for (int i = 0; i < this.hmap.length; i++) {
|
||||||
|
this.hmap[i] = hmap.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Allocate arrays indexed by section */
|
/* Allocate arrays indexed by section */
|
||||||
LinkedList<Section> sections = new LinkedList<Section>();
|
LinkedList<Section> sections = new LinkedList<Section>();
|
||||||
int sectoff = 0; // Default to zero
|
int sectoff = 0; // Default to zero
|
||||||
@ -186,11 +212,12 @@ public class ChunkSnapshot {
|
|||||||
sections.set(secnum + sectoff, cursect);
|
sections.set(secnum + sectoff, cursect);
|
||||||
DynmapBlockState[] states = cursect.states;
|
DynmapBlockState[] states = cursect.states;
|
||||||
DynmapBlockState[] palette = null;
|
DynmapBlockState[] palette = null;
|
||||||
NbtCompound block_states = sec.getCompound("block_states");
|
int[] biomes = cursect.biomes;
|
||||||
// If we've block state data, process non-empty section
|
// If we've got palette and block states list, process non-empty section
|
||||||
if (block_states.contains("data", 12)) {
|
if (sec.contains("block_states", NbtType.COMPOUND)) {
|
||||||
long[] statelist = block_states.getLongArray("data");
|
NbtCompound bstat = sec.getCompound("block_states");
|
||||||
NbtList plist = block_states.getList("palette", 10);
|
NbtList plist = bstat.getList("palette", 10);
|
||||||
|
long[] statelist = bstat.getLongArray("data");
|
||||||
palette = new DynmapBlockState[plist.size()];
|
palette = new DynmapBlockState[plist.size()];
|
||||||
for (int pi = 0; pi < plist.size(); pi++) {
|
for (int pi = 0; pi < plist.size(); pi++) {
|
||||||
NbtCompound tc = plist.getCompound(pi);
|
NbtCompound tc = plist.getCompound(pi);
|
||||||
@ -212,6 +239,7 @@ public class ChunkSnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (statelist.length > 0) {
|
||||||
PackedIntegerArray db = null;
|
PackedIntegerArray db = null;
|
||||||
WordPackedArray dbp = null;
|
WordPackedArray dbp = null;
|
||||||
|
|
||||||
@ -224,7 +252,8 @@ public class ChunkSnapshot {
|
|||||||
if (statelist.length == expectedLegacyStatelistLength) {
|
if (statelist.length == expectedLegacyStatelistLength) {
|
||||||
dbp = new WordPackedArray(bitsperblock, 4096, statelist);
|
dbp = new WordPackedArray(bitsperblock, 4096, statelist);
|
||||||
} else {
|
} else {
|
||||||
throw new StateListException(x, z, statelist.length, expectedStatelistLength, expectedLegacyStatelistLength);
|
throw new StateListException(x, z, statelist.length, expectedStatelistLength,
|
||||||
|
expectedLegacyStatelistLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,34 +269,23 @@ public class ChunkSnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (sec.contains("BlockLight")) {
|
if (sec.contains("BlockLight")) {
|
||||||
cursect.emitlight = sec.getByteArray("BlockLight");
|
cursect.emitlight = sec.getByteArray("BlockLight");
|
||||||
}
|
}
|
||||||
if (sec.contains("SkyLight")) {
|
if (sec.contains("SkyLight")) {
|
||||||
cursect.skylight = sec.getByteArray("SkyLight");
|
cursect.skylight = sec.getByteArray("SkyLight");
|
||||||
}
|
}
|
||||||
}
|
if (sec.contains("biomes")) {
|
||||||
/* Get biome data */
|
NbtCompound nbtbiomes = sec.getCompound("biomes");
|
||||||
// TODO: Update to new 1.18 format (3D biomes, sectioned):
|
long[] bdataPacked = nbtbiomes.getLongArray("data");
|
||||||
this.biome = new int[COLUMNS_PER_CHUNK];
|
NbtList bpalette = nbtbiomes.getList("palette", NbtType.STRING);
|
||||||
if (nbt.contains("Biomes")) {
|
PackedIntegerArray bdata = null;
|
||||||
int[] bb = nbt.getIntArray("Biomes");
|
if (bdataPacked.length > 0)
|
||||||
if (bb != null) {
|
bdata = new PackedIntegerArray(bdataPacked.length, 64, bdataPacked);
|
||||||
// If v1.15+ format
|
for (int j = 0; j < 64; j++) {
|
||||||
if (bb.length > COLUMNS_PER_CHUNK) {
|
int b = bdata != null ? bdata.get(j) : 0;
|
||||||
// For now, just pad the grid with the first 16
|
biomes[j] = b < bpalette.size() ? BiomeMap.byBiomeName(bpalette.getString(b)).getBiomeID() : -1;
|
||||||
for (int i = 0; i < COLUMNS_PER_CHUNK; i++) {
|
|
||||||
int off = ((i >> 4) & 0xC) + ((i >> 2) & 0x3);
|
|
||||||
int bv = bb[off + 64]; // Offset to y=64
|
|
||||||
if (bv < 0) bv = 0;
|
|
||||||
this.biome[i] = bv;
|
|
||||||
}
|
|
||||||
} else { // Else, older chunks
|
|
||||||
for (int i = 0; i < bb.length; i++) {
|
|
||||||
int bv = bb[i];
|
|
||||||
if (bv < 0) bv = 0;
|
|
||||||
this.biome[i] = bv;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +328,11 @@ public class ChunkSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getBiome(int x, int z) {
|
public int getBiome(int x, int z) {
|
||||||
return biome[z << 4 | x];
|
int y = getHighestBlockYAt(x, z);
|
||||||
|
final int idx = (y >> 4) + sectionOffset;
|
||||||
|
if ((idx < 0) || (idx >= section.length))
|
||||||
|
return 0;
|
||||||
|
return section[idx].getBiome(x % 16, y % 16, z % 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getCaptureFullTime() {
|
public final long getCaptureFullTime() {
|
||||||
|
Loading…
Reference in New Issue
Block a user