Fix lazy nbt reading for int/long arrays

This commit is contained in:
Jesse Boyd 2019-04-01 21:29:41 +11:00
parent a636a30e9f
commit 49e3102779
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -21,12 +21,15 @@ package com.sk89q.jnbt;
import com.boydti.fawe.jnbt.NBTStreamer; import com.boydti.fawe.jnbt.NBTStreamer;
import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.util.StringMan;
import java.io.Closeable; import java.io.Closeable;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -407,7 +410,7 @@ public final class NBTInputStream implements Closeable {
int toRead = Math.min(length << 2, buf.length); int toRead = Math.min(length << 2, buf.length);
is.readFully(buf, 0, toRead); is.readFully(buf, 0, toRead);
for (int i = 0; i < toRead; i += 4, index++) { for (int i = 0; i < toRead; i += 4, index++) {
data[index] = ((buf[i] << 24) + (buf[i + 1] << 16) + (buf[i + 2] << 8) + (buf[i + 3])); data[index] = ((buf[i + 0] & 0xFF) << 24) + ((buf[i + 1] & 0xFF) << 16) + ((buf[i + 2] & 0xFF) << 8) + (buf[i + 3] & 0xFF);
} }
length -= toRead; length -= toRead;
} }
@ -424,7 +427,7 @@ public final class NBTInputStream implements Closeable {
int toRead = Math.min(length << 3, buf.length); int toRead = Math.min(length << 3, buf.length);
is.readFully(buf, 0, toRead); is.readFully(buf, 0, toRead);
for (int i = 0; i < toRead; i += 8, index++) { for (int i = 0; i < toRead; i += 8, index++) {
data[index] = (((long) buf[i] << 56) | ((long) buf[i + 1] << 48) | ((long) buf[i + 2] << 40) | ((long) buf[i + 3] << 32) | (buf[i + 4] << 24) | (buf[i + 5] << 16) | (buf[i + 6] << 8) | (buf[i + 7])); data[index] = (((long) buf[i] << 56) | ((long) (buf[i + 1] & 255) << 48) | ((long) (buf[i + 2] & 255) << 40) | ((long) (buf[i + 3] & 255) << 32) | ((long) (buf[i + 4] & 255) << 24) | ((buf[i + 5] & 255) << 16) | ((buf[i + 6] & 255) << 8) | (buf[i + 7] & 255));
} }
length -= toRead; length -= toRead;
} }