Lazily initialize nbtReader

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-11-04 19:13:11 +01:00
parent acc711c640
commit ca6f0b1eb5

View File

@ -28,7 +28,7 @@ import java.util.function.Supplier;
*/
public class BinaryReader extends InputStream {
private final ByteBuffer buffer;
private final NBTReader nbtReader = new NBTReader(this, false);
private NBTReader nbtReader;
public BinaryReader(@NotNull ByteBuffer buffer) {
this.buffer = buffer;
@ -235,7 +235,12 @@ public class BinaryReader extends InputStream {
}
public NBT readTag() throws IOException, NBTException {
return nbtReader.read();
NBTReader reader = this.nbtReader;
if (reader == null) {
reader = new NBTReader(this, false);
this.nbtReader = reader;
}
return reader.read();
}
/**