Get Forge 1.13.2 chunk reading working

This commit is contained in:
Mike Primm 2020-05-03 15:05:28 -05:00
parent 0cb59d23a4
commit 0d937ce368
2 changed files with 52 additions and 95 deletions

View File

@ -7,6 +7,7 @@ import org.dynmap.renderer.DynmapBlockState;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.BitArray;
/** /**
* Represents a static, thread-safe snapshot of chunk of blocks * Represents a static, thread-safe snapshot of chunk of blocks
@ -140,96 +141,60 @@ public class ChunkSnapshot
NBTTagList sect = nbt.getList("Sections", 10); NBTTagList sect = nbt.getList("Sections", 10);
for (int i = 0; i < sect.size(); i++) { for (int i = 0; i < sect.size(); i++) {
NBTTagCompound sec = sect.getCompound(i); NBTTagCompound sec = sect.getCompound(i);
byte secnum = sec.getByte("Y"); int secnum = sec.getByte("Y");
if (secnum >= this.sectionCnt) { if (secnum >= this.sectionCnt) {
Log.info("Section " + (int) secnum + " above world height " + worldheight); //Log.info("Section " + (int) secnum + " above world height " + worldheight);
continue; continue;
} }
if (secnum < 0)
continue;
//System.out.println("section(" + secnum + ")=" + sec.asString());
// Create normal section to initialize // Create normal section to initialize
StdSection cursect = new StdSection(); StdSection cursect = new StdSection();
this.section[secnum] = cursect; this.section[secnum] = cursect;
DynmapBlockState[] states = cursect.states; DynmapBlockState[] states = cursect.states;
// JEI format DynmapBlockState[] palette = null;
if (sec.contains("Palette")) { // If we've got palette and block states list, process non-empty section
int[] p = sec.getIntArray("Palette"); if (sec.contains("Palette", 9) && sec.contains("BlockStates", 12)) {
// Palette is list of state values, where Blocks=bit 11-4 of index, Data=bit 3-0 NBTTagList plist = sec.getList("Palette", 10);
byte[] msb_bytes = sec.getByteArray("Blocks"); long[] statelist = sec.getLongArray("BlockStates");
int mlen = msb_bytes.length / 2; palette = new DynmapBlockState[plist.size()];
byte[] lsb_bytes = sec.getByteArray("Data"); for (int pi = 0; pi < plist.size(); pi++) {
int llen = BLOCKS_PER_SECTION / 2; NBTTagCompound tc = plist.getCompound(pi);
if (llen > lsb_bytes.length) llen = lsb_bytes.length; String pname = tc.getString("Name");
for(int j = 0; j < llen; j++) { if (tc.contains("Properties")) {
int idx = lsb_bytes[j] & 0xF; StringBuilder statestr = new StringBuilder();
int idx2 = (lsb_bytes[j] & 0xF0) >>> 4; NBTTagCompound prop = tc.getCompound("Properties");
if (j < mlen) { for (String pid : prop.keySet()) {
idx += (255 & msb_bytes[2*j]) << 4; if (statestr.length() > 0) statestr.append(',');
idx2 += (255 & msb_bytes[2*j+1]) << 4; statestr.append(pid).append('=').append(prop.get(pid).getString());
} }
// Get even block id palette[pi] = DynmapBlockState.getStateByNameAndState(pname, statestr.toString());
states[2*j] = DynmapPlugin.stateByID[(idx < p.length) ? p[idx] : 0]; }
// Get odd block id if (palette[pi] == null) {
states[2*j+1] = DynmapPlugin.stateByID[(idx2 < p.length) ? p[idx2] : 0]; palette[pi] = DynmapBlockState.getBaseStateByName(pname);
}
if (palette[pi] == null) {
palette[pi] = DynmapBlockState.AIR;
}
}
int bitsperblock = (statelist.length * 64) / 4096;
BitArray db = new BitArray(bitsperblock, 4096, statelist);
if (bitsperblock > 8) { // Not palette
for (int j = 0; j < 4096; j++) {
states[j] = DynmapBlockState.getStateByGlobalIndex(db.getAt(j));
} }
} }
else { else {
// Get block IDs for (int j = 0; j < 4096; j++) {
byte[] lsb_bytes = sec.getByteArray("Blocks"); int v = db.getAt(j);
if (lsb_bytes.length < BLOCKS_PER_SECTION) { states[j] = (v < palette.length) ? palette[v] : DynmapBlockState.AIR;
lsb_bytes = Arrays.copyOf(lsb_bytes, BLOCKS_PER_SECTION);
}
// Get any additional ID data
byte[] addid = null;
if (sec.contains("Add")) { /* If additional data, add it */
addid = sec.getByteArray("Add");
if (addid.length < (BLOCKS_PER_SECTION / 2)) {
addid = Arrays.copyOf(addid, (BLOCKS_PER_SECTION / 2));
} }
} }
// Check for NEID additional additional ID data
byte[] addid2 = null;
if (sec.contains("Add2")) { /* If additional data (NEID), add it */
addid2 = sec.getByteArray("Add2");
if (addid2.length < (BLOCKS_PER_SECTION / 2)) {
addid2 = Arrays.copyOf(addid2, (BLOCKS_PER_SECTION / 2));
}
}
// Get meta nibble data
byte[] bd = null;
if (sec.contains("Data")) {
bd = sec.getByteArray("Data");
if (bd.length < (BLOCKS_PER_SECTION / 2)) {
bd = Arrays.copyOf(bd, (BLOCKS_PER_SECTION / 2));
}
}
// Traverse section
for(int j = 0; j < BLOCKS_PER_SECTION; j += 2) {
// Start with block ID
int id = (0xFF & lsb_bytes[j]) << 4;
int id2 = (0xFF & lsb_bytes[j+1]) << 4;
// Add in additional parts
if (addid != null) {
byte b = addid[j >> 1];
id += (0xF & b) << 12;
id2 += (0xF0 & b) << 8;
}
// Add in additional additional parts
if (addid2 != null) {
byte b = addid2[j >> 1];
id += (0xF & b) << 16;
id2 += (0xF0 & b) << 12;
}
// Add in metadata
if (bd != null) {
byte b = bd[j >> 1];
id += (0xF & b);
id2 += (0xF0 & b) >> 4;
}
// Compute states
states[j] = DynmapPlugin.stateByID[id];
states[j+1] = DynmapPlugin.stateByID[id2];
}
} }
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");
} }
@ -237,14 +202,6 @@ public class ChunkSnapshot
/* Get biome data */ /* Get biome data */
this.biome = new int[COLUMNS_PER_CHUNK]; this.biome = new int[COLUMNS_PER_CHUNK];
if (nbt.contains("Biomes")) { if (nbt.contains("Biomes")) {
byte[] b = nbt.getByteArray("Biomes");
if (b != null) {
for (int i = 0; i < b.length; i++) {
int bv = 255 & b[i];
this.biome[i] = (bv == 255) ? 0 : bv;
}
}
else { // Check JEI biomes
int[] bb = nbt.getIntArray("Biomes"); int[] bb = nbt.getIntArray("Biomes");
if (bb != null) { if (bb != null) {
for (int i = 0; i < bb.length; i++) { for (int i = 0; i < bb.length; i++) {
@ -254,7 +211,6 @@ public class ChunkSnapshot
} }
} }
} }
}
public int getX() public int getX()
{ {

View File

@ -1097,6 +1097,7 @@ public class ForgeMapChunkCache extends MapChunkCache
} }
if(rslt != null) if(rslt != null)
rslt = rslt.getCompound("Level"); rslt = rslt.getCompound("Level");
//Log.info(String.format("loadChunk(%d,%d)=%s", x, z, (rslt != null) ? rslt.toString() : "null"));
return rslt; return rslt;
} catch (Exception exc) { } catch (Exception exc) {
Log.severe(String.format("Error reading chunk: %s,%d,%d", dw.getName(), x, z), exc); Log.severe(String.format("Error reading chunk: %s,%d,%d", dw.getName(), x, z), exc);