Support NotEnoughIDs and JustEnoughIDs NBT formats (blockids, biomes)

This commit is contained in:
Mike Primm 2018-09-06 00:16:15 -05:00
parent 09ccad6eca
commit 0a739347bf
7 changed files with 311 additions and 198 deletions

View File

@ -24,7 +24,7 @@ public class ChunkSnapshot
private final byte[][] emitlight;
private final boolean[] empty;
private final int[] hmap; // Height map
private final byte[] biome;
private final int[] biome;
private final long captureFulltime;
private final int sectionCnt;
private final long inhabitedTicks;
@ -65,7 +65,7 @@ public class ChunkSnapshot
this.x = x;
this.z = z;
this.captureFulltime = captime;
this.biome = new byte[COLUMNS_PER_CHUNK];
this.biome = new int[COLUMNS_PER_CHUNK];
this.sectionCnt = worldheight / 16;
/* Allocate arrays indexed by section */
this.blockids = new short[this.sectionCnt][];
@ -146,6 +146,19 @@ public class ChunkSnapshot
blkids[(j << 1) + 1] |= (b & 0xF0) << 4;
}
}
if (sec.hasKey("Add2")) { /* If additional data (NEID), add it */
byte[] msb = sec.getByteArray("Add2");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 12;
blkids[(j << 1) + 1] |= (b & 0xF0) << 8;
}
}
this.blockdata[secnum] = sec.getByteArray("Data");
this.emitlight[secnum] = sec.getByteArray("BlockLight");
if (sec.hasKey("SkyLight")) {
@ -154,15 +167,22 @@ public class ChunkSnapshot
this.empty[secnum] = false;
}
/* Get biome data */
this.biome = new int[COLUMNS_PER_CHUNK];
if (nbt.hasKey("Biomes")) {
byte[] b = nbt.getByteArray("Biomes");
if (b.length < COLUMNS_PER_CHUNK) {
b = Arrays.copyOf(b, COLUMNS_PER_CHUNK);
if (b != null) {
for (int i = 0; i < b.length; i++) {
this.biome[i] = 255 & b[i];
}
}
else { // Check JEI biomes
int[] bb = nbt.getIntArray("Biomes");
if (bb != null) {
for (int i = 0; i < bb.length; i++) {
this.biome[i] = bb[i];
}
}
}
this.biome = b;
}
else {
this.biome = new byte[COLUMNS_PER_CHUNK];
}
}
@ -226,7 +246,7 @@ public class ChunkSnapshot
public int getBiome(int x, int z)
{
return 255 & biome[z << 4 | x];
return biome[z << 4 | x];
}
public final long getCaptureFullTime()

View File

