mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-09 01:06:05 +00:00
Cleanup
This commit is contained in:
@@ -20,7 +20,20 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.engine.data.io.ExceptionBiFunction;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -49,31 +62,13 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
|
||||
put(LongArrayTag.ID, (i, d) -> readLongArray(i), LongArrayTag.class);
|
||||
}
|
||||
|
||||
private static void put(byte id, ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> reader, Class<?> clazz) {
|
||||
readers.put(id, reader);
|
||||
idClassMapping.put(id, clazz);
|
||||
}
|
||||
|
||||
public NBTInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public NamedTag readTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return new NamedTag(readUTF(), readTag(id, maxDepth));
|
||||
}
|
||||
|
||||
public Tag<?> readRawTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return readTag(id, maxDepth);
|
||||
}
|
||||
|
||||
private Tag<?> readTag(byte type, int maxDepth) throws IOException {
|
||||
ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> f;
|
||||
if ((f = readers.get(type)) == null) {
|
||||
throw new IOException("invalid tag id \"" + type + "\"");
|
||||
}
|
||||
return f.accept(this, maxDepth);
|
||||
private static void put(byte id, ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> reader, Class<?> clazz) {
|
||||
readers.put(id, reader);
|
||||
idClassMapping.put(id, clazz);
|
||||
}
|
||||
|
||||
private static ByteTag readByte(NBTInputStream in) throws IOException {
|
||||
@@ -152,4 +147,22 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
public NamedTag readTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return new NamedTag(readUTF(), readTag(id, maxDepth));
|
||||
}
|
||||
|
||||
public Tag<?> readRawTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return readTag(id, maxDepth);
|
||||
}
|
||||
|
||||
private Tag<?> readTag(byte type, int maxDepth) throws IOException {
|
||||
ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> f;
|
||||
if ((f = readers.get(type)) == null) {
|
||||
throw new IOException("invalid tag id \"" + type + "\"");
|
||||
}
|
||||
return f.accept(this, maxDepth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,20 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.engine.data.io.ExceptionTriConsumer;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -50,37 +63,13 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
|
||||
put(LongArrayTag.ID, (o, t, d) -> writeLongArray(o, t), LongArrayTag.class);
|
||||
}
|
||||
|
||||
private static void put(byte id, ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f, Class<?> clazz) {
|
||||
writers.put(id, f);
|
||||
classIdMapping.put(clazz, id);
|
||||
}
|
||||
|
||||
public NBTOutputStream(OutputStream out) {
|
||||
super(out);
|
||||
}
|
||||
|
||||
public void writeTag(NamedTag tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getTag().getID());
|
||||
if (tag.getTag().getID() != 0) {
|
||||
writeUTF(tag.getName() == null ? "" : tag.getName());
|
||||
}
|
||||
writeRawTag(tag.getTag(), maxDepth);
|
||||
}
|
||||
|
||||
public void writeTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getID());
|
||||
if (tag.getID() != 0) {
|
||||
writeUTF("");
|
||||
}
|
||||
writeRawTag(tag, maxDepth);
|
||||
}
|
||||
|
||||
public void writeRawTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f;
|
||||
if ((f = writers.get(tag.getID())) == null) {
|
||||
throw new IOException("invalid tag \"" + tag.getID() + "\"");
|
||||
}
|
||||
f.accept(this, tag, maxDepth);
|
||||
private static void put(byte id, ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f, Class<?> clazz) {
|
||||
writers.put(id, f);
|
||||
classIdMapping.put(clazz, id);
|
||||
}
|
||||
|
||||
static byte idFromClass(Class<?> clazz) {
|
||||
@@ -157,4 +146,28 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
|
||||
}
|
||||
out.writeByte(0);
|
||||
}
|
||||
|
||||
public void writeTag(NamedTag tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getTag().getID());
|
||||
if (tag.getTag().getID() != 0) {
|
||||
writeUTF(tag.getName() == null ? "" : tag.getName());
|
||||
}
|
||||
writeRawTag(tag.getTag(), maxDepth);
|
||||
}
|
||||
|
||||
public void writeTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getID());
|
||||
if (tag.getID() != 0) {
|
||||
writeUTF("");
|
||||
}
|
||||
writeRawTag(tag, maxDepth);
|
||||
}
|
||||
|
||||
public void writeRawTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f;
|
||||
if ((f = writers.get(tag.getID())) == null) {
|
||||
throw new IOException("invalid tag \"" + tag.getID() + "\"");
|
||||
}
|
||||
f.accept(this, tag, maxDepth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,13 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public final class NBTUtil {
|
||||
|
||||
@@ -30,19 +30,19 @@ public class NamedTag {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setTag(Tag<?> tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Tag<?> getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(Tag<?> tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,21 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,7 +19,20 @@
|
||||
package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
@@ -49,6 +62,23 @@ public final class SNBTWriter implements MaxDepthIO {
|
||||
write(tag, writer, Tag.DEFAULT_MAX_DEPTH);
|
||||
}
|
||||
|
||||
public static String escapeString(String s) {
|
||||
if (!NON_QUOTE_PATTERN.matcher(s).matches()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('"');
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\' || c == '"') {
|
||||
sb.append('\\');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append('"');
|
||||
return sb.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private void writeAnything(Tag<?> tag, int maxDepth) throws IOException {
|
||||
switch (tag.getID()) {
|
||||
case EndTag.ID:
|
||||
@@ -115,21 +145,4 @@ public final class SNBTWriter implements MaxDepthIO {
|
||||
}
|
||||
writer.write(']');
|
||||
}
|
||||
|
||||
public static String escapeString(String s) {
|
||||
if (!NON_QUOTE_PATTERN.matcher(s).matches()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('"');
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\' || c == '"') {
|
||||
sb.append('\\');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append('"');
|
||||
return sb.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ public class StringPointer {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private static boolean isSimpleChar(char c) {
|
||||
return c >= 'a' && c <= 'z'
|
||||
|| c >= 'A' && c <= 'Z'
|
||||
|| c >= '0' && c <= '9'
|
||||
|| c == '-'
|
||||
|| c == '+'
|
||||
|| c == '.'
|
||||
|| c == '_';
|
||||
}
|
||||
|
||||
public String parseSimpleString() {
|
||||
int oldIndex = index;
|
||||
while (hasNext() && isSimpleChar(currentChar())) {
|
||||
@@ -117,16 +127,6 @@ public class StringPointer {
|
||||
return value.charAt(index + offset);
|
||||
}
|
||||
|
||||
private static boolean isSimpleChar(char c) {
|
||||
return c >= 'a' && c <= 'z'
|
||||
|| c >= 'A' && c <= 'Z'
|
||||
|| c >= '0' && c <= '9'
|
||||
|| c == '-'
|
||||
|| c == '+'
|
||||
|| c == '.'
|
||||
|| c == '_';
|
||||
}
|
||||
|
||||
public ParseException parseException(String msg) {
|
||||
return new ParseException(msg, value, index);
|
||||
}
|
||||
|
||||
@@ -27,13 +27,19 @@ import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
import static com.volmit.iris.util.nbt.mca.LoadFlags.*;
|
||||
|
||||
public class Chunk {
|
||||
public static final int DEFAULT_DATA_VERSION = 2730;
|
||||
private final AtomicReferenceArray<Section> sections = new AtomicReferenceArray<>(16);
|
||||
private boolean partial;
|
||||
private int lastMCAUpdate;
|
||||
private CompoundTag data;
|
||||
@@ -43,7 +49,6 @@ public class Chunk {
|
||||
private BiomeContainer biomes;
|
||||
private CompoundTag heightMaps;
|
||||
private CompoundTag carvingMasks;
|
||||
private final AtomicReferenceArray<Section> sections = new AtomicReferenceArray<>(16);
|
||||
private ListTag<CompoundTag> entities;
|
||||
private ListTag<CompoundTag> tileEntities;
|
||||
private ListTag<CompoundTag> tileTicks;
|
||||
@@ -70,6 +75,23 @@ public class Chunk {
|
||||
setStatus("full");
|
||||
}
|
||||
|
||||
public static Chunk newChunk() {
|
||||
Chunk c = new Chunk(0);
|
||||
c.dataVersion = DEFAULT_DATA_VERSION;
|
||||
c.data = new CompoundTag();
|
||||
c.biomes = INMS.get().newBiomeContainer(0, 256);
|
||||
c.data.put("Level", defaultLevel());
|
||||
c.status = "full";
|
||||
return c;
|
||||
}
|
||||
|
||||
private static CompoundTag defaultLevel() {
|
||||
CompoundTag level = new CompoundTag();
|
||||
level.putString("Status", "full");
|
||||
level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion());
|
||||
return level;
|
||||
}
|
||||
|
||||
private void initReferences(long loadFlags) {
|
||||
if (data == null) {
|
||||
throw new NullPointerException("data cannot be null");
|
||||
@@ -550,23 +572,6 @@ public class Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
public static Chunk newChunk() {
|
||||
Chunk c = new Chunk(0);
|
||||
c.dataVersion = DEFAULT_DATA_VERSION;
|
||||
c.data = new CompoundTag();
|
||||
c.biomes = INMS.get().newBiomeContainer(0, 256);
|
||||
c.data.put("Level", defaultLevel());
|
||||
c.status = "full";
|
||||
return c;
|
||||
}
|
||||
|
||||
private static CompoundTag defaultLevel() {
|
||||
CompoundTag level = new CompoundTag();
|
||||
level.putString("Status", "full");
|
||||
level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion());
|
||||
return level;
|
||||
}
|
||||
|
||||
public CompoundTag updateHandle(int xPos, int zPos) {
|
||||
data.putInt("DataVersion", dataVersion);
|
||||
CompoundTag level = data.getCompoundTag("Level");
|
||||
|
||||
@@ -44,6 +44,15 @@ public enum CompressionType {
|
||||
this.decompressor = decompressor;
|
||||
}
|
||||
|
||||
public static CompressionType getFromID(byte id) {
|
||||
for (CompressionType c : CompressionType.values()) {
|
||||
if (c.id == id) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte getID() {
|
||||
return id;
|
||||
}
|
||||
@@ -55,13 +64,4 @@ public enum CompressionType {
|
||||
public InputStream decompress(InputStream in) throws IOException {
|
||||
return decompressor.accept(in);
|
||||
}
|
||||
|
||||
public static CompressionType getFromID(byte id) {
|
||||
for (CompressionType c : CompressionType.values()) {
|
||||
if (c.id == id) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,18 @@ public class MCAFile {
|
||||
this.regionZ = regionZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the index of a chunk from its x- and z-coordinates in this region.
|
||||
* This works with absolute and relative coordinates.
|
||||
*
|
||||
* @param chunkX The x-coordinate of the chunk.
|
||||
* @param chunkZ The z-coordinate of the chunk.
|
||||
* @return The index of this chunk.
|
||||
*/
|
||||
public static int getChunkIndex(int chunkX, int chunkZ) {
|
||||
return (chunkX & 0x1F) + (chunkZ & 0x1F) * 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an .mca file from a {@code RandomAccessFile} into this object.
|
||||
* This method does not perform any cleanups on the data.
|
||||
@@ -245,18 +257,6 @@ public class MCAFile {
|
||||
return getChunk(chunkX, chunkZ) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the index of a chunk from its x- and z-coordinates in this region.
|
||||
* This works with absolute and relative coordinates.
|
||||
*
|
||||
* @param chunkX The x-coordinate of the chunk.
|
||||
* @param chunkZ The z-coordinate of the chunk.
|
||||
* @return The index of this chunk.
|
||||
*/
|
||||
public static int getChunkIndex(int chunkX, int chunkZ) {
|
||||
return (chunkX & 0x1F) + (chunkZ & 0x1F) * 32;
|
||||
}
|
||||
|
||||
private int checkIndex(int index) {
|
||||
if (index < 0 || index > 1023) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
@@ -35,6 +35,8 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public final class MCAUtil {
|
||||
|
||||
private static final Pattern mcaFilePattern = Pattern.compile("^.*r\\.(?<regionX>-?\\d+)\\.(?<regionZ>-?\\d+)\\.mca$");
|
||||
|
||||
private MCAUtil() {
|
||||
}
|
||||
|
||||
@@ -259,8 +261,6 @@ public final class MCAUtil {
|
||||
return chunk << 4;
|
||||
}
|
||||
|
||||
private static final Pattern mcaFilePattern = Pattern.compile("^.*r\\.(?<regionX>-?\\d+)\\.(?<regionZ>-?\\d+)\\.mca$");
|
||||
|
||||
public static MCAFile newMCAFile(File file) {
|
||||
Matcher m = mcaFilePattern.matcher(file.getName());
|
||||
if (m.find()) {
|
||||
|
||||
@@ -89,6 +89,49 @@ public class NBTWorld {
|
||||
});
|
||||
}
|
||||
|
||||
public static BlockData getBlockData(CompoundTag tag) {
|
||||
if (tag == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
StringBuilder p = new StringBuilder(tag.getString("Name"));
|
||||
|
||||
if (tag.containsKey("Properties")) {
|
||||
CompoundTag props = tag.getCompoundTag("Properties");
|
||||
p.append('[');
|
||||
|
||||
for (String i : props.keySet()) {
|
||||
p.append(i).append('=').append(props.getString(i)).append(',');
|
||||
}
|
||||
|
||||
p.deleteCharAt(p.length() - 1).append(']');
|
||||
}
|
||||
|
||||
BlockData b = B.getOrNull(p.toString());
|
||||
|
||||
if (b == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public static CompoundTag getCompound(BlockData bd) {
|
||||
return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone();
|
||||
}
|
||||
|
||||
private static Map<Biome, Integer> computeBiomeIDs() {
|
||||
Map<Biome, Integer> biomeIds = new KMap<>();
|
||||
|
||||
for (Biome biome : Biome.values()) {
|
||||
if (!biome.name().equals("CUSTOM")) {
|
||||
biomeIds.put(biome, INMS.get().getBiomeId(biome));
|
||||
}
|
||||
}
|
||||
|
||||
return biomeIds;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
for (Long i : loadedRegions.k()) {
|
||||
@@ -184,37 +227,6 @@ public class NBTWorld {
|
||||
return new File(worldFolder, "region/r." + x + "." + z + ".mca");
|
||||
}
|
||||
|
||||
public static BlockData getBlockData(CompoundTag tag) {
|
||||
if (tag == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
StringBuilder p = new StringBuilder(tag.getString("Name"));
|
||||
|
||||
if (tag.containsKey("Properties")) {
|
||||
CompoundTag props = tag.getCompoundTag("Properties");
|
||||
p.append('[');
|
||||
|
||||
for (String i : props.keySet()) {
|
||||
p.append(i).append('=').append(props.getString(i)).append(',');
|
||||
}
|
||||
|
||||
p.deleteCharAt(p.length() - 1).append(']');
|
||||
}
|
||||
|
||||
BlockData b = B.getOrNull(p.toString());
|
||||
|
||||
if (b == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public static CompoundTag getCompound(BlockData bd) {
|
||||
return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone();
|
||||
}
|
||||
|
||||
public BlockData getBlockData(int x, int y, int z) {
|
||||
try {
|
||||
CompoundTag tag = getChunkSection(x >> 4, y >> 4, z >> 4).getBlockStateAt(x & 15, y & 15, z & 15);
|
||||
@@ -317,16 +329,4 @@ public class NBTWorld {
|
||||
public int size() {
|
||||
return loadedRegions.size();
|
||||
}
|
||||
|
||||
private static Map<Biome, Integer> computeBiomeIDs() {
|
||||
Map<Biome, Integer> biomeIds = new KMap<>();
|
||||
|
||||
for (Biome biome : Biome.values()) {
|
||||
if (!biome.name().equals("CUSTOM")) {
|
||||
biomeIds.put(biome, INMS.get().getBiomeId(biome));
|
||||
}
|
||||
}
|
||||
|
||||
return biomeIds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,18 @@ public class Section {
|
||||
Section() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty Section with base values.
|
||||
*
|
||||
* @return An empty Section
|
||||
*/
|
||||
public static Section newSection() {
|
||||
Section s = new Section();
|
||||
s.data = new CompoundTag();
|
||||
s.palette = INMS.get().createPalette();
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the data of this Section is empty.
|
||||
*
|
||||
@@ -141,18 +153,6 @@ public class Section {
|
||||
this.skyLight = skyLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty Section with base values.
|
||||
*
|
||||
* @return An empty Section
|
||||
*/
|
||||
public static Section newSection() {
|
||||
Section s = new Section();
|
||||
s.data = new CompoundTag();
|
||||
s.palette = INMS.get().createPalette();
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the raw CompoundTag that this Section is based on.
|
||||
* This must be called before saving a Section to disk if the Section was manually created
|
||||
|
||||
@@ -28,12 +28,9 @@ import java.util.List;
|
||||
|
||||
public class IdMapper<T> implements IdMap<T> {
|
||||
public static final int DEFAULT = -1;
|
||||
|
||||
private int nextId;
|
||||
|
||||
private final IdentityHashMap<T, Integer> tToId;
|
||||
|
||||
private final List<T> idToT;
|
||||
private int nextId;
|
||||
|
||||
public IdMapper(IdentityHashMap<T, Integer> tToId, List<T> idToT, int nextId) {
|
||||
this.tToId = tToId;
|
||||
|
||||
@@ -24,35 +24,34 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Mth {
|
||||
private static final int BIG_ENOUGH_INT = 1024;
|
||||
|
||||
private static final float BIG_ENOUGH_FLOAT = 1024.0F;
|
||||
|
||||
private static final long UUID_VERSION = 61440L;
|
||||
|
||||
private static final long UUID_VERSION_TYPE_4 = 16384L;
|
||||
|
||||
private static final long UUID_VARIANT = -4611686018427387904L;
|
||||
|
||||
private static final long UUID_VARIANT_2 = -9223372036854775808L;
|
||||
|
||||
public static final float PI = 3.1415927F;
|
||||
|
||||
public static final float HALF_PI = 1.5707964F;
|
||||
|
||||
public static final float TWO_PI = 6.2831855F;
|
||||
|
||||
public static final float DEG_TO_RAD = 0.017453292F;
|
||||
|
||||
public static final float RAD_TO_DEG = 57.295776F;
|
||||
|
||||
public static final float EPSILON = 1.0E-5F;
|
||||
|
||||
public static final float SQRT_OF_TWO = sqrt(2.0F);
|
||||
|
||||
private static final int BIG_ENOUGH_INT = 1024;
|
||||
private static final float BIG_ENOUGH_FLOAT = 1024.0F;
|
||||
private static final long UUID_VERSION = 61440L;
|
||||
private static final long UUID_VERSION_TYPE_4 = 16384L;
|
||||
private static final long UUID_VARIANT = -4611686018427387904L;
|
||||
private static final long UUID_VARIANT_2 = -9223372036854775808L;
|
||||
private static final float SIN_SCALE = 10430.378F;
|
||||
|
||||
private static final float[] SIN;
|
||||
private static final Random RANDOM = new Random();
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22,
|
||||
20, 15, 25, 17, 4, 8, 31, 27, 13, 23,
|
||||
21, 19, 16, 7, 26, 12, 18, 6, 11, 5,
|
||||
10, 9};
|
||||
private static final double ONE_SIXTH = 0.16666666666666666D;
|
||||
private static final int FRAC_EXP = 8;
|
||||
private static final int LUT_SIZE = 257;
|
||||
private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
|
||||
private static final double[] ASIN_TAB = new double[257];
|
||||
private static final double[] COS_TAB = new double[257];
|
||||
|
||||
static {
|
||||
SIN = make(new float[65536], var0 -> {
|
||||
@@ -61,6 +60,15 @@ public class Mth {
|
||||
});
|
||||
}
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; var0++) {
|
||||
double var1 = var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
COS_TAB[var0] = Math.cos(var3);
|
||||
ASIN_TAB[var0] = var3;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T make(Supplier<T> var0) {
|
||||
return var0.get();
|
||||
}
|
||||
@@ -70,8 +78,6 @@ public class Mth {
|
||||
return var0;
|
||||
}
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
public static float sin(float var0) {
|
||||
return SIN[(int) (var0 * 10430.378F) & 0xFFFF];
|
||||
}
|
||||
@@ -325,18 +331,6 @@ public class Mth {
|
||||
return (var0 != 0 && (var0 & var0 - 1) == 0);
|
||||
}
|
||||
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22,
|
||||
20, 15, 25, 17, 4, 8, 31, 27, 13, 23,
|
||||
21, 19, 16, 7, 26, 12, 18, 6, 11, 5,
|
||||
10, 9};
|
||||
|
||||
private static final double ONE_SIXTH = 0.16666666666666666D;
|
||||
|
||||
private static final int FRAC_EXP = 8;
|
||||
|
||||
private static final int LUT_SIZE = 257;
|
||||
|
||||
public static int ceillog2(int var0) {
|
||||
var0 = isPowerOfTwo(var0) ? var0 : smallestEncompassingPowerOfTwo(var0);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) (var0 * 125613361L >> 27L) & 0x1F];
|
||||
@@ -471,21 +465,6 @@ public class Mth {
|
||||
return var2;
|
||||
}
|
||||
|
||||
private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
|
||||
|
||||
private static final double[] ASIN_TAB = new double[257];
|
||||
|
||||
private static final double[] COS_TAB = new double[257];
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; var0++) {
|
||||
double var1 = var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
COS_TAB[var0] = Math.cos(var3);
|
||||
ASIN_TAB[var0] = var3;
|
||||
}
|
||||
}
|
||||
|
||||
public static int hsvToRgb(float var0, float var1, float var2) {
|
||||
float var8, var9, var10;
|
||||
int var11, var12, var13, var3 = (int) (var0 * 6.0F) % 6;
|
||||
|
||||
@@ -26,12 +26,9 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
private static final int SIZE = 4096;
|
||||
|
||||
public static final int GLOBAL_PALETTE_BITS = 9;
|
||||
|
||||
public static final int MIN_PALETTE_SIZE = 4;
|
||||
|
||||
private static final int SIZE = 4096;
|
||||
private final Palette<T> globalPalette;
|
||||
|
||||
private final PaletteResize<T> dummyPaletteResize = (var0, var1) -> 0;
|
||||
|
||||
@@ -21,7 +21,11 @@ package com.volmit.iris.util.nbt.tag;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@@ -33,15 +37,15 @@ public class CompoundTag extends Tag<Map<String, Tag<?>>> implements Iterable<Ma
|
||||
super(createEmptyValue());
|
||||
}
|
||||
|
||||
private static Map<String, Tag<?>> createEmptyValue() {
|
||||
return new KMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
private static Map<String, Tag<?>> createEmptyValue() {
|
||||
return new KMap<>();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return getValue().size();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,11 @@ package com.volmit.iris.util.nbt.tag;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -43,14 +47,17 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
|
||||
super(createEmptyValue(3));
|
||||
}
|
||||
|
||||
public ListTag<T> makeAtomic() {
|
||||
setValue(new CopyOnWriteArrayList<>(getValue()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getID() {
|
||||
return ID;
|
||||
/**
|
||||
* @param typeClass The exact class of the elements
|
||||
* @throws IllegalArgumentException When {@code typeClass} is {@link EndTag}{@code .class}
|
||||
* @throws NullPointerException When {@code typeClass} is {@code null}
|
||||
*/
|
||||
public ListTag(Class<? super T> typeClass) throws IllegalArgumentException, NullPointerException {
|
||||
super(createEmptyValue(3));
|
||||
if (typeClass == EndTag.class) {
|
||||
throw new IllegalArgumentException("cannot create ListTag with EndTag elements");
|
||||
}
|
||||
this.typeClass = Objects.requireNonNull(typeClass);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,17 +86,14 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
|
||||
return new KList<>(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param typeClass The exact class of the elements
|
||||
* @throws IllegalArgumentException When {@code typeClass} is {@link EndTag}{@code .class}
|
||||
* @throws NullPointerException When {@code typeClass} is {@code null}
|
||||
*/
|
||||
public ListTag(Class<? super T> typeClass) throws IllegalArgumentException, NullPointerException {
|
||||
super(createEmptyValue(3));
|
||||
if (typeClass == EndTag.class) {
|
||||
throw new IllegalArgumentException("cannot create ListTag with EndTag elements");
|
||||
}
|
||||
this.typeClass = Objects.requireNonNull(typeClass);
|
||||
public ListTag<T> makeAtomic() {
|
||||
setValue(new CopyOnWriteArrayList<>(getValue()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
|
||||
@@ -59,6 +59,8 @@ public abstract class Tag<T> implements Cloneable {
|
||||
public static final int DEFAULT_MAX_DEPTH = 512;
|
||||
|
||||
private static final Map<String, String> ESCAPE_CHARACTERS;
|
||||
private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
|
||||
private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
|
||||
|
||||
static {
|
||||
final Map<String, String> temp = new HashMap<>();
|
||||
@@ -71,9 +73,6 @@ public abstract class Tag<T> implements Cloneable {
|
||||
ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
|
||||
}
|
||||
|
||||
private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
|
||||
private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
|
||||
|
||||
private T value;
|
||||
|
||||
/**
|
||||
@@ -86,6 +85,30 @@ public abstract class Tag<T> implements Cloneable {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a string to fit into a JSON-like string representation for Minecraft
|
||||
* or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
|
||||
*
|
||||
* @param s The string to be escaped.
|
||||
* @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
|
||||
* the end of the string.
|
||||
* @return The escaped string.
|
||||
*/
|
||||
@SuppressWarnings("StringBufferMayBeStringBuilder")
|
||||
protected static String escapeString(String s, @SuppressWarnings("SameParameterValue") boolean lenient) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Matcher m = ESCAPE_PATTERN.matcher(s);
|
||||
while (m.find()) {
|
||||
m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
m = NON_QUOTE_PATTERN.matcher(s);
|
||||
if (!lenient || !m.matches()) {
|
||||
sb.insert(0, "\"").append("\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return This Tag's ID, usually used for serialization and deserialization.
|
||||
*/
|
||||
@@ -192,28 +215,4 @@ public abstract class Tag<T> implements Cloneable {
|
||||
* @return A clone of this Tag.
|
||||
*/
|
||||
public abstract Tag<T> clone();
|
||||
|
||||
/**
|
||||
* Escapes a string to fit into a JSON-like string representation for Minecraft
|
||||
* or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
|
||||
*
|
||||
* @param s The string to be escaped.
|
||||
* @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
|
||||
* the end of the string.
|
||||
* @return The escaped string.
|
||||
*/
|
||||
@SuppressWarnings("StringBufferMayBeStringBuilder")
|
||||
protected static String escapeString(String s, @SuppressWarnings("SameParameterValue") boolean lenient) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Matcher m = ESCAPE_PATTERN.matcher(s);
|
||||
while (m.find()) {
|
||||
m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
m = NON_QUOTE_PATTERN.matcher(s);
|
||||
if (!lenient || !m.matches()) {
|
||||
sb.insert(0, "\"").append("\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user