@ -1,15 +1,10 @@
package org.dynmap.forge_1_11_2;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.dynmap.Log;
import org.dynmap.renderer.DynmapBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.chunk.NibbleArray;
import scala.actors.threadpool.Arrays;
/**
* Represents a static, thread-safe snapshot of chunk of blocks
@ -24,7 +19,7 @@ public class ChunkSnapshot
private final byte[][] emitlight;
private final boolean[] empty;
private final int[] hmap; // Height map
private final byte[] biome;
private final int[] biome;
private final long captureFulltime;
private final int sectionCnt;
private final long inhabitedTicks;
@ -34,7 +29,6 @@ public class ChunkSnapshot
private static final short[] emptyIDs = new short[BLOCKS_PER_SECTION];
private static final byte[] emptyData = new byte[BLOCKS_PER_SECTION / 2];
private static final byte[] fullData = new byte[BLOCKS_PER_SECTION / 2];
private static Method getvalarray = null;
static
{
@ -42,16 +36,6 @@ public class ChunkSnapshot
{
fullData[i] = (byte)0xFF;
}
try {
Method[] m = NibbleArray.class.getDeclaredMethods();
for (Method mm : m) {
if (mm.getName().equals("getValueArray")) {
getvalarray = mm;
break;
}
}
} catch (Exception x) {
}
}
/**
@ -65,7 +49,7 @@ public class ChunkSnapshot
this.x = x;
this.z = z;
this.captureFulltime = captime;
this.biome = new byte[COLUMNS_PER_CHUNK];
this.biome = new int[COLUMNS_PER_CHUNK];
this.sectionCnt = worldheight / 16;
/* Allocate arrays indexed by section */
this.blockids = new short[this.sectionCnt][];
@ -125,28 +109,55 @@ public class ChunkSnapshot
Log.info("Section " + (int) secnum + " above world height " + worldheight);
continue;
}
byte[] lsb_bytes = sec.getByteArray("Blocks");
short[] blkids = new short[BLOCKS_PER_SECTION];
this.blockids[secnum] = blkids;
int len = BLOCKS_PER_SECTION;
if(len > lsb_bytes.length) len = lsb_bytes.length;
for(int j = 0; j < len; j++) {
blkids[j] = (short)(0xFF & lsb_bytes[j]);
}
if (sec.hasKey("Add")) { /* If additional data, add it */
byte[] msb = sec.getByteArray("Add");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 8;
blkids[(j << 1) + 1] |= (b & 0xF0) << 4;
// JEI format
if (sec.hasKey("Palette", 11)) {
byte[] bd = new byte[BLOCKS_PER_SECTION / 2];
int[] p = sec.getIntArray("Palette");
this.blockdata[secnum] = bd;
int len = BLOCKS_PER_SECTION;
if(len > p.length) len = p.length;
for(int j = 0; j < len; j++) {
blkids[j] = (short)((p[j] >> 4) & 0xFFFF);
bd[j / 2] |= (p[j] & 0xF) << (4 * (j&1));
}
}
this.blockdata[secnum] = sec.getByteArray("Data");
else {
byte[] lsb_bytes = sec.getByteArray("Blocks");
int len = BLOCKS_PER_SECTION;
if(len > lsb_bytes.length) len = lsb_bytes.length;
for(int j = 0; j < len; j++) {
blkids[j] = (short)(0xFF & lsb_bytes[j]);
}
if (sec.hasKey("Add", 7)) { /* If additional data, add it */
byte[] msb = sec.getByteArray("Add");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 8;
blkids[(j << 1) + 1] |= (b & 0xF0) << 4;
}
}
if (sec.hasKey("Add2", 7)) { /* If additional data (NEID), add it */
byte[] msb = sec.getByteArray("Add2");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 12;
blkids[(j << 1) + 1] |= (b & 0xF0) << 8;
}
}
this.blockdata[secnum] = sec.getByteArray("Data");
}
this.emitlight[secnum] = sec.getByteArray("BlockLight");
if (sec.hasKey("SkyLight")) {
this.skylight[secnum] = sec.getByteArray("SkyLight");
@ -154,30 +165,27 @@ public class ChunkSnapshot
this.empty[secnum] = false;
}
/* Get biome data */
this.biome = new int[COLUMNS_PER_CHUNK];
if (nbt.hasKey("Biomes")) {
byte[] b = nbt.getByteArray("Biomes");
if (b.length < COLUMNS_PER_CHUNK) {
b = Arrays.copyOf(b, COLUMNS_PER_CHUNK);
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");
if (bb != null) {
for (int i = 0; i < bb.length; i++) {
int bv = bb[i];
this.biome[i] = (bv < 0) ? 0 : bv;
}
}
}
this.biome = b;
}
else {
this.biome = new byte[COLUMNS_PER_CHUNK];
}
}
private static byte[] getValueArray(NibbleArray na) {
if(getvalarray != null) {
try {
return (byte[])getvalarray.invoke(na);
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
return na.getData();
}
public int getX()
{
return x;
@ -226,7 +234,7 @@ public class ChunkSnapshot
public int getBiome(int x, int z)
{
return 255 & biome[z << 4 | x];
return biome[z << 4 | x];
}
public final long getCaptureFullTime()

View File

@ -155,12 +155,18 @@ public class DynmapPlugin
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
public void initializeBlockStates() {
stateByID = new DynmapBlockState[4096*16]; // Simple meta+id map
stateByID = new DynmapBlockState[512*16]; // Simple map - scale as needed
Arrays.fill(stateByID, DynmapBlockState.AIR); // Default to air
for (int i = 0; i < 4096; i++) {
Block b = getBlockByID(i);
if (b == null) continue;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
if (i >= (stateByID.length >> 4)) {
int plen = stateByID.length;
stateByID = Arrays.copyOf(stateByID, (i+1) << 4);
Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
}
ResourceLocation ui = null;
try {
ui = Block.REGISTRY.getNameForObject(b);
@ -180,7 +186,7 @@ public class DynmapPlugin
try {
blkstate = b.getStateFromMeta(m);
} catch (Exception x) {
// Bad metadata
// Invalid metadata
}
if (blkstate != null) {
Material mat = blkstate.getMaterial();
@ -200,7 +206,8 @@ public class DynmapPlugin
}
}
}
}
}
//for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.verboseinfo(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
@ -229,10 +236,16 @@ public class DynmapPlugin
public static final Biome[] getBiomeList() {
if (biomelist == null) {
biomelist = new Biome[256];
for (int i = 0; i < biomelist.length; i++) {
biomelist[i] = Biome.getBiome(i);
}
biomelist = new Biome[256];
Iterator<Biome> iter = Biome.REGISTRY.iterator();
while (iter.hasNext()) {
Biome b = iter.next();
int bidx = Biome.getIdForBiome(b);
if (bidx >= biomelist.length) {
biomelist = Arrays.copyOf(biomelist, bidx + biomelist.length);
}
biomelist[bidx] = b;
}
}
return biomelist;
}
@ -992,9 +1005,10 @@ public class DynmapPlugin
@Override
public Map<Integer, String> getBlockIDMap() {
Map<Integer, String> map = new HashMap<Integer, String>();
for (int i = 0; i < 4096; i++) {
Block b = getBlockByID(i);
if (b == null) continue;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
ResourceLocation ui = Block.REGISTRY.getNameForObject(b);
if (ui != null) {
map.put(i, ui.getResourceDomain() + ":" + ui.getResourcePath());
@ -1032,9 +1046,10 @@ public class DynmapPlugin
@Override
public Map<String, Integer> getBlockUniqueIDMap() {
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (int i = 0; i < 4096; i++) {
Block b = getBlockByID(i);
if (b == null) continue;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
ResourceLocation ui = null;
try {
ui = Block.REGISTRY.getNameForObject(b);
@ -1387,23 +1402,26 @@ public class DynmapPlugin
}
private int[] getBlockMaterialMap() {
int[] map = new int[4096];
int[] map = new int[512];
ArrayList<Material> mats = new ArrayList<Material>();
for (int i = 0; i < map.length; i++) {
Block b = getBlockByID(i);
if(b != null) {
Material mat = b.getBlockState().getBaseState().getMaterial();
if (mat != null) {
map[i] = mats.indexOf(mat);
if (map[i] < 0) {
map[i] = mats.size();
mats.add(mat);
}
}
else {
map[i] = -1;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
if (i >= map.length) {
map = Arrays.copyOf(map, i+1);
}
Material mat = b.getBlockState().getBaseState().getMaterial();
if (mat != null) {
map[i] = mats.indexOf(mat);
if (map[i] < 0) {
map[i] = mats.size();
mats.add(mat);
}
}
else {
map[i] = -1;
}
}
return map;
}

View File

@ -1,15 +1,10 @@
package org.dynmap.forge_1_12_2;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.dynmap.Log;
import org.dynmap.renderer.DynmapBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.chunk.NibbleArray;
import scala.actors.threadpool.Arrays;
/**
* Represents a static, thread-safe snapshot of chunk of blocks
@ -24,7 +19,7 @@ public class ChunkSnapshot
private final byte[][] emitlight;
private final boolean[] empty;
private final int[] hmap; // Height map
private final byte[] biome;
private final int[] biome;
private final long captureFulltime;
private final int sectionCnt;
private final long inhabitedTicks;
@ -34,7 +29,6 @@ public class ChunkSnapshot
private static final short[] emptyIDs = new short[BLOCKS_PER_SECTION];
private static final byte[] emptyData = new byte[BLOCKS_PER_SECTION / 2];
private static final byte[] fullData = new byte[BLOCKS_PER_SECTION / 2];
private static Method getvalarray = null;
static
{
@ -42,16 +36,6 @@ public class ChunkSnapshot
{
fullData[i] = (byte)0xFF;
}
try {
Method[] m = NibbleArray.class.getDeclaredMethods();
for (Method mm : m) {
if (mm.getName().equals("getValueArray")) {
getvalarray = mm;
break;
}
}
} catch (Exception x) {
}
}
/**
@ -65,7 +49,7 @@ public class ChunkSnapshot
this.x = x;
this.z = z;
this.captureFulltime = captime;
this.biome = new byte[COLUMNS_PER_CHUNK];
this.biome = new int[COLUMNS_PER_CHUNK];
this.sectionCnt = worldheight / 16;
/* Allocate arrays indexed by section */
this.blockids = new short[this.sectionCnt][];
@ -125,28 +109,55 @@ public class ChunkSnapshot
Log.info("Section " + (int) secnum + " above world height " + worldheight);
continue;
}
byte[] lsb_bytes = sec.getByteArray("Blocks");
short[] blkids = new short[BLOCKS_PER_SECTION];
this.blockids[secnum] = blkids;
int len = BLOCKS_PER_SECTION;
if(len > lsb_bytes.length) len = lsb_bytes.length;
for(int j = 0; j < len; j++) {
blkids[j] = (short)(0xFF & lsb_bytes[j]);
}
if (sec.hasKey("Add")) { /* If additional data, add it */
byte[] msb = sec.getByteArray("Add");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 8;
blkids[(j << 1) + 1] |= (b & 0xF0) << 4;
// JEI format
if (sec.hasKey("Palette", 11)) {
byte[] bd = new byte[BLOCKS_PER_SECTION / 2];
int[] p = sec.getIntArray("Palette");
this.blockdata[secnum] = bd;
int len = BLOCKS_PER_SECTION;
if(len > p.length) len = p.length;
for(int j = 0; j < len; j++) {
blkids[j] = (short)((p[j] >> 4) & 0xFFFF);
bd[j / 2] |= (p[j] & 0xF) << (4 * (j&1));
}
}
this.blockdata[secnum] = sec.getByteArray("Data");
else {
byte[] lsb_bytes = sec.getByteArray("Blocks");
int len = BLOCKS_PER_SECTION;
if(len > lsb_bytes.length) len = lsb_bytes.length;
for(int j = 0; j < len; j++) {
blkids[j] = (short)(0xFF & lsb_bytes[j]);
}
if (sec.hasKey("Add", 7)) { /* If additional data, add it */
byte[] msb = sec.getByteArray("Add");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 8;
blkids[(j << 1) + 1] |= (b & 0xF0) << 4;
}
}
if (sec.hasKey("Add2", 7)) { /* If additional data (NEID), add it */
byte[] msb = sec.getByteArray("Add2");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 12;
blkids[(j << 1) + 1] |= (b & 0xF0) << 8;
}
}
this.blockdata[secnum] = sec.getByteArray("Data");
}
this.emitlight[secnum] = sec.getByteArray("BlockLight");
if (sec.hasKey("SkyLight")) {
this.skylight[secnum] = sec.getByteArray("SkyLight");
@ -154,30 +165,27 @@ public class ChunkSnapshot
this.empty[secnum] = false;
}
/* Get biome data */
this.biome = new int[COLUMNS_PER_CHUNK];
if (nbt.hasKey("Biomes")) {
byte[] b = nbt.getByteArray("Biomes");
if (b.length < COLUMNS_PER_CHUNK) {
b = Arrays.copyOf(b, COLUMNS_PER_CHUNK);
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");
if (bb != null) {
for (int i = 0; i < bb.length; i++) {
int bv = bb[i];
this.biome[i] = (bv < 0) ? 0 : bv;
}
}
}
this.biome = b;
}
else {
this.biome = new byte[COLUMNS_PER_CHUNK];
}
}
private static byte[] getValueArray(NibbleArray na) {
if(getvalarray != null) {
try {
return (byte[])getvalarray.invoke(na);
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
return na.getData();
}
public int getX()
{
return x;
@ -226,7 +234,7 @@ public class ChunkSnapshot
public int getBiome(int x, int z)
{
return 255 & biome[z << 4 | x];
return biome[z << 4 | x];
}
public final long getCaptureFullTime()

View File

@ -36,6 +36,7 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.NetworkManager;
@ -155,12 +156,18 @@ public class DynmapPlugin
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
public void initializeBlockStates() {
stateByID = new DynmapBlockState[4096*16]; // Simple meta+id map
stateByID = new DynmapBlockState[512*16]; // Simple map - scale as needed
Arrays.fill(stateByID, DynmapBlockState.AIR); // Default to air
for (int i = 0; i < 4096; i++) {
Block b = getBlockByID(i);
if (b == null) continue;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
if (i >= (stateByID.length >> 4)) {
int plen = stateByID.length;
stateByID = Arrays.copyOf(stateByID, (i+1) << 4);
Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
}
ResourceLocation ui = null;
try {
ui = Block.REGISTRY.getNameForObject(b);
@ -200,7 +207,8 @@ public class DynmapPlugin
}
}
}
}
}
//for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.verboseinfo(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
@ -229,10 +237,16 @@ public class DynmapPlugin
public static final Biome[] getBiomeList() {
if (biomelist == null) {
biomelist = new Biome[256];
for (int i = 0; i < biomelist.length; i++) {
biomelist[i] = Biome.getBiome(i);
}
biomelist = new Biome[256];
Iterator<Biome> iter = Biome.REGISTRY.iterator();
while (iter.hasNext()) {
Biome b = iter.next();
int bidx = Biome.getIdForBiome(b);
if (bidx >= biomelist.length) {
biomelist = Arrays.copyOf(biomelist, bidx + biomelist.length);
}
biomelist[bidx] = b;
}
}
return biomelist;
}
@ -992,9 +1006,10 @@ public class DynmapPlugin
@Override
public Map<Integer, String> getBlockIDMap() {
Map<Integer, String> map = new HashMap<Integer, String>();
for (int i = 0; i < 4096; i++) {
Block b = getBlockByID(i);
if (b == null) continue;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
ResourceLocation ui = Block.REGISTRY.getNameForObject(b);
if (ui != null) {
map.put(i, ui.getResourceDomain() + ":" + ui.getResourcePath());
@ -1032,9 +1047,10 @@ public class DynmapPlugin
@Override
public Map<String, Integer> getBlockUniqueIDMap() {
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (int i = 0; i < 4096; i++) {
Block b = getBlockByID(i);
if (b == null) continue;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
ResourceLocation ui = null;
try {
ui = Block.REGISTRY.getNameForObject(b);
@ -1387,23 +1403,26 @@ public class DynmapPlugin
}
private int[] getBlockMaterialMap() {
int[] map = new int[4096];
int[] map = new int[512];
ArrayList<Material> mats = new ArrayList<Material>();
for (int i = 0; i < map.length; i++) {
Block b = getBlockByID(i);
if(b != null) {
Material mat = b.getBlockState().getBaseState().getMaterial();
if (mat != null) {
map[i] = mats.indexOf(mat);
if (map[i] < 0) {
map[i] = mats.size();
mats.add(mat);
}
}
else {
map[i] = -1;
Iterator<Block> iter = Block.REGISTRY.iterator();
while (iter.hasNext()) {
Block b = iter.next();
int i = Block.getIdFromBlock(b);
if (i >= map.length) {
map = Arrays.copyOf(map, i+1);
}
Material mat = b.getBlockState().getBaseState().getMaterial();
if (mat != null) {
map[i] = mats.indexOf(mat);
if (map[i] < 0) {
map[i] = mats.size();
mats.add(mat);
}
}
else {
map[i] = -1;
}
}
return map;
}

View File

@ -26,7 +26,7 @@ public class ChunkSnapshot
private final byte[][] emitlight;
private final boolean[] empty;
private final int[] hmap; // Height map
private final byte[] biome;
private final int[] biome;
private final long captureFulltime;
private final int sectionCnt;
private final long inhabitedTicks;
@ -67,7 +67,7 @@ public class ChunkSnapshot
this.x = x;
this.z = z;
this.captureFulltime = captime;
this.biome = new byte[COLUMNS_PER_CHUNK];
this.biome = new int[COLUMNS_PER_CHUNK];
this.sectionCnt = worldheight / 16;
/* Allocate arrays indexed by section */
this.blockids = new short[this.sectionCnt][];
@ -148,6 +148,19 @@ public class ChunkSnapshot
blkids[(j << 1) + 1] |= (b & 0xF0) << 4;
}
}
if (sec.hasKey("Add2")) { /* If additional data (NEID), add it */
byte[] msb = sec.getByteArray("Add2");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 12;
blkids[(j << 1) + 1] |= (b & 0xF0) << 8;
}
}
this.blockdata[secnum] = sec.getByteArray("Data");
this.emitlight[secnum] = sec.getByteArray("BlockLight");
if (sec.hasKey("SkyLight")) {
@ -156,15 +169,22 @@ public class ChunkSnapshot
this.empty[secnum] = false;
}
/* Get biome data */
this.biome = new int[COLUMNS_PER_CHUNK];
if (nbt.hasKey("Biomes")) {
byte[] b = nbt.getByteArray("Biomes");
if (b.length < COLUMNS_PER_CHUNK) {
b = Arrays.copyOf(b, COLUMNS_PER_CHUNK);
if (b != null) {
for (int i = 0; i < b.length; i++) {
this.biome[i] = 255 & b[i];
}
}
else { // Check JEI biomes
int[] bb = nbt.getIntArray("Biomes");
if (bb != null) {
for (int i = 0; i < bb.length; i++) {
this.biome[i] = bb[i];
}
}
}
this.biome = b;
}
else {
this.biome = new byte[COLUMNS_PER_CHUNK];
}
}
@ -273,7 +293,7 @@ public class ChunkSnapshot
public int getBiome(int x, int z)
{
return 255 & biome[z << 4 | x];
return biome[z << 4 | x];
}
public final long getCaptureFullTime()

View File

@ -24,7 +24,7 @@ public class ChunkSnapshot
private final byte[][] emitlight;
private final boolean[] empty;
private final int[] hmap; // Height map
private final byte[] biome;
private final int[] biome;
private final long captureFulltime;
private final int sectionCnt;
private final long inhabitedTicks;
@ -65,7 +65,7 @@ public class ChunkSnapshot
this.x = x;
this.z = z;
this.captureFulltime = captime;
this.biome = new byte[COLUMNS_PER_CHUNK];
this.biome = new int[COLUMNS_PER_CHUNK];
this.sectionCnt = worldheight / 16;
/* Allocate arrays indexed by section */
this.blockids = new short[this.sectionCnt][];
@ -146,6 +146,19 @@ public class ChunkSnapshot
blkids[(j << 1) + 1] |= (b & 0xF0) << 4;
}
}
if (sec.hasKey("Add2")) { /* If additional data (NEID), add it */
byte[] msb = sec.getByteArray("Add2");
len = BLOCKS_PER_SECTION / 2;
if(len > msb.length) len = msb.length;
for (int j = 0; j < len; j++) {
short b = (short)(msb[j] & 0xFF);
if (b == 0) {
continue;
}
blkids[j << 1] |= (b & 0x0F) << 12;
blkids[(j << 1) + 1] |= (b & 0xF0) << 8;
}
}
this.blockdata[secnum] = sec.getByteArray("Data");
this.emitlight[secnum] = sec.getByteArray("BlockLight");
if (sec.hasKey("SkyLight")) {
@ -154,15 +167,22 @@ public class ChunkSnapshot
this.empty[secnum] = false;
}
/* Get biome data */
this.biome = new int[COLUMNS_PER_CHUNK];
if (nbt.hasKey("Biomes")) {
byte[] b = nbt.getByteArray("Biomes");
if (b.length < COLUMNS_PER_CHUNK) {
b = Arrays.copyOf(b, COLUMNS_PER_CHUNK);
if (b != null) {
for (int i = 0; i < b.length; i++) {
this.biome[i] = 255 & b[i];
}
}
else { // Check JEI biomes
int[] bb = nbt.getIntArray("Biomes");
if (bb != null) {
for (int i = 0; i < bb.length; i++) {
this.biome[i] = bb[i];
}
}
}
this.biome = b;
}
else {
this.biome = new byte[COLUMNS_PER_CHUNK];
}
}
@ -226,7 +246,7 @@ public class ChunkSnapshot
public int getBiome(int x, int z)
{
return 255 & biome[z << 4 | x];
return biome[z << 4 | x];
}
public final long getCaptureFullTime()