This commit is contained in:
cyberpwn
2022-01-12 01:47:38 -05:00
parent 8c00499e76
commit 2dde426df6
463 changed files with 11845 additions and 10159 deletions

View File

@@ -40,7 +40,7 @@ public class NBTDeserializer implements Deserializer<NamedTag> {
@Override
public NamedTag fromStream(InputStream stream) throws IOException {
NBTInputStream nbtIn;
if (compressed) {
if(compressed) {
nbtIn = new NBTInputStream(new GZIPInputStream(stream));
} else {
nbtIn = new NBTInputStream(stream);

View File

@@ -109,7 +109,7 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
int l = in.readInt();
int[] data = new int[l];
IntArrayTag iat = new IntArrayTag(data);
for (int i = 0; i < l; i++) {
for(int i = 0; i < l; i++) {
data[i] = in.readInt();
}
return iat;
@@ -119,7 +119,7 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
int l = in.readInt();
long[] data = new long[l];
LongArrayTag iat = new LongArrayTag(data);
for (int i = 0; i < l; i++) {
for(int i = 0; i < l; i++) {
data[i] = in.readLong();
}
return iat;
@@ -129,10 +129,10 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
byte listType = in.readByte();
ListTag<?> list = ListTag.createUnchecked(idClassMapping.get(listType));
int length = in.readInt();
if (length < 0) {
if(length < 0) {
length = 0;
}
for (int i = 0; i < length; i++) {
for(int i = 0; i < length; i++) {
list.addUnchecked(in.readTag(listType, in.decrementMaxDepth(maxDepth)));
}
return list;
@@ -140,7 +140,7 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
private static CompoundTag readCompound(NBTInputStream in, int maxDepth) throws IOException {
CompoundTag comp = new CompoundTag();
for (int id = in.readByte() & 0xFF; id != 0; id = in.readByte() & 0xFF) {
for(int id = in.readByte() & 0xFF; id != 0; id = in.readByte() & 0xFF) {
String key = in.readUTF();
Tag<?> element = in.readTag((byte) id, in.decrementMaxDepth(maxDepth));
comp.put(key, element);
@@ -160,7 +160,7 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
private Tag<?> readTag(byte type, int maxDepth) throws IOException {
ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> f;
if ((f = readers.get(type)) == null) {
if((f = readers.get(type)) == null) {
throw new IOException("invalid tag id \"" + type + "\"");
}
return f.accept(this, maxDepth);

View File

@@ -74,7 +74,7 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
static byte idFromClass(Class<?> clazz) {
Byte id = classIdMapping.get(clazz);
if (id == null) {
if(id == null) {
throw new IllegalArgumentException("unknown Tag class " + clazz.getName());
}
return id;
@@ -115,14 +115,14 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
private static void writeIntArray(NBTOutputStream out, Tag<?> tag) throws IOException {
out.writeInt(((IntArrayTag) tag).length());
for (int i : ((IntArrayTag) tag).getValue()) {
for(int i : ((IntArrayTag) tag).getValue()) {
out.writeInt(i);
}
}
private static void writeLongArray(NBTOutputStream out, Tag<?> tag) throws IOException {
out.writeInt(((LongArrayTag) tag).length());
for (long l : ((LongArrayTag) tag).getValue()) {
for(long l : ((LongArrayTag) tag).getValue()) {
out.writeLong(l);
}
}
@@ -130,14 +130,14 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
private static void writeList(NBTOutputStream out, Tag<?> tag, int maxDepth) throws IOException {
out.writeByte(idFromClass(((ListTag<?>) tag).getTypeClass()));
out.writeInt(((ListTag<?>) tag).size());
for (Tag<?> t : ((ListTag<?>) tag)) {
for(Tag<?> t : ((ListTag<?>) tag)) {
out.writeRawTag(t, out.decrementMaxDepth(maxDepth));
}
}
private static void writeCompound(NBTOutputStream out, Tag<?> tag, int maxDepth) throws IOException {
for (Map.Entry<String, Tag<?>> entry : (CompoundTag) tag) {
if (entry.getValue().getID() == 0) {
for(Map.Entry<String, Tag<?>> entry : (CompoundTag) tag) {
if(entry.getValue().getID() == 0) {
throw new IOException("end tag not allowed");
}
out.writeByte(entry.getValue().getID());
@@ -149,7 +149,7 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
public void writeTag(NamedTag tag, int maxDepth) throws IOException {
writeByte(tag.getTag().getID());
if (tag.getTag().getID() != 0) {
if(tag.getTag().getID() != 0) {
writeUTF(tag.getName() == null ? "" : tag.getName());
}
writeRawTag(tag.getTag(), maxDepth);
@@ -157,7 +157,7 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
public void writeTag(Tag<?> tag, int maxDepth) throws IOException {
writeByte(tag.getID());
if (tag.getID() != 0) {
if(tag.getID() != 0) {
writeUTF("");
}
writeRawTag(tag, maxDepth);
@@ -165,7 +165,7 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
public void writeRawTag(Tag<?> tag, int maxDepth) throws IOException {
ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f;
if ((f = writers.get(tag.getID())) == null) {
if((f = writers.get(tag.getID())) == null) {
throw new IOException("invalid tag \"" + tag.getID() + "\"");
}
f.accept(this, tag, maxDepth);

View File

@@ -40,7 +40,7 @@ public class NBTSerializer implements Serializer<NamedTag> {
@Override
public void toStream(NamedTag object, OutputStream out) throws IOException {
NBTOutputStream nbtOut;
if (compressed) {
if(compressed) {
nbtOut = new NBTOutputStream(new GZIPOutputStream(out, true));
} else {
nbtOut = new NBTOutputStream(out);

View File

@@ -35,7 +35,7 @@ public final class NBTUtil {
}
public static void write(NamedTag tag, File file, boolean compressed) throws IOException {
try (FileOutputStream fos = new FileOutputStream(file)) {
try(FileOutputStream fos = new FileOutputStream(file)) {
new NBTSerializer(compressed).toStream(tag, fos);
}
}
@@ -77,7 +77,7 @@ public final class NBTUtil {
}
public static NamedTag read(File file, boolean compressed) throws IOException {
try (FileInputStream fis = new FileInputStream(file)) {
try(FileInputStream fis = new FileInputStream(file)) {
return new NBTDeserializer(compressed).fromStream(fis);
}
}
@@ -91,7 +91,7 @@ public final class NBTUtil {
}
public static NamedTag read(File file) throws IOException {
try (FileInputStream fis = new FileInputStream(file)) {
try(FileInputStream fis = new FileInputStream(file)) {
return new NBTDeserializer(false).fromStream(detectDecompression(fis));
}
}
@@ -105,7 +105,7 @@ public final class NBTUtil {
int signature = (pbis.read() & 0xFF) + (pbis.read() << 8);
pbis.unread(signature >> 8);
pbis.unread(signature & 0xFF);
if (signature == GZIPInputStream.GZIP_MAGIC) {
if(signature == GZIPInputStream.GZIP_MAGIC) {
return new GZIPInputStream(pbis);
}
return pbis;

View File

@@ -33,7 +33,7 @@ public class ParseException extends IOException {
private static String formatError(String value, int index) {
StringBuilder builder = new StringBuilder();
int i = Math.min(value.length(), index);
if (i > 35) {
if(i > 35) {
builder.append("...");
}
builder.append(value, Math.max(0, i - 35), i);

View File

@@ -35,7 +35,7 @@ public class SNBTDeserializer implements StringDeserializer<Tag<?>> {
public Tag<?> fromReader(Reader reader, int maxDepth) throws IOException {
BufferedReader bufferedReader;
if (reader instanceof BufferedReader) {
if(reader instanceof BufferedReader) {
bufferedReader = (BufferedReader) reader;
} else {
bufferedReader = new BufferedReader(reader);

View File

@@ -43,14 +43,14 @@ import java.util.regex.Pattern;
public final class SNBTParser implements MaxDepthIO {
private static final Pattern
FLOAT_LITERAL_PATTERN = Pattern.compile("^[-+]?(?:\\d+\\.?|\\d*\\.\\d+)(?:e[-+]?\\d+)?f$", Pattern.CASE_INSENSITIVE),
DOUBLE_LITERAL_PATTERN = Pattern.compile("^[-+]?(?:\\d+\\.?|\\d*\\.\\d+)(?:e[-+]?\\d+)?d$", Pattern.CASE_INSENSITIVE),
DOUBLE_LITERAL_NO_SUFFIX_PATTERN = Pattern.compile("^[-+]?(?:\\d+\\.|\\d*\\.\\d+)(?:e[-+]?\\d+)?$", Pattern.CASE_INSENSITIVE),
BYTE_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+b$", Pattern.CASE_INSENSITIVE),
SHORT_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+s$", Pattern.CASE_INSENSITIVE),
INT_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+$", Pattern.CASE_INSENSITIVE),
LONG_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+l$", Pattern.CASE_INSENSITIVE),
NUMBER_PATTERN = Pattern.compile("^[-+]?\\d+$");
FLOAT_LITERAL_PATTERN = Pattern.compile("^[-+]?(?:\\d+\\.?|\\d*\\.\\d+)(?:e[-+]?\\d+)?f$", Pattern.CASE_INSENSITIVE),
DOUBLE_LITERAL_PATTERN = Pattern.compile("^[-+]?(?:\\d+\\.?|\\d*\\.\\d+)(?:e[-+]?\\d+)?d$", Pattern.CASE_INSENSITIVE),
DOUBLE_LITERAL_NO_SUFFIX_PATTERN = Pattern.compile("^[-+]?(?:\\d+\\.|\\d*\\.\\d+)(?:e[-+]?\\d+)?$", Pattern.CASE_INSENSITIVE),
BYTE_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+b$", Pattern.CASE_INSENSITIVE),
SHORT_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+s$", Pattern.CASE_INSENSITIVE),
INT_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+$", Pattern.CASE_INSENSITIVE),
LONG_LITERAL_PATTERN = Pattern.compile("^[-+]?\\d+l$", Pattern.CASE_INSENSITIVE),
NUMBER_PATTERN = Pattern.compile("^[-+]?\\d+$");
private final StringPointer ptr;
@@ -62,7 +62,7 @@ public final class SNBTParser implements MaxDepthIO {
SNBTParser parser = new SNBTParser(string);
Tag<?> tag = parser.parseAnything(maxDepth);
parser.ptr.skipWhitespace();
if (parser.ptr.hasNext()) {
if(parser.ptr.hasNext()) {
throw parser.ptr.parseException("invalid characters after end of snbt");
}
return tag;
@@ -74,11 +74,11 @@ public final class SNBTParser implements MaxDepthIO {
private Tag<?> parseAnything(int maxDepth) throws ParseException {
ptr.skipWhitespace();
switch (ptr.currentChar()) {
switch(ptr.currentChar()) {
case '{':
return parseCompoundTag(maxDepth);
case '[':
if (ptr.hasCharsLeft(2) && ptr.lookAhead(1) != '"' && ptr.lookAhead(2) == ';') {
if(ptr.hasCharsLeft(2) && ptr.lookAhead(1) != '"' && ptr.lookAhead(2) == ';') {
return parseNumArray();
}
return parseListTag(maxDepth);
@@ -88,50 +88,50 @@ public final class SNBTParser implements MaxDepthIO {
private Tag<?> parseStringOrLiteral() throws ParseException {
ptr.skipWhitespace();
if (ptr.currentChar() == '"') {
if(ptr.currentChar() == '"') {
return new StringTag(ptr.parseQuotedString());
}
String s = ptr.parseSimpleString();
if (s.isEmpty()) {
if(s.isEmpty()) {
throw new ParseException("expected non empty value");
}
if (FLOAT_LITERAL_PATTERN.matcher(s).matches()) {
if(FLOAT_LITERAL_PATTERN.matcher(s).matches()) {
return new FloatTag(Float.parseFloat(s.substring(0, s.length() - 1)));
} else if (BYTE_LITERAL_PATTERN.matcher(s).matches()) {
} else if(BYTE_LITERAL_PATTERN.matcher(s).matches()) {
try {
return new ByteTag(Byte.parseByte(s.substring(0, s.length() - 1)));
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
Iris.reportError(ex);
throw ptr.parseException("byte not in range: \"" + s.substring(0, s.length() - 1) + "\"");
}
} else if (SHORT_LITERAL_PATTERN.matcher(s).matches()) {
} else if(SHORT_LITERAL_PATTERN.matcher(s).matches()) {
try {
return new ShortTag(Short.parseShort(s.substring(0, s.length() - 1)));
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
Iris.reportError(ex);
throw ptr.parseException("short not in range: \"" + s.substring(0, s.length() - 1) + "\"");
}
} else if (LONG_LITERAL_PATTERN.matcher(s).matches()) {
} else if(LONG_LITERAL_PATTERN.matcher(s).matches()) {
try {
return new LongTag(Long.parseLong(s.substring(0, s.length() - 1)));
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
Iris.reportError(ex);
throw ptr.parseException("long not in range: \"" + s.substring(0, s.length() - 1) + "\"");
}
} else if (INT_LITERAL_PATTERN.matcher(s).matches()) {
} else if(INT_LITERAL_PATTERN.matcher(s).matches()) {
try {
return new IntTag(Integer.parseInt(s));
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
Iris.reportError(ex);
throw ptr.parseException("int not in range: \"" + s.substring(0, s.length() - 1) + "\"");
}
} else if (DOUBLE_LITERAL_PATTERN.matcher(s).matches()) {
} else if(DOUBLE_LITERAL_PATTERN.matcher(s).matches()) {
return new DoubleTag(Double.parseDouble(s.substring(0, s.length() - 1)));
} else if (DOUBLE_LITERAL_NO_SUFFIX_PATTERN.matcher(s).matches()) {
} else if(DOUBLE_LITERAL_NO_SUFFIX_PATTERN.matcher(s).matches()) {
return new DoubleTag(Double.parseDouble(s));
} else if ("true".equalsIgnoreCase(s)) {
} else if("true".equalsIgnoreCase(s)) {
return new ByteTag(true);
} else if ("false".equalsIgnoreCase(s)) {
} else if("false".equalsIgnoreCase(s)) {
return new ByteTag(false);
}
return new StringTag(s);
@@ -143,17 +143,17 @@ public final class SNBTParser implements MaxDepthIO {
CompoundTag compoundTag = new CompoundTag();
ptr.skipWhitespace();
while (ptr.hasNext() && ptr.currentChar() != '}') {
while(ptr.hasNext() && ptr.currentChar() != '}') {
ptr.skipWhitespace();
String key = ptr.currentChar() == '"' ? ptr.parseQuotedString() : ptr.parseSimpleString();
if (key.isEmpty()) {
if(key.isEmpty()) {
throw new ParseException("empty keys are not allowed");
}
ptr.expectChar(':');
compoundTag.put(key, parseAnything(decrementMaxDepth(maxDepth)));
if (!ptr.nextArrayElement()) {
if(!ptr.nextArrayElement()) {
break;
}
}
@@ -165,15 +165,15 @@ public final class SNBTParser implements MaxDepthIO {
ptr.expectChar('[');
ptr.skipWhitespace();
ListTag<?> list = ListTag.createUnchecked(EndTag.class);
while (ptr.currentChar() != ']') {
while(ptr.currentChar() != ']') {
Tag<?> element = parseAnything(decrementMaxDepth(maxDepth));
try {
list.addUnchecked(element);
} catch (IllegalArgumentException ex) {
} catch(IllegalArgumentException ex) {
Iris.reportError(ex);
throw ptr.parseException(ex.getMessage());
}
if (!ptr.nextArrayElement()) {
if(!ptr.nextArrayElement()) {
break;
}
}
@@ -186,7 +186,7 @@ public final class SNBTParser implements MaxDepthIO {
char arrayType = ptr.next();
ptr.expectChar(';');
ptr.skipWhitespace();
switch (arrayType) {
switch(arrayType) {
case 'B':
return parseByteArrayTag();
case 'I':
@@ -199,26 +199,26 @@ public final class SNBTParser implements MaxDepthIO {
private ByteArrayTag parseByteArrayTag() throws ParseException {
List<Byte> byteList = new ArrayList<>();
while (ptr.currentChar() != ']') {
while(ptr.currentChar() != ']') {
String s = ptr.parseSimpleString();
ptr.skipWhitespace();
if (NUMBER_PATTERN.matcher(s).matches()) {
if(NUMBER_PATTERN.matcher(s).matches()) {
try {
byteList.add(Byte.parseByte(s));
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
Iris.reportError(ex);
throw ptr.parseException("byte not in range: \"" + s + "\"");
}
} else {
throw ptr.parseException("invalid byte in ByteArrayTag: \"" + s + "\"");
}
if (!ptr.nextArrayElement()) {
if(!ptr.nextArrayElement()) {
break;
}
}
ptr.expectChar(']');
byte[] bytes = new byte[byteList.size()];
for (int i = 0; i < byteList.size(); i++) {
for(int i = 0; i < byteList.size(); i++) {
bytes[i] = byteList.get(i);
}
return new ByteArrayTag(bytes);
@@ -226,20 +226,20 @@ public final class SNBTParser implements MaxDepthIO {
private IntArrayTag parseIntArrayTag() throws ParseException {
List<Integer> intList = new ArrayList<>();
while (ptr.currentChar() != ']') {
while(ptr.currentChar() != ']') {
String s = ptr.parseSimpleString();
ptr.skipWhitespace();
if (NUMBER_PATTERN.matcher(s).matches()) {
if(NUMBER_PATTERN.matcher(s).matches()) {
try {
intList.add(Integer.parseInt(s));
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
Iris.reportError(ex);
throw ptr.parseException("int not in range: \"" + s + "\"");
}
} else {
throw ptr.parseException("invalid int in IntArrayTag: \"" + s + "\"");
}
if (!ptr.nextArrayElement()) {
if(!ptr.nextArrayElement()) {
break;
}
}
@@ -249,20 +249,20 @@ public final class SNBTParser implements MaxDepthIO {
private LongArrayTag parseLongArrayTag() throws ParseException {
List<Long> longList = new ArrayList<>();
while (ptr.currentChar() != ']') {
while(ptr.currentChar() != ']') {
String s = ptr.parseSimpleString();
ptr.skipWhitespace();
if (NUMBER_PATTERN.matcher(s).matches()) {
if(NUMBER_PATTERN.matcher(s).matches()) {
try {
longList.add(Long.parseLong(s));
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
Iris.reportError(ex);
throw ptr.parseException("long not in range: \"" + s + "\"");
}
} else {
throw ptr.parseException("invalid long in LongArrayTag: \"" + s + "\"");
}
if (!ptr.nextArrayElement()) {
if(!ptr.nextArrayElement()) {
break;
}
}

View File

@@ -63,12 +63,12 @@ public final class SNBTWriter implements MaxDepthIO {
}
public static String escapeString(String s) {
if (!NON_QUOTE_PATTERN.matcher(s).matches()) {
if(!NON_QUOTE_PATTERN.matcher(s).matches()) {
StringBuilder sb = new StringBuilder();
sb.append('"');
for (int i = 0; i < s.length(); i++) {
for(int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '\\' || c == '"') {
if(c == '\\' || c == '"') {
sb.append('\\');
}
sb.append(c);
@@ -80,7 +80,7 @@ public final class SNBTWriter implements MaxDepthIO {
}
private void writeAnything(Tag<?> tag, int maxDepth) throws IOException {
switch (tag.getID()) {
switch(tag.getID()) {
case EndTag.ID:
//do nothing
break;
@@ -110,7 +110,7 @@ public final class SNBTWriter implements MaxDepthIO {
break;
case ListTag.ID:
writer.write('[');
for (int i = 0; i < ((ListTag<?>) tag).size(); i++) {
for(int i = 0; i < ((ListTag<?>) tag).size(); i++) {
writer.write(i == 0 ? "" : ",");
writeAnything(((ListTag<?>) tag).get(i), decrementMaxDepth(maxDepth));
}
@@ -119,7 +119,7 @@ public final class SNBTWriter implements MaxDepthIO {
case CompoundTag.ID:
writer.write('{');
boolean first = true;
for (Map.Entry<String, Tag<?>> entry : (CompoundTag) tag) {
for(Map.Entry<String, Tag<?>> entry : (CompoundTag) tag) {
writer.write(first ? "" : ",");
writer.append(escapeString(entry.getKey())).write(':');
writeAnything(entry.getValue(), decrementMaxDepth(maxDepth));
@@ -140,7 +140,7 @@ public final class SNBTWriter implements MaxDepthIO {
private void writeArray(Object array, int length, String prefix) throws IOException {
writer.append('[').append(prefix).write(';');
for (int i = 0; i < length; i++) {
for(int i = 0; i < length; i++) {
writer.append(i == 0 ? "" : ",").write(Array.get(array, i).toString());
}
writer.write(']');

View File

@@ -29,17 +29,17 @@ public class StringPointer {
private static boolean isSimpleChar(char c) {
return c >= 'a' && c <= 'z'
|| c >= 'A' && c <= 'Z'
|| c >= '0' && c <= '9'
|| c == '-'
|| c == '+'
|| c == '.'
|| c == '_';
|| c >= 'A' && c <= 'Z'
|| c >= '0' && c <= '9'
|| c == '-'
|| c == '+'
|| c == '.'
|| c == '_';
}
public String parseSimpleString() {
int oldIndex = index;
while (hasNext() && isSimpleChar(currentChar())) {
while(hasNext() && isSimpleChar(currentChar())) {
index++;
}
return value.substring(oldIndex, index);
@@ -49,27 +49,27 @@ public class StringPointer {
int oldIndex = ++index; //ignore beginning quotes
StringBuilder sb = null;
boolean escape = false;
while (hasNext()) {
while(hasNext()) {
char c = next();
if (escape) {
if (c != '\\' && c != '"') {
if(escape) {
if(c != '\\' && c != '"') {
throw parseException("invalid escape of '" + c + "'");
}
escape = false;
} else {
if (c == '\\') { //escape
if(c == '\\') { //escape
escape = true;
if (sb != null) {
if(sb != null) {
continue;
}
sb = new StringBuilder(value.substring(oldIndex, index - 1));
continue;
}
if (c == '"') {
if(c == '"') {
return sb == null ? value.substring(oldIndex, index - 1) : sb.toString();
}
}
if (sb != null) {
if(sb != null) {
sb.append(c);
}
}
@@ -79,7 +79,7 @@ public class StringPointer {
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean nextArrayElement() {
skipWhitespace();
if (hasNext() && currentChar() == ',') {
if(hasNext() && currentChar() == ',') {
index++;
skipWhitespace();
return true;
@@ -90,7 +90,7 @@ public class StringPointer {
public void expectChar(char c) throws ParseException {
skipWhitespace();
boolean hasNext = hasNext();
if (hasNext && currentChar() == c) {
if(hasNext && currentChar() == c) {
index++;
return;
}
@@ -98,7 +98,7 @@ public class StringPointer {
}
public void skipWhitespace() {
while (hasNext() && Character.isWhitespace(currentChar())) {
while(hasNext() && Character.isWhitespace(currentChar())) {
index++;
}
}

View File

@@ -67,7 +67,8 @@ public class Chunk {
/**
* Create a new chunk based on raw base data from a region file.
*
* @param data The raw base data to be used.
* @param data
* The raw base data to be used.
*/
public Chunk(CompoundTag data) {
this.data = data;
@@ -93,61 +94,61 @@ public class Chunk {
}
private void initReferences(long loadFlags) {
if (data == null) {
if(data == null) {
throw new NullPointerException("data cannot be null");
}
CompoundTag level;
if ((level = data.getCompoundTag("Level")) == null) {
if((level = data.getCompoundTag("Level")) == null) {
throw new IllegalArgumentException("data does not contain \"Level\" tag");
}
dataVersion = data.getInt("DataVersion");
inhabitedTime = level.getLong("InhabitedTime");
lastUpdate = level.getLong("LastUpdate");
if ((loadFlags & BIOMES) != 0) {
if((loadFlags & BIOMES) != 0) {
biomes = INMS.get().newBiomeContainer(0, 256, level.getIntArray("Biomes"));
}
if ((loadFlags & HEIGHTMAPS) != 0) {
if((loadFlags & HEIGHTMAPS) != 0) {
heightMaps = level.getCompoundTag("Heightmaps");
}
if ((loadFlags & CARVING_MASKS) != 0) {
if((loadFlags & CARVING_MASKS) != 0) {
carvingMasks = level.getCompoundTag("CarvingMasks");
}
if ((loadFlags & ENTITIES) != 0) {
if((loadFlags & ENTITIES) != 0) {
entities = level.containsKey("Entities") ? level.getListTag("Entities").asCompoundTagList() : null;
}
if ((loadFlags & TILE_ENTITIES) != 0) {
if((loadFlags & TILE_ENTITIES) != 0) {
tileEntities = level.containsKey("TileEntities") ? level.getListTag("TileEntities").asCompoundTagList() : null;
}
if ((loadFlags & TILE_TICKS) != 0) {
if((loadFlags & TILE_TICKS) != 0) {
tileTicks = level.containsKey("TileTicks") ? level.getListTag("TileTicks").asCompoundTagList() : null;
}
if ((loadFlags & LIQUID_TICKS) != 0) {
if((loadFlags & LIQUID_TICKS) != 0) {
liquidTicks = level.containsKey("LiquidTicks") ? level.getListTag("LiquidTicks").asCompoundTagList() : null;
}
if ((loadFlags & LIGHTS) != 0) {
if((loadFlags & LIGHTS) != 0) {
lights = level.containsKey("Lights") ? level.getListTag("Lights").asListTagList() : null;
}
if ((loadFlags & LIQUIDS_TO_BE_TICKED) != 0) {
if((loadFlags & LIQUIDS_TO_BE_TICKED) != 0) {
liquidsToBeTicked = level.containsKey("LiquidsToBeTicked") ? level.getListTag("LiquidsToBeTicked").asListTagList() : null;
}
if ((loadFlags & TO_BE_TICKED) != 0) {
if((loadFlags & TO_BE_TICKED) != 0) {
toBeTicked = level.containsKey("ToBeTicked") ? level.getListTag("ToBeTicked").asListTagList() : null;
}
if ((loadFlags & POST_PROCESSING) != 0) {
if((loadFlags & POST_PROCESSING) != 0) {
postProcessing = level.containsKey("PostProcessing") ? level.getListTag("PostProcessing").asListTagList() : null;
}
status = level.getString("Status");
if ((loadFlags & STRUCTURES) != 0) {
if((loadFlags & STRUCTURES) != 0) {
structures = level.getCompoundTag("Structures");
}
if ((loadFlags & (BLOCK_LIGHTS | BLOCK_STATES | SKY_LIGHT)) != 0 && level.containsKey("Sections")) {
for (CompoundTag section : level.getListTag("Sections").asCompoundTagList()) {
if((loadFlags & (BLOCK_LIGHTS | BLOCK_STATES | SKY_LIGHT)) != 0 && level.containsKey("Sections")) {
for(CompoundTag section : level.getListTag("Sections").asCompoundTagList()) {
int sectionIndex = section.getByte("Y");
if (sectionIndex > 15 || sectionIndex < 0) {
if(sectionIndex > 15 || sectionIndex < 0) {
continue;
}
Section newSection = new Section(section, dataVersion, loadFlags);
if (newSection.isEmpty()) {
if(newSection.isEmpty()) {
continue;
}
sections.set(sectionIndex, newSection);
@@ -155,7 +156,7 @@ public class Chunk {
}
// If we haven't requested the full set of data we can drop the underlying raw data to let the GC handle it.
if (loadFlags != ALL_DATA) {
if(loadFlags != ALL_DATA) {
data = null;
partial = true;
} else {
@@ -166,19 +167,24 @@ public class Chunk {
/**
* Serializes this chunk to a <code>RandomAccessFile</code>.
*
* @param raf The RandomAccessFile to be written to.
* @param xPos The x-coordinate of the chunk.
* @param zPos The z-coodrinate of the chunk.
* @param raf
* The RandomAccessFile to be written to.
* @param xPos
* The x-coordinate of the chunk.
* @param zPos
* The z-coodrinate of the chunk.
* @return The amount of bytes written to the RandomAccessFile.
* @throws UnsupportedOperationException When something went wrong during writing.
* @throws IOException When something went wrong during writing.
* @throws UnsupportedOperationException
* When something went wrong during writing.
* @throws IOException
* When something went wrong during writing.
*/
public int serialize(RandomAccessFile raf, int xPos, int zPos) throws IOException {
if (partial) {
if(partial) {
throw new UnsupportedOperationException("Partially loaded chunks cannot be serialized");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
try (BufferedOutputStream nbtOut = new BufferedOutputStream(CompressionType.ZLIB.compress(baos))) {
try(BufferedOutputStream nbtOut = new BufferedOutputStream(CompressionType.ZLIB.compress(baos))) {
new NBTSerializer(false).toStream(new NamedTag(null, updateHandle(xPos, zPos)), nbtOut);
}
@@ -192,8 +198,10 @@ public class Chunk {
/**
* Reads chunk data from a RandomAccessFile. The RandomAccessFile must already be at the correct position.
*
* @param raf The RandomAccessFile to read the chunk data from.
* @throws IOException When something went wrong during reading.
* @param raf
* The RandomAccessFile to read the chunk data from.
* @throws IOException
* When something went wrong during reading.
*/
public void deserialize(RandomAccessFile raf) throws IOException {
deserialize(raf, ALL_DATA);
@@ -202,19 +210,22 @@ public class Chunk {
/**
* Reads chunk data from a RandomAccessFile. The RandomAccessFile must already be at the correct position.
*
* @param raf The RandomAccessFile to read the chunk data from.
* @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @throws IOException When something went wrong during reading.
* @param raf
* The RandomAccessFile to read the chunk data from.
* @param loadFlags
* A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @throws IOException
* When something went wrong during reading.
*/
public void deserialize(RandomAccessFile raf, long loadFlags) throws IOException {
byte compressionTypeByte = raf.readByte();
CompressionType compressionType = CompressionType.getFromID(compressionTypeByte);
if (compressionType == null) {
if(compressionType == null) {
throw new IOException("invalid compression type " + compressionTypeByte);
}
BufferedInputStream dis = new BufferedInputStream(compressionType.decompress(new FileInputStream(raf.getFD())));
NamedTag tag = new NBTDeserializer(false).fromStream(dis);
if (tag != null && tag.getTag() instanceof CompoundTag) {
if(tag != null && tag.getTag() instanceof CompoundTag) {
data = (CompoundTag) tag.getTag();
initReferences(loadFlags);
} else {
@@ -226,9 +237,12 @@ public class Chunk {
* Fetches a biome id at a specific block in this chunk.
* The coordinates can be absolute coordinates or relative to the region or chunk.
*
* @param blockX The x-coordinate of the block.
* @param blockY The y-coordinate of the block.
* @param blockZ The z-coordinate of the block.
* @param blockX
* The x-coordinate of the block.
* @param blockY
* The y-coordinate of the block.
* @param blockZ
* The z-coordinate of the block.
* @return The biome id or -1 if the biomes are not correctly initialized.
*/
public synchronized int getBiomeAt(int blockX, int blockY, int blockZ) {
@@ -239,10 +253,13 @@ public class Chunk {
* Sets a biome id at a specific block column.
* The coordinates can be absolute coordinates or relative to the region or chunk.
*
* @param blockX The x-coordinate of the block column.
* @param blockZ The z-coordinate of the block column.
* @param biomeID The biome id to be set.
* When set to a negative number, Minecraft will replace it with the block column's default biome.
* @param blockX
* The x-coordinate of the block column.
* @param blockZ
* The z-coordinate of the block column.
* @param biomeID
* The biome id to be set.
* When set to a negative number, Minecraft will replace it with the block column's default biome.
*/
public synchronized void setBiomeAt(int blockX, int blockY, int blockZ, int biomeID) {
biomes.setBiome(blockX, blockY, blockZ, biomeID);
@@ -255,12 +272,12 @@ public class Chunk {
public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
int s = MCAUtil.blockToChunk(blockY);
if (sections.length() <= s) {
if(sections.length() <= s) {
return null;
}
Section section = sections.get(s);
if (section == null) {
if(section == null) {
return null;
}
return section.getBlockStateAt(blockX, blockY, blockZ);
@@ -270,23 +287,28 @@ public class Chunk {
* Sets a block state at a specific location.
* The block coordinates can be absolute or relative to the region or chunk.
*
* @param blockX The x-coordinate of the block.
* @param blockY The y-coordinate of the block.
* @param blockZ The z-coordinate of the block.
* @param state The block state to be set.
* @param cleanup When <code>true</code>, it will cleanup all palettes of this chunk.
* This option should only be used moderately to avoid unnecessary recalculation of the palette indices.
* Recalculating the Palette should only be executed once right before saving the Chunk to file.
* @param blockX
* The x-coordinate of the block.
* @param blockY
* The y-coordinate of the block.
* @param blockZ
* The z-coordinate of the block.
* @param state
* The block state to be set.
* @param cleanup
* When <code>true</code>, it will cleanup all palettes of this chunk.
* This option should only be used moderately to avoid unnecessary recalculation of the palette indices.
* Recalculating the Palette should only be executed once right before saving the Chunk to file.
*/
public void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
int sectionIndex = MCAUtil.blockToChunk(blockY);
if (sections.length() <= sectionIndex) {
if(sections.length() <= sectionIndex) {
return;
}
Section section = sections.get(sectionIndex);
if (section == null) {
if(section == null) {
section = Section.newSection();
sections.set(sectionIndex, section);
}
@@ -304,7 +326,8 @@ public class Chunk {
* Sets the DataVersion of this chunk. This does not check if the data of this chunk conforms
* to that DataVersion, that is the responsibility of the developer.
*
* @param dataVersion The DataVersion to be set.
* @param dataVersion
* The DataVersion to be set.
*/
public void setDataVersion(int dataVersion) {
this.dataVersion = dataVersion;
@@ -320,7 +343,8 @@ public class Chunk {
/**
* Sets the timestamp when this region file was last updated in seconds since 1970-01-01.
*
* @param lastMCAUpdate The time in seconds since 1970-01-01.
* @param lastMCAUpdate
* The time in seconds since 1970-01-01.
*/
public void setLastMCAUpdate(int lastMCAUpdate) {
this.lastMCAUpdate = lastMCAUpdate;
@@ -336,7 +360,8 @@ public class Chunk {
/**
* Sets the generation status of this chunk.
*
* @param status The generation status of this chunk.
* @param status
* The generation status of this chunk.
*/
public void setStatus(String status) {
this.status = status;
@@ -345,7 +370,8 @@ public class Chunk {
/**
* Fetches the section at the given y-coordinate.
*
* @param sectionY The y-coordinate of the section in this chunk ranging from 0 to 15.
* @param sectionY
* The y-coordinate of the section in this chunk ranging from 0 to 15.
* @return The Section.
*/
public Section getSection(int sectionY) {
@@ -355,8 +381,10 @@ public class Chunk {
/**
* Sets a section at a givesn y-coordinate
*
* @param sectionY The y-coordinate of the section in this chunk ranging from 0 to 15.
* @param section The section to be set.
* @param sectionY
* The y-coordinate of the section in this chunk ranging from 0 to 15.
* @param section
* The section to be set.
*/
public void setSection(int sectionY, Section section) {
sections.set(sectionY, section);
@@ -372,7 +400,8 @@ public class Chunk {
/**
* Sets the time when this chunk was last updated as a UNIX timestamp.
*
* @param lastUpdate The UNIX timestamp.
* @param lastUpdate
* The UNIX timestamp.
*/
public void setLastUpdate(long lastUpdate) {
this.lastUpdate = lastUpdate;
@@ -388,7 +417,8 @@ public class Chunk {
/**
* Sets the cumulative amount of time players have spent in this chunk in ticks.
*
* @param inhabitedTime The time in ticks.
* @param inhabitedTime
* The time in ticks.
*/
public void setInhabitedTime(long inhabitedTime) {
this.inhabitedTime = inhabitedTime;
@@ -404,7 +434,8 @@ public class Chunk {
/**
* Sets the height maps of this chunk.
*
* @param heightMaps The height maps.
* @param heightMaps
* The height maps.
*/
public void setHeightMaps(CompoundTag heightMaps) {
this.heightMaps = heightMaps;
@@ -420,7 +451,8 @@ public class Chunk {
/**
* Sets the carving masks of this chunk.
*
* @param carvingMasks The carving masks.
* @param carvingMasks
* The carving masks.
*/
public void setCarvingMasks(CompoundTag carvingMasks) {
this.carvingMasks = carvingMasks;
@@ -436,7 +468,8 @@ public class Chunk {
/**
* Sets the entities of this chunk.
*
* @param entities The entities.
* @param entities
* The entities.
*/
public void setEntities(ListTag<CompoundTag> entities) {
this.entities = entities;
@@ -452,7 +485,8 @@ public class Chunk {
/**
* Sets the tile entities of this chunk.
*
* @param tileEntities The tile entities of this chunk.
* @param tileEntities
* The tile entities of this chunk.
*/
public void setTileEntities(ListTag<CompoundTag> tileEntities) {
this.tileEntities = tileEntities;
@@ -468,7 +502,8 @@ public class Chunk {
/**
* Sets the tile ticks of this chunk.
*
* @param tileTicks Thee tile ticks.
* @param tileTicks
* Thee tile ticks.
*/
public void setTileTicks(ListTag<CompoundTag> tileTicks) {
this.tileTicks = tileTicks;
@@ -484,7 +519,8 @@ public class Chunk {
/**
* Sets the liquid ticks of this chunk.
*
* @param liquidTicks The liquid ticks.
* @param liquidTicks
* The liquid ticks.
*/
public void setLiquidTicks(ListTag<CompoundTag> liquidTicks) {
this.liquidTicks = liquidTicks;
@@ -500,7 +536,8 @@ public class Chunk {
/**
* Sets the light sources in this chunk.
*
* @param lights The light sources.
* @param lights
* The light sources.
*/
public void setLights(ListTag<ListTag<?>> lights) {
this.lights = lights;
@@ -516,7 +553,8 @@ public class Chunk {
/**
* Sets the liquids to be ticked in this chunk.
*
* @param liquidsToBeTicked The liquids to be ticked.
* @param liquidsToBeTicked
* The liquids to be ticked.
*/
public void setLiquidsToBeTicked(ListTag<ListTag<?>> liquidsToBeTicked) {
this.liquidsToBeTicked = liquidsToBeTicked;
@@ -532,7 +570,8 @@ public class Chunk {
/**
* Sets stuff to be ticked in this chunk.
*
* @param toBeTicked The stuff to be ticked.
* @param toBeTicked
* The stuff to be ticked.
*/
public void setToBeTicked(ListTag<ListTag<?>> toBeTicked) {
this.toBeTicked = toBeTicked;
@@ -548,7 +587,8 @@ public class Chunk {
/**
* Sets things to be post processed in this chunk.
*
* @param postProcessing The things to be post processed.
* @param postProcessing
* The things to be post processed.
*/
public void setPostProcessing(ListTag<ListTag<?>> postProcessing) {
this.postProcessing = postProcessing;
@@ -564,7 +604,8 @@ public class Chunk {
/**
* Sets data about structures in this chunk.
*
* @param structures The data about structures.
* @param structures
* The data about structures.
*/
public void setStructures(CompoundTag structures) {
this.structures = structures;
@@ -575,9 +616,9 @@ public class Chunk {
}
public void cleanupPalettesAndBlockStates() {
for (int i = 0; i < sections.length(); i++) {
for(int i = 0; i < sections.length(); i++) {
Section section = sections.get(i);
if (section != null) {
if(section != null) {
section.cleanupPaletteAndBlockStates();
}
}
@@ -591,21 +632,21 @@ public class Chunk {
level.putLong("LastUpdate", lastUpdate);
level.putLong("InhabitedTime", inhabitedTime);
level.putIntArray("Biomes", biomes.getData());
if (heightMaps != null) level.put("Heightmaps", heightMaps);
if (carvingMasks != null) level.put("CarvingMasks", carvingMasks);
if (entities != null) level.put("Entities", entities);
if (tileEntities != null) level.put("TileEntities", tileEntities);
if (tileTicks != null) level.put("TileTicks", tileTicks);
if (liquidTicks != null) level.put("LiquidTicks", liquidTicks);
if (lights != null) level.put("Lights", lights);
if (liquidsToBeTicked != null) level.put("LiquidsToBeTicked", liquidsToBeTicked);
if (toBeTicked != null) level.put("ToBeTicked", toBeTicked);
if (postProcessing != null) level.put("PostProcessing", postProcessing);
if(heightMaps != null) level.put("Heightmaps", heightMaps);
if(carvingMasks != null) level.put("CarvingMasks", carvingMasks);
if(entities != null) level.put("Entities", entities);
if(tileEntities != null) level.put("TileEntities", tileEntities);
if(tileTicks != null) level.put("TileTicks", tileTicks);
if(liquidTicks != null) level.put("LiquidTicks", liquidTicks);
if(lights != null) level.put("Lights", lights);
if(liquidsToBeTicked != null) level.put("LiquidsToBeTicked", liquidsToBeTicked);
if(toBeTicked != null) level.put("ToBeTicked", toBeTicked);
if(postProcessing != null) level.put("PostProcessing", postProcessing);
level.putString("Status", status);
if (structures != null) level.put("Structures", structures);
if(structures != null) level.put("Structures", structures);
ListTag<CompoundTag> sections = new ListTag<>(CompoundTag.class);
for (int i = 0; i < this.sections.length(); i++) {
if (this.sections.get(i) != null) {
for(int i = 0; i < this.sections.length(); i++) {
if(this.sections.get(i) != null) {
sections.add(this.sections.get(i).updateHandle(i));
}
}

View File

@@ -45,8 +45,8 @@ public enum CompressionType {
}
public static CompressionType getFromID(byte id) {
for (CompressionType c : CompressionType.values()) {
if (c.id == id) {
for(CompressionType c : CompressionType.values()) {
if(c.id == id) {
return c;
}
}

View File

@@ -47,8 +47,10 @@ public class MCAFile {
* This constructor needs the x- and z-coordinates of the stored region,
* which can usually be taken from the file name {@code r.x.z.mca}
*
* @param regionX The x-coordinate of this region.
* @param regionZ The z-coordinate of this region.
* @param regionX
* The x-coordinate of this region.
* @param regionZ
* The z-coordinate of this region.
*/
public MCAFile(int regionX, int regionZ) {
this.regionX = regionX;
@@ -60,8 +62,10 @@ public class MCAFile {
* 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.
* @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) {
@@ -72,8 +76,10 @@ public class MCAFile {
* Reads an .mca file from a {@code RandomAccessFile} into this object.
* This method does not perform any cleanups on the data.
*
* @param raf The {@code RandomAccessFile} to read from.
* @throws IOException If something went wrong during deserialization.
* @param raf
* The {@code RandomAccessFile} to read from.
* @throws IOException
* If something went wrong during deserialization.
*/
public void deserialize(RandomAccessFile raf) throws IOException {
deserialize(raf, LoadFlags.ALL_DATA);
@@ -83,18 +89,21 @@ public class MCAFile {
* Reads an .mca file from a {@code RandomAccessFile} into this object.
* This method does not perform any cleanups on the data.
*
* @param raf The {@code RandomAccessFile} to read from.
* @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @throws IOException If something went wrong during deserialization.
* @param raf
* The {@code RandomAccessFile} to read from.
* @param loadFlags
* A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @throws IOException
* If something went wrong during deserialization.
*/
public void deserialize(RandomAccessFile raf, long loadFlags) throws IOException {
chunks = new AtomicReferenceArray<>(1024);
for (int i = 0; i < 1024; i++) {
for(int i = 0; i < 1024; i++) {
raf.seek(i * 4);
int offset = raf.read() << 16;
offset |= (raf.read() & 0xFF) << 8;
offset |= raf.read() & 0xFF;
if (raf.readByte() == 0) {
if(raf.readByte() == 0) {
continue;
}
raf.seek(4096 + i * 4);
@@ -111,7 +120,7 @@ public class MCAFile {
chunks = new AtomicReferenceArray<>(1024);
int x = 0;
int z = 0;
for (int i = 0; i < 1024; i++) {
for(int i = 0; i < 1024; i++) {
x++;
z++;
@@ -119,7 +128,7 @@ public class MCAFile {
int offset = raf.read() << 16;
offset |= (raf.read() & 0xFF) << 8;
offset |= raf.read() & 0xFF;
if (raf.readByte() == 0) {
if(raf.readByte() == 0) {
continue;
}
p2.add(new Position2(x & 31, (z / 31) & 31));
@@ -134,9 +143,11 @@ public class MCAFile {
/**
* Calls {@link MCAFile#serialize(RandomAccessFile, boolean)} without updating any timestamps.
*
* @param raf The {@code RandomAccessFile} to writeNodeData to.
* @param raf
* The {@code RandomAccessFile} to writeNodeData to.
* @return The amount of chunks written to the file.
* @throws IOException If something went wrong during serialization.
* @throws IOException
* If something went wrong during serialization.
* @see MCAFile#serialize(RandomAccessFile, boolean)
*/
public int serialize(RandomAccessFile raf) throws IOException {
@@ -147,11 +158,14 @@ public class MCAFile {
* Serializes this object to an .mca file.
* This method does not perform any cleanups on the data.
*
* @param raf The {@code RandomAccessFile} to writeNodeData to.
* @param changeLastUpdate Whether it should update all timestamps that show
* when this file was last updated.
* @param raf
* The {@code RandomAccessFile} to writeNodeData to.
* @param changeLastUpdate
* Whether it should update all timestamps that show
* when this file was last updated.
* @return The amount of chunks written to the file.
* @throws IOException If something went wrong during serialization.
* @throws IOException
* If something went wrong during serialization.
*/
public int serialize(RandomAccessFile raf, boolean changeLastUpdate) throws IOException {
int globalOffset = 2;
@@ -161,21 +175,21 @@ public class MCAFile {
int chunkXOffset = MCAUtil.regionToChunk(regionX);
int chunkZOffset = MCAUtil.regionToChunk(regionZ);
if (chunks == null) {
if(chunks == null) {
return 0;
}
for (int cx = 0; cx < 32; cx++) {
for (int cz = 0; cz < 32; cz++) {
for(int cx = 0; cx < 32; cx++) {
for(int cz = 0; cz < 32; cz++) {
int index = getChunkIndex(cx, cz);
Chunk chunk = chunks.get(index);
if (chunk == null) {
if(chunk == null) {
continue;
}
raf.seek(4096L * globalOffset);
lastWritten = chunk.serialize(raf, chunkXOffset + cx, chunkZOffset + cz);
if (lastWritten == 0) {
if(lastWritten == 0) {
continue;
}
@@ -198,7 +212,7 @@ public class MCAFile {
}
// padding
if (lastWritten % 4096 != 0) {
if(lastWritten % 4096 != 0) {
raf.seek(globalOffset * 4096L - 1);
raf.write(0);
}
@@ -213,13 +227,16 @@ public class MCAFile {
/**
* Set a specific Chunk at a specific index. The index must be in range of 0 - 1023.
*
* @param index The index of the Chunk.
* @param chunk The Chunk to be set.
* @throws IndexOutOfBoundsException If index is not in the range.
* @param index
* The index of the Chunk.
* @param chunk
* The Chunk to be set.
* @throws IndexOutOfBoundsException
* If index is not in the range.
*/
public void setChunk(int index, Chunk chunk) {
checkIndex(index);
if (chunks == null) {
if(chunks == null) {
chunks = new AtomicReferenceArray<>(1024);
}
chunks.set(index, chunk);
@@ -229,9 +246,12 @@ public class MCAFile {
* Set a specific Chunk at a specific chunk location.
* The x- and z-value can be absolute chunk coordinates or they can be relative to the region origin.
*
* @param chunkX The x-coordinate of the Chunk.
* @param chunkZ The z-coordinate of the Chunk.
* @param chunk The chunk to be set.
* @param chunkX
* The x-coordinate of the Chunk.
* @param chunkZ
* The z-coordinate of the Chunk.
* @param chunk
* The chunk to be set.
*/
public void setChunk(int chunkX, int chunkZ, Chunk chunk) {
setChunk(getChunkIndex(chunkX, chunkZ), chunk);
@@ -240,12 +260,13 @@ public class MCAFile {
/**
* Returns the chunk data of a chunk at a specific index in this file.
*
* @param index The index of the chunk in this file.
* @param index
* The index of the chunk in this file.
* @return The chunk data.
*/
public Chunk getChunk(int index) {
checkIndex(index);
if (chunks == null) {
if(chunks == null) {
return null;
}
return chunks.get(index);
@@ -254,8 +275,10 @@ public class MCAFile {
/**
* Returns the chunk data of a chunk in this file.
*
* @param chunkX The x-coordinate of the chunk.
* @param chunkZ The z-coordinate of the chunk.
* @param chunkX
* The x-coordinate of the chunk.
* @param chunkZ
* The z-coordinate of the chunk.
* @return The chunk data.
*/
public Chunk getChunk(int chunkX, int chunkZ) {
@@ -267,7 +290,7 @@ public class MCAFile {
}
private int checkIndex(int index) {
if (index < 0 || index > 1023) {
if(index < 0 || index > 1023) {
throw new IndexOutOfBoundsException();
}
return index;
@@ -276,7 +299,7 @@ public class MCAFile {
private Chunk createChunkIfMissing(int blockX, int blockZ) {
int chunkX = MCAUtil.blockToChunk(blockX), chunkZ = MCAUtil.blockToChunk(blockZ);
Chunk chunk = getChunk(chunkX, chunkZ);
if (chunk == null) {
if(chunk == null) {
chunk = Chunk.newChunk();
setChunk(getChunkIndex(chunkX, chunkZ), chunk);
}
@@ -290,15 +313,18 @@ public class MCAFile {
/**
* Fetches the biome id at a specific block.
*
* @param blockX The x-coordinate of the block.
* @param blockY The y-coordinate of the block.
* @param blockZ The z-coordinate of the block.
* @param blockX
* The x-coordinate of the block.
* @param blockY
* The y-coordinate of the block.
* @param blockZ
* The z-coordinate of the block.
* @return The biome id if the chunk exists and the chunk has biomes, otherwise -1.
*/
public int getBiomeAt(int blockX, int blockY, int blockZ) {
int chunkX = MCAUtil.blockToChunk(blockX), chunkZ = MCAUtil.blockToChunk(blockZ);
Chunk chunk = getChunk(getChunkIndex(chunkX, chunkZ));
if (chunk == null) {
if(chunk == null) {
return -1;
}
return chunk.getBiomeAt(blockX, blockY, blockZ);
@@ -308,11 +334,16 @@ public class MCAFile {
* Set a block state at a specific block location.
* The block coordinates can be absolute coordinates or they can be relative to the region.
*
* @param blockX The x-coordinate of the block.
* @param blockY The y-coordinate of the block.
* @param blockZ The z-coordinate of the block.
* @param state The block state to be set.
* @param cleanup Whether the Palette and the BLockStates should be recalculated after adding the block state.
* @param blockX
* The x-coordinate of the block.
* @param blockY
* The y-coordinate of the block.
* @param blockZ
* The z-coordinate of the block.
* @param state
* The block state to be set.
* @param cleanup
* Whether the Palette and the BLockStates should be recalculated after adding the block state.
*/
public void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
createChunkIfMissing(blockX, blockZ).setBlockStateAt(blockX, blockY, blockZ, state, cleanup);
@@ -322,15 +353,18 @@ public class MCAFile {
* Fetches a block state at a specific block location.
* The block coordinates can be absolute coordinates or they can be relative to the region.
*
* @param blockX The x-coordinate of the block.
* @param blockY The y-coordinate of the block.
* @param blockZ The z-coordinate of the block.
* @param blockX
* The x-coordinate of the block.
* @param blockY
* The y-coordinate of the block.
* @param blockZ
* The z-coordinate of the block.
* @return The block state or <code>null</code> if the chunk or the section do not exist.
*/
public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
int chunkX = MCAUtil.blockToChunk(blockX), chunkZ = MCAUtil.blockToChunk(blockZ);
Chunk chunk = getChunk(chunkX, chunkZ);
if (chunk == null) {
if(chunk == null) {
return null;
}
return chunk.getBlockStateAt(blockX, blockY, blockZ);

View File

@@ -41,9 +41,11 @@ public final class MCAUtil {
}
/**
* @param file The file to read the data from.
* @param file
* The file to read the data from.
* @return An in-memory representation of the MCA file with decompressed chunk data.
* @throws IOException if something during deserialization goes wrong.
* @throws IOException
* if something during deserialization goes wrong.
* @see MCAUtil#read(File)
*/
public static MCAFile read(String file) throws IOException {
@@ -53,19 +55,24 @@ public final class MCAUtil {
/**
* Reads an MCA file and loads all of its chunks.
*
* @param file The file to read the data from.
* @param file
* The file to read the data from.
* @return An in-memory representation of the MCA file with decompressed chunk data.
* @throws IOException if something during deserialization goes wrong.
* @throws IOException
* if something during deserialization goes wrong.
*/
public static MCAFile read(File file) throws IOException {
return read(file, LoadFlags.ALL_DATA);
}
/**
* @param file The file to read the data from.
* @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @param file
* The file to read the data from.
* @param loadFlags
* A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @return An in-memory representation of the MCA file with decompressed chunk data.
* @throws IOException if something during deserialization goes wrong.
* @throws IOException
* if something during deserialization goes wrong.
* @see MCAUtil#read(File)
*/
public static MCAFile read(String file, long loadFlags) throws IOException {
@@ -75,14 +82,17 @@ public final class MCAUtil {
/**
* Reads an MCA file and loads all of its chunks.
*
* @param file The file to read the data from.
* @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @param file
* The file to read the data from.
* @param loadFlags
* A logical or of {@link LoadFlags} constants indicating what data should be loaded
* @return An in-memory representation of the MCA file with decompressed chunk data
* @throws IOException if something during deserialization goes wrong.
* @throws IOException
* if something during deserialization goes wrong.
*/
public static MCAFile read(File file, long loadFlags) throws IOException {
MCAFile mcaFile = newMCAFile(file);
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
try(RandomAccessFile raf = new RandomAccessFile(file, "r")) {
mcaFile.deserialize(raf, loadFlags);
return mcaFile;
}
@@ -90,7 +100,7 @@ public final class MCAUtil {
public static KList<Position2> sampleChunkPositions(File file) throws IOException {
MCAFile mcaFile = newMCAFile(file);
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
try(RandomAccessFile raf = new RandomAccessFile(file, "r")) {
return mcaFile.samplePositions(raf);
}
}
@@ -98,10 +108,13 @@ public final class MCAUtil {
/**
* Calls {@link MCAUtil#write(MCAFile, File, boolean)} without changing the timestamps.
*
* @param file The file to writeNodeData to.
* @param mcaFile The data of the MCA file to writeNodeData.
* @param file
* The file to writeNodeData to.
* @param mcaFile
* The data of the MCA file to writeNodeData.
* @return The amount of chunks written to the file.
* @throws IOException If something goes wrong during serialization.
* @throws IOException
* If something goes wrong during serialization.
* @see MCAUtil#write(MCAFile, File, boolean)
*/
public static int write(MCAFile mcaFile, String file) throws IOException {
@@ -111,10 +124,13 @@ public final class MCAUtil {
/**
* Calls {@link MCAUtil#write(MCAFile, File, boolean)} without changing the timestamps.
*
* @param file The file to writeNodeData to.
* @param mcaFile The data of the MCA file to writeNodeData.
* @param file
* The file to writeNodeData to.
* @param mcaFile
* The data of the MCA file to writeNodeData.
* @return The amount of chunks written to the file.
* @throws IOException If something goes wrong during serialization.
* @throws IOException
* If something goes wrong during serialization.
* @see MCAUtil#write(MCAFile, File, boolean)
*/
public static int write(MCAFile mcaFile, File file) throws IOException {
@@ -122,11 +138,15 @@ public final class MCAUtil {
}
/**
* @param file The file to writeNodeData to.
* @param mcaFile The data of the MCA file to writeNodeData.
* @param changeLastUpdate Whether to adjust the timestamps of when the file was saved.
* @param file
* The file to writeNodeData to.
* @param mcaFile
* The data of the MCA file to writeNodeData.
* @param changeLastUpdate
* Whether to adjust the timestamps of when the file was saved.
* @return The amount of chunks written to the file.
* @throws IOException If something goes wrong during serialization.
* @throws IOException
* If something goes wrong during serialization.
* @see MCAUtil#write(MCAFile, File, boolean)
*/
public static int write(MCAFile mcaFile, String file, boolean changeLastUpdate) throws IOException {
@@ -139,27 +159,31 @@ public final class MCAUtil {
* the value set by either loading an already existing MCA file or setting them manually.<br>
* If the file already exists, it is completely overwritten by the new file (no modification).
*
* @param file The file to writeNodeData to.
* @param mcaFile The data of the MCA file to writeNodeData.
* @param changeLastUpdate Whether to adjust the timestamps of when the file was saved.
* @param file
* The file to writeNodeData to.
* @param mcaFile
* The data of the MCA file to writeNodeData.
* @param changeLastUpdate
* Whether to adjust the timestamps of when the file was saved.
* @return The amount of chunks written to the file.
* @throws IOException If something goes wrong during serialization.
* @throws IOException
* If something goes wrong during serialization.
*/
public static int write(MCAFile mcaFile, File file, boolean changeLastUpdate) throws IOException {
if (mcaFile == null) {
if(mcaFile == null) {
return 0;
}
File to = file;
if (file.exists()) {
if(file.exists()) {
to = File.createTempFile(to.getName(), null);
}
int chunks;
try (RandomAccessFile raf = new RandomAccessFile(to, "rw")) {
try(RandomAccessFile raf = new RandomAccessFile(to, "rw")) {
chunks = mcaFile.serialize(raf, changeLastUpdate);
}
if (chunks > 0 && to != file) {
if(chunks > 0 && to != file) {
Files.move(to.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
@@ -170,8 +194,10 @@ public final class MCAUtil {
* Turns the chunks coordinates into region coordinates and calls
* {@link MCAUtil#createNameFromRegionLocation(int, int)}
*
* @param chunkX The x-value of the location of the chunk.
* @param chunkZ The z-value of the location of the chunk.
* @param chunkX
* The x-value of the location of the chunk.
* @param chunkZ
* The z-value of the location of the chunk.
* @return A mca filename in the format "r.{regionX}.{regionZ}.mca"
*/
public static String createNameFromChunkLocation(int chunkX, int chunkZ) {
@@ -182,8 +208,10 @@ public final class MCAUtil {
* Turns the block coordinates into region coordinates and calls
* {@link MCAUtil#createNameFromRegionLocation(int, int)}
*
* @param blockX The x-value of the location of the block.
* @param blockZ The z-value of the location of the block.
* @param blockX
* The x-value of the location of the block.
* @param blockZ
* The z-value of the location of the block.
* @return A mca filename in the format "r.{regionX}.{regionZ}.mca"
*/
public static String createNameFromBlockLocation(int blockX, int blockZ) {
@@ -193,8 +221,10 @@ public final class MCAUtil {
/**
* Creates a filename string from provided chunk coordinates.
*
* @param regionX The x-value of the location of the region.
* @param regionZ The z-value of the location of the region.
* @param regionX
* The x-value of the location of the region.
* @param regionZ
* The z-value of the location of the region.
* @return A mca filename in the format "r.{regionX}.{regionZ}.mca"
*/
public static String createNameFromRegionLocation(int regionX, int regionZ) {
@@ -204,7 +234,8 @@ public final class MCAUtil {
/**
* Turns a block coordinate value into a chunk coordinate value.
*
* @param block The block coordinate value.
* @param block
* The block coordinate value.
* @return The chunk coordinate value.
*/
public static int blockToChunk(int block) {
@@ -214,7 +245,8 @@ public final class MCAUtil {
/**
* Turns a block coordinate value into a region coordinate value.
*
* @param block The block coordinate value.
* @param block
* The block coordinate value.
* @return The region coordinate value.
*/
public static int blockToRegion(int block) {
@@ -224,7 +256,8 @@ public final class MCAUtil {
/**
* Turns a chunk coordinate value into a region coordinate value.
*
* @param chunk The chunk coordinate value.
* @param chunk
* The chunk coordinate value.
* @return The region coordinate value.
*/
public static int chunkToRegion(int chunk) {
@@ -234,7 +267,8 @@ public final class MCAUtil {
/**
* Turns a region coordinate value into a chunk coordinate value.
*
* @param region The region coordinate value.
* @param region
* The region coordinate value.
* @return The chunk coordinate value.
*/
public static int regionToChunk(int region) {
@@ -244,7 +278,8 @@ public final class MCAUtil {
/**
* Turns a region coordinate value into a block coordinate value.
*
* @param region The region coordinate value.
* @param region
* The region coordinate value.
* @return The block coordinate value.
*/
public static int regionToBlock(int region) {
@@ -254,7 +289,8 @@ public final class MCAUtil {
/**
* Turns a chunk coordinate value into a block coordinate value.
*
* @param chunk The chunk coordinate value.
* @param chunk
* The chunk coordinate value.
* @return The block coordinate value.
*/
public static int chunkToBlock(int chunk) {
@@ -263,7 +299,7 @@ public final class MCAUtil {
public static MCAFile newMCAFile(File file) {
Matcher m = mcaFilePattern.matcher(file.getName());
if (m.find()) {
if(m.find()) {
return new MCAFile(Integer.parseInt(m.group("regionX")), Integer.parseInt(m.group("regionZ")));
}
throw new IllegalArgumentException("invalid mca file name: " + file.getName());

View File

@@ -49,11 +49,11 @@ public class NBTWorld {
NamespacedKey key = blockData.getMaterial().getKey();
s.putString("Name", key.getNamespace() + ":" + key.getKey());
if (data.contains("[")) {
if(data.contains("[")) {
String raw = data.split("\\Q[\\E")[1].replaceAll("\\Q]\\E", "");
CompoundTag props = new CompoundTag();
if (raw.contains(",")) {
for (String i : raw.split("\\Q,\\E")) {
if(raw.contains(",")) {
for(String i : raw.split("\\Q,\\E")) {
String[] m = i.split("\\Q=\\E");
String k = m[0];
String v = m[1];
@@ -90,17 +90,17 @@ public class NBTWorld {
}
public static BlockData getBlockData(CompoundTag tag) {
if (tag == null) {
if(tag == null) {
return B.getAir();
}
StringBuilder p = new StringBuilder(tag.getString("Name"));
if (tag.containsKey("Properties")) {
if(tag.containsKey("Properties")) {
CompoundTag props = tag.getCompoundTag("Properties");
p.append('[');
for (String i : props.keySet()) {
for(String i : props.keySet()) {
p.append(i).append('=').append(props.getString(i)).append(',');
}
@@ -109,7 +109,7 @@ public class NBTWorld {
BlockData b = B.getOrNull(p.toString());
if (b == null) {
if(b == null) {
return B.getAir();
}
@@ -123,8 +123,8 @@ public class NBTWorld {
private static Map<Biome, Integer> computeBiomeIDs() {
Map<Biome, Integer> biomeIds = new KMap<>();
for (Biome biome : Biome.values()) {
if (!biome.name().equals("CUSTOM")) {
for(Biome biome : Biome.values()) {
if(!biome.name().equals("CUSTOM")) {
biomeIds.put(biome, INMS.get().getBiomeId(biome));
}
}
@@ -134,22 +134,22 @@ public class NBTWorld {
public void close() {
for (Long i : loadedRegions.k()) {
for(Long i : loadedRegions.k()) {
queueSaveUnload(Cache.keyX(i), Cache.keyZ(i));
}
saveQueue.shutdown();
try {
while (!saveQueue.awaitTermination(3, TimeUnit.SECONDS)) {
while(!saveQueue.awaitTermination(3, TimeUnit.SECONDS)) {
Iris.info("Still Waiting to save MCA Files...");
}
} catch (InterruptedException e) {
} catch(InterruptedException e) {
e.printStackTrace();
}
}
public void flushNow() {
for (Long i : loadedRegions.k()) {
for(Long i : loadedRegions.k()) {
doSaveUnload(Cache.keyX(i), Cache.keyZ(i));
}
}
@@ -160,7 +160,7 @@ public class NBTWorld {
public void doSaveUnload(int x, int z) {
MCAFile f = getMCAOrNull(x, z);
if (f != null) {
if(f != null) {
unloadRegion(x, z);
}
@@ -170,15 +170,15 @@ public class NBTWorld {
public void save() {
boolean saving = true;
for (Long i : loadedRegions.k()) {
for(Long i : loadedRegions.k()) {
int x = Cache.keyX(i);
int z = Cache.keyZ(i);
if (!lastUse.containsKey(i)) {
if(!lastUse.containsKey(i)) {
lastUse.put(i, M.ms());
}
if (shouldUnload(x, z)) {
if(shouldUnload(x, z)) {
queueSaveUnload(x, z);
}
}
@@ -203,7 +203,7 @@ public class NBTWorld {
try {
MCAUtil.write(mca, getRegionFile(x, z), true);
Iris.debug("Saved Region " + C.GOLD + x + " " + z);
} catch (IOException e) {
} catch(IOException e) {
Iris.error("Failed to save region " + getRegionFile(x, z).getPath());
e.printStackTrace();
}
@@ -213,7 +213,7 @@ public class NBTWorld {
try {
MCAUtil.write(mca, getRegionFile(x, z), true);
Iris.debug("Saved Region " + C.GOLD + x + " " + z);
} catch (IOException e) {
} catch(IOException e) {
Iris.error("Failed to save region " + getRegionFile(x, z).getPath());
e.printStackTrace();
}
@@ -231,12 +231,12 @@ public class NBTWorld {
try {
CompoundTag tag = getChunkSection(x >> 4, y >> 4, z >> 4).getBlockStateAt(x & 15, y & 15, z & 15);
if (tag == null) {
if(tag == null) {
return AIR;
}
return getBlockData(tag);
} catch (Throwable e) {
} catch(Throwable e) {
Iris.reportError(e);
}
@@ -259,7 +259,7 @@ public class NBTWorld {
Chunk c = getChunk(x, z);
Section s = c.getSection(y);
if (s == null) {
if(s == null) {
s = Section.newSection();
c.setSection(y, s);
}
@@ -274,7 +274,7 @@ public class NBTWorld {
public Chunk getChunk(MCAFile mca, int x, int z) {
Chunk c = mca.getChunk(x & 31, z & 31);
if (c == null) {
if(c == null) {
c = Chunk.newChunk();
mca.setChunk(x & 31, z & 31, c);
}
@@ -304,7 +304,7 @@ public class NBTWorld {
MCAFile mcaf = loadedRegions.get(key);
if (mcaf == null) {
if(mcaf == null) {
mcaf = new MCAFile(x, z);
loadedRegions.put(key, mcaf);
}
@@ -317,7 +317,7 @@ public class NBTWorld {
long key = Cache.key(x, z);
return hyperLock.withResult(x, z, () -> {
if (loadedRegions.containsKey(key)) {
if(loadedRegions.containsKey(key)) {
lastUse.put(key, M.ms());
return loadedRegions.get(key);
}

View File

@@ -40,7 +40,7 @@ public class Section {
data = sectionRoot;
this.dataVersion = dataVersion;
ListTag<?> rawPalette = sectionRoot.getListTag("Palette");
if (rawPalette == null) {
if(rawPalette == null) {
return;
}
palette = INMS.get().createPalette();
@@ -79,13 +79,16 @@ public class Section {
* Fetches a block state based on a block location from this section.
* The coordinates represent the location of the block inside of this Section.
*
* @param blockX The x-coordinate of the block in this Section
* @param blockY The y-coordinate of the block in this Section
* @param blockZ The z-coordinate of the block in this Section
* @param blockX
* The x-coordinate of the block in this Section
* @param blockY
* The y-coordinate of the block in this Section
* @param blockZ
* The z-coordinate of the block in this Section
* @return The block state data of this block.
*/
public synchronized CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
synchronized (palette) {
synchronized(palette) {
return palette.getBlock(blockX & 15, blockY & 15, blockZ & 15);
}
}
@@ -93,13 +96,17 @@ public class Section {
/**
* Attempts to add a block state for a specific block location in this Section.
*
* @param blockX The x-coordinate of the block in this Section
* @param blockY The y-coordinate of the block in this Section
* @param blockZ The z-coordinate of the block in this Section
* @param state The block state to be set
* @param blockX
* The x-coordinate of the block in this Section
* @param blockY
* The y-coordinate of the block in this Section
* @param blockZ
* The z-coordinate of the block in this Section
* @param state
* The block state to be set
*/
public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
synchronized (palette) {
synchronized(palette) {
palette.setBlock(blockX & 15, blockY & 15, blockZ & 15, state);
}
}
@@ -123,11 +130,13 @@ public class Section {
/**
* Sets the block light array for this section.
*
* @param blockLight The block light array
* @throws IllegalArgumentException When the length of the array is not 2048
* @param blockLight
* The block light array
* @throws IllegalArgumentException
* When the length of the array is not 2048
*/
public synchronized void setBlockLight(byte[] blockLight) {
if (blockLight != null && blockLight.length != 2048) {
if(blockLight != null && blockLight.length != 2048) {
throw new IllegalArgumentException("BlockLight array must have a length of 2048");
}
this.blockLight = blockLight;
@@ -143,11 +152,13 @@ public class Section {
/**
* Sets the sky light values of this section.
*
* @param skyLight The custom sky light values
* @throws IllegalArgumentException If the length of the array is not 2048
* @param skyLight
* The custom sky light values
* @throws IllegalArgumentException
* If the length of the array is not 2048
*/
public synchronized void setSkyLight(byte[] skyLight) {
if (skyLight != null && skyLight.length != 2048) {
if(skyLight != null && skyLight.length != 2048) {
throw new IllegalArgumentException("SkyLight array must have a length of 2048");
}
this.skyLight = skyLight;
@@ -158,21 +169,22 @@ public class Section {
* This must be called before saving a Section to disk if the Section was manually created
* to set the Y of this Section.
*
* @param y The Y-value of this Section
* @param y
* The Y-value of this Section
* @return A reference to the raw CompoundTag this Section is based on
*/
public synchronized CompoundTag updateHandle(int y) {
data.putByte("Y", (byte) y);
if (palette != null) {
synchronized (palette) {
if(palette != null) {
synchronized(palette) {
palette.writeToSection(data);
}
}
if (blockLight != null) {
if(blockLight != null) {
data.putByteArray("BlockLight", blockLight);
}
if (skyLight != null) {
if(skyLight != null) {
data.putByteArray("SkyLight", skyLight);
}
return data;

View File

@@ -23,27 +23,27 @@ import org.apache.commons.lang3.Validate;
import java.util.function.IntConsumer;
public class MCABitStorage {
private static final int[] MAGIC = new int[]{
-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE,
0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756,
0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0,
390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378,
306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 0, 3, 252645135, 252645135,
0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0,
204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970,
178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862,
0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0,
138547332, 138547332, 0, Integer.MIN_VALUE, 0, 4, 130150524, 130150524, 0, 126322567,
126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197,
0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0,
104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893,
97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282,
0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0,
84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431,
79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303,
0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0,
70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE,
0, 5};
private static final int[] MAGIC = new int[] {
-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE,
0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756,
0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0,
390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378,
306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 0, 3, 252645135, 252645135,
0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0,
204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970,
178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862,
0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0,
138547332, 138547332, 0, Integer.MIN_VALUE, 0, 4, 130150524, 130150524, 0, 126322567,
126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197,
0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0,
104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893,
97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282,
0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0,
84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431,
79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303,
0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0,
70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE,
0, 5};
private final long[] data;
@@ -76,8 +76,8 @@ public class MCABitStorage {
this.divideAdd = MAGIC[var3 + 1];
this.divideShift = MAGIC[var3 + 2];
int var4 = (length + this.valuesPerLong - 1) / this.valuesPerLong;
if (data != null) {
if (data.length != var4)
if(data != null) {
if(data.length != var4)
throw new RuntimeException("NO!");
this.data = data;
} else {
@@ -133,11 +133,11 @@ public class MCABitStorage {
public void getAll(IntConsumer var0) {
int var1 = 0;
for (long var5 : this.data) {
for (int var7 = 0; var7 < this.valuesPerLong; var7++) {
for(long var5 : this.data) {
for(int var7 = 0; var7 < this.valuesPerLong; var7++) {
var0.accept((int) (var5 & this.mask));
var5 >>= this.bits;
if (++var1 >= this.size)
if(++var1 >= this.size)
return;
}
}

View File

@@ -54,18 +54,18 @@ public class MCAChunkBiomeContainer<T> {
public MCAChunkBiomeContainer(MCAIdMap<T> registry, int minHeight, int maxHeight, int[] aint) {
this(registry, minHeight, maxHeight, (T[]) new Object[aint.length]);
int i = -1;
for (int j = 0; j < this.biomes.length; j++) {
for(int j = 0; j < this.biomes.length; j++) {
int k = aint[j];
T biomebase = registry.byId(k);
if (biomebase == null) {
if (i == -1)
if(biomebase == null) {
if(i == -1)
i = j;
this.biomes[j] = registry.byId(0);
} else {
this.biomes[j] = biomebase;
}
}
if (i != -1)
if(i != -1)
LOGGER.warn("Invalid biome data received, starting from {}: {}", Integer.valueOf(i), Arrays.toString(aint));
}
@@ -75,7 +75,7 @@ public class MCAChunkBiomeContainer<T> {
public int[] writeBiomes() {
int[] aint = new int[this.biomes.length];
for (int i = 0; i < this.biomes.length; i++)
for(int i = 0; i < this.biomes.length; i++)
aint[i] = this.biomeRegistry.getId(this.biomes[i]);
return aint;
}

View File

@@ -54,13 +54,13 @@ public class MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<K> {
public K byId(int var0) {
if (var0 < 0 || var0 >= this.byId.length)
if(var0 < 0 || var0 >= this.byId.length)
return null;
return this.byId[var0];
}
private int getValue(int var0) {
if (var0 == -1)
if(var0 == -1)
return -1;
return this.values[var0];
}
@@ -80,7 +80,7 @@ public class MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<K> {
}
private int nextId() {
while (this.nextId < this.byId.length && this.byId[this.nextId] != null)
while(this.nextId < this.byId.length && this.byId[this.nextId] != null)
this.nextId++;
return this.nextId;
}
@@ -93,17 +93,17 @@ public class MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<K> {
this.byId = (K[]) new Object[var0];
this.nextId = 0;
this.size = 0;
for (int var3 = 0; var3 < var1.length; var3++) {
if (var1[var3] != null)
for(int var3 = 0; var3 < var1.length; var3++) {
if(var1[var3] != null)
addMapping(var1[var3], var2[var3]);
}
}
public void addMapping(K var0, int var1) {
int var2 = Math.max(var1, this.size + 1);
if (var2 >= this.keys.length * 0.8F) {
if(var2 >= this.keys.length * 0.8F) {
int i = this.keys.length << 1;
while (i < var1)
while(i < var1)
i <<= 1;
grow(i);
}
@@ -112,7 +112,7 @@ public class MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<K> {
this.values[var3] = var1;
this.byId[var1] = var0;
this.size++;
if (var1 == this.nextId)
if(var1 == this.nextId)
this.nextId++;
}
@@ -122,16 +122,16 @@ public class MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<K> {
private int indexOf(K var0, int var1) {
int var2;
for (var2 = var1; var2 < this.keys.length; var2++) {
if (this.keys[var2] == var0)
for(var2 = var1; var2 < this.keys.length; var2++) {
if(this.keys[var2] == var0)
return var2;
if (this.keys[var2] == EMPTY_SLOT)
if(this.keys[var2] == EMPTY_SLOT)
return -1;
}
for (var2 = 0; var2 < var1; var2++) {
if (this.keys[var2] == var0)
for(var2 = 0; var2 < var1; var2++) {
if(this.keys[var2] == var0)
return var2;
if (this.keys[var2] == EMPTY_SLOT)
if(this.keys[var2] == EMPTY_SLOT)
return -1;
}
return -1;
@@ -139,12 +139,12 @@ public class MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<K> {
private int findEmpty(int var0) {
int var1;
for (var1 = var0; var1 < this.keys.length; var1++) {
if (this.keys[var1] == EMPTY_SLOT)
for(var1 = var0; var1 < this.keys.length; var1++) {
if(this.keys[var1] == EMPTY_SLOT)
return var1;
}
for (var1 = 0; var1 < var0; var1++) {
if (this.keys[var1] == EMPTY_SLOT)
for(var1 = 0; var1 < var0; var1++) {
if(this.keys[var1] == EMPTY_SLOT)
return var1;
}
throw new RuntimeException("Overflowed :(");

View File

@@ -48,17 +48,17 @@ public class MCAHashMapPalette<T> implements MCAPalette<T> {
public int idFor(T var0) {
int var1 = this.values.getId(var0);
if (var1 == -1) {
if(var1 == -1) {
var1 = this.values.add(var0);
if (var1 >= 1 << this.bits)
if(var1 >= 1 << this.bits)
var1 = this.resizeHandler.onResize(this.bits + 1, var0);
}
return var1;
}
public boolean maybeHas(Predicate<T> var0) {
for (int var1 = 0; var1 < getSize(); var1++) {
if (var0.test(this.values.byId(var1)))
for(int var1 = 0; var1 < getSize(); var1++) {
if(var0.test(this.values.byId(var1)))
return true;
}
return false;
@@ -74,12 +74,12 @@ public class MCAHashMapPalette<T> implements MCAPalette<T> {
public void read(ListTag var0) {
this.values.clear();
for (int var1 = 0; var1 < var0.size(); var1++)
for(int var1 = 0; var1 < var0.size(); var1++)
this.values.add(this.reader.apply((CompoundTag) var0.get(var1)));
}
public void write(ListTag var0) {
for (int var1 = 0; var1 < getSize(); var1++)
for(int var1 = 0; var1 < getSize(); var1++)
var0.add(this.writer.apply(this.values.byId(var1)));
}
}

View File

@@ -21,14 +21,10 @@ package com.volmit.iris.util.nbt.mca.palette;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap;
import net.kyori.adventure.identity.Identity;
import net.minecraft.Util;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
@@ -55,10 +51,10 @@ public class MCAIdMapper<T> implements MCAIdMap<T> {
public void addMapping(T var0, int var1) {
this.tToId.put(var0, Integer.valueOf(var1));
while (this.idToT.size() <= var1)
while(this.idToT.size() <= var1)
this.idToT.add(null);
this.idToT.set(var1, var0);
if (this.nextId <= var1)
if(this.nextId <= var1)
this.nextId = var1 + 1;
}
@@ -72,7 +68,7 @@ public class MCAIdMapper<T> implements MCAIdMap<T> {
}
public final T byId(int var0) {
if (var0 >= 0 && var0 < this.idToT.size())
if(var0 >= 0 && var0 < this.idToT.size())
return this.idToT.get(var0);
return null;
}
@@ -89,10 +85,10 @@ public class MCAIdMapper<T> implements MCAIdMap<T> {
return this.tToId.size();
}
static enum IdentityStrategy implements Hash.Strategy<Object> {
enum IdentityStrategy implements Hash.Strategy<Object> {
INSTANCE;
private IdentityStrategy() {
IdentityStrategy() {
}
public int hashCode(Object var0) {

View File

@@ -47,12 +47,12 @@ public class MCALinearPalette<T> implements MCAPalette<T> {
public int idFor(T var0) {
int var1;
for (var1 = 0; var1 < this.size; var1++) {
if (this.values[var1] == var0)
for(var1 = 0; var1 < this.size; var1++) {
if(this.values[var1] == var0)
return var1;
}
var1 = this.size;
if (var1 < this.values.length) {
if(var1 < this.values.length) {
this.values[var1] = var0;
this.size++;
return var1;
@@ -61,15 +61,15 @@ public class MCALinearPalette<T> implements MCAPalette<T> {
}
public boolean maybeHas(Predicate<T> var0) {
for (int var1 = 0; var1 < this.size; var1++) {
if (var0.test(this.values[var1]))
for(int var1 = 0; var1 < this.size; var1++) {
if(var0.test(this.values[var1]))
return true;
}
return false;
}
public T valueFor(int var0) {
if (var0 >= 0 && var0 < this.size)
if(var0 >= 0 && var0 < this.size)
return this.values[var0];
return null;
}
@@ -79,7 +79,7 @@ public class MCALinearPalette<T> implements MCAPalette<T> {
}
public void read(ListTag var0) {
for (int var1 = 0; var1 < var0.size(); var1++) {
for(int var1 = 0; var1 < var0.size(); var1++) {
this.values[var1] = this.reader.apply((CompoundTag) var0.get(var1));
}
this.size = var0.size();

View File

@@ -41,11 +41,11 @@ public class MCAMth {
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 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;
@@ -55,13 +55,13 @@ public class MCAMth {
static {
SIN = make(new float[65536], var0 -> {
for (int var1 = 0; var1 < var0.length; var1++)
for(int var1 = 0; var1 < var0.length; var1++)
var0[var1] = (float) Math.sin(var1 * Math.PI * 2.0D / 65536.0D);
});
}
static {
for (int var0 = 0; var0 < 257; var0++) {
for(int var0 = 0; var0 < 257; var0++) {
double var1 = var0 / 256.0D;
double var3 = Math.asin(var1);
COS_TAB[var0] = Math.cos(var3);
@@ -132,65 +132,65 @@ public class MCAMth {
}
public static byte clamp(byte var0, byte var1, byte var2) {
if (var0 < var1)
if(var0 < var1)
return var1;
if (var0 > var2)
if(var0 > var2)
return var2;
return var0;
}
public static int clamp(int var0, int var1, int var2) {
if (var0 < var1)
if(var0 < var1)
return var1;
if (var0 > var2)
if(var0 > var2)
return var2;
return var0;
}
public static long clamp(long var0, long var2, long var4) {
if (var0 < var2)
if(var0 < var2)
return var2;
if (var0 > var4)
if(var0 > var4)
return var4;
return var0;
}
public static float clamp(float var0, float var1, float var2) {
if (var0 < var1)
if(var0 < var1)
return var1;
if (var0 > var2)
if(var0 > var2)
return var2;
return var0;
}
public static double clamp(double var0, double var2, double var4) {
if (var0 < var2)
if(var0 < var2)
return var2;
if (var0 > var4)
if(var0 > var4)
return var4;
return var0;
}
public static double clampedLerp(double var0, double var2, double var4) {
if (var4 < 0.0D)
if(var4 < 0.0D)
return var0;
if (var4 > 1.0D)
if(var4 > 1.0D)
return var2;
return lerp(var4, var0, var2);
}
public static float clampedLerp(float var0, float var1, float var2) {
if (var2 < 0.0F)
if(var2 < 0.0F)
return var0;
if (var2 > 1.0F)
if(var2 > 1.0F)
return var1;
return lerp(var2, var0, var1);
}
public static double absMax(double var0, double var2) {
if (var0 < 0.0D)
if(var0 < 0.0D)
var0 = -var0;
if (var2 < 0.0D)
if(var2 < 0.0D)
var2 = -var2;
return (var0 > var2) ? var0 : var2;
}
@@ -200,26 +200,26 @@ public class MCAMth {
}
public static int nextInt(Random var0, int var1, int var2) {
if (var1 >= var2)
if(var1 >= var2)
return var1;
return var0.nextInt(var2 - var1 + 1) + var1;
}
public static float nextFloat(Random var0, float var1, float var2) {
if (var1 >= var2)
if(var1 >= var2)
return var1;
return var0.nextFloat() * (var2 - var1) + var1;
}
public static double nextDouble(Random var0, double var1, double var3) {
if (var1 >= var3)
if(var1 >= var3)
return var1;
return var0.nextDouble() * (var3 - var1) + var1;
}
public static double average(long[] var0) {
long var1 = 0L;
for (long var6 : var0)
for(long var6 : var0)
var1 += var6;
return var1 / var0.length;
}
@@ -246,27 +246,27 @@ public class MCAMth {
public static int wrapDegrees(int var0) {
int var1 = var0 % 360;
if (var1 >= 180)
if(var1 >= 180)
var1 -= 360;
if (var1 < -180)
if(var1 < -180)
var1 += 360;
return var1;
}
public static float wrapDegrees(float var0) {
float var1 = var0 % 360.0F;
if (var1 >= 180.0F)
if(var1 >= 180.0F)
var1 -= 360.0F;
if (var1 < -180.0F)
if(var1 < -180.0F)
var1 += 360.0F;
return var1;
}
public static double wrapDegrees(double var0) {
double var2 = var0 % 360.0D;
if (var2 >= 180.0D)
if(var2 >= 180.0D)
var2 -= 360.0D;
if (var2 < -180.0D)
if(var2 < -180.0D)
var2 += 360.0D;
return var2;
}
@@ -287,7 +287,7 @@ public class MCAMth {
public static float approach(float var0, float var1, float var2) {
var2 = abs(var2);
if (var0 < var1)
if(var0 < var1)
return clamp(var0 + var2, var0, var1);
return clamp(var0 - var2, var1, var0);
}
@@ -308,7 +308,7 @@ public class MCAMth {
public static double getDouble(String var0, double var1) {
try {
return Double.parseDouble(var0);
} catch (Throwable var3) {
} catch(Throwable var3) {
return var1;
}
}
@@ -404,16 +404,16 @@ public class MCAMth {
public static double atan2(double var0, double var2) {
double var4 = var2 * var2 + var0 * var0;
if (Double.isNaN(var4))
if(Double.isNaN(var4))
return Double.NaN;
boolean var6 = (var0 < 0.0D);
if (var6)
if(var6)
var0 = -var0;
boolean var7 = (var2 < 0.0D);
if (var7)
if(var7)
var2 = -var2;
boolean var8 = (var0 > var2);
if (var8) {
if(var8) {
double d = var2;
var2 = var0;
var0 = d;
@@ -429,11 +429,11 @@ public class MCAMth {
double var20 = var0 * var16 - var2 * var18;
double var22 = (6.0D + var20 * var20) * var20 * 0.16666666666666666D;
double var24 = var14 + var22;
if (var8)
if(var8)
var24 = 1.5707963267948966D - var24;
if (var7)
if(var7)
var24 = Math.PI - var24;
if (var6)
if(var6)
var24 = -var24;
return var24;
}
@@ -472,7 +472,7 @@ public class MCAMth {
float var5 = var2 * (1.0F - var1);
float var6 = var2 * (1.0F - var4 * var1);
float var7 = var2 * (1.0F - (1.0F - var4) * var1);
switch (var3) {
switch(var3) {
case 0:
var8 = var2;
var9 = var7;
@@ -545,20 +545,20 @@ public class MCAMth {
public static double[] cumulativeSum(double... var0) {
float var1 = 0.0F;
for (double var5 : var0)
for(double var5 : var0)
var1 = (float) (var1 + var5);
int var2;
for (var2 = 0; var2 < var0.length; var2++)
for(var2 = 0; var2 < var0.length; var2++)
var0[var2] = var0[var2] / var1;
for (var2 = 0; var2 < var0.length; var2++)
for(var2 = 0; var2 < var0.length; var2++)
var0[var2] = ((var2 == 0) ? 0.0D : var0[var2 - 1]) + var0[var2];
return var0;
}
public static int getRandomForDistributionIntegral(Random var0, double[] var1) {
double var2 = var0.nextDouble();
for (int var4 = 0; var4 < var1.length; var4++) {
if (var2 < var1[var4])
for(int var4 = 0; var4 < var1.length; var4++) {
if(var2 < var1[var4])
return var4;
}
return var1.length;
@@ -567,10 +567,10 @@ public class MCAMth {
public static double[] binNormalDistribution(double var0, double var2, double var4, int var6, int var7) {
double[] var8 = new double[var7 - var6 + 1];
int var9 = 0;
for (int var10 = var6; var10 <= var7; var10++) {
for(int var10 = var6; var10 <= var7; var10++) {
var8[var9] = Math.max(0.0D, var0 *
StrictMath.exp(-(var10 - var4) * (var10 - var4) / 2.0D * var2 * var2));
StrictMath.exp(-(var10 - var4) * (var10 - var4) / 2.0D * var2 * var2));
var9++;
}
return var8;
@@ -579,11 +579,11 @@ public class MCAMth {
public static double[] binBiModalNormalDistribution(double var0, double var2, double var4, double var6, double var8, double var10, int var12, int var13) {
double[] var14 = new double[var13 - var12 + 1];
int var15 = 0;
for (int var16 = var12; var16 <= var13; var16++) {
for(int var16 = var12; var16 <= var13; var16++) {
var14[var15] = Math.max(0.0D, var0 *
StrictMath.exp(-(var16 - var4) * (var16 - var4) / 2.0D * var2 * var2) + var6 *
StrictMath.exp(-(var16 - var10) * (var16 - var10) / 2.0D * var8 * var8));
StrictMath.exp(-(var16 - var4) * (var16 - var4) / 2.0D * var2 * var2) + var6 *
StrictMath.exp(-(var16 - var10) * (var16 - var10) / 2.0D * var8 * var8));
var15++;
}
return var14;
@@ -592,7 +592,7 @@ public class MCAMth {
public static double[] binLogDistribution(double var0, double var2, int var4, int var5) {
double[] var6 = new double[var5 - var4 + 1];
int var7 = 0;
for (int var8 = var4; var8 <= var5; var8++) {
for(int var8 = var4; var8 <= var5; var8++) {
var6[var7] = Math.max(var0 * StrictMath.log(var8) + var2, 0.0D);
var7++;
}
@@ -610,15 +610,15 @@ public class MCAMth {
public static double lerp2(double var0, double var2, double var4, double var6, double var8, double var10) {
return lerp(var2,
lerp(var0, var4, var6),
lerp(var0, var8, var10));
lerp(var0, var4, var6),
lerp(var0, var8, var10));
}
public static double lerp3(double var0, double var2, double var4, double var6, double var8, double var10, double var12, double var14, double var16, double var18, double var20) {
return lerp(var4,
lerp2(var0, var2, var6, var8, var10, var12),
lerp2(var0, var2, var14, var16, var18, var20));
lerp2(var0, var2, var6, var8, var10, var12),
lerp2(var0, var2, var14, var16, var18, var20));
}
public static double smoothstep(double var0) {
@@ -630,7 +630,7 @@ public class MCAMth {
}
public static int sign(double var0) {
if (var0 == 0.0D)
if(var0 == 0.0D)
return 0;
return (var0 > 0.0D) ? 1 : -1;
}
@@ -646,18 +646,18 @@ public class MCAMth {
@Deprecated
public static float rotlerp(float var0, float var1, float var2) {
float var3 = var1 - var0;
while (var3 < -180.0F)
while(var3 < -180.0F)
var3 += 360.0F;
while (var3 >= 180.0F)
while(var3 >= 180.0F)
var3 -= 360.0F;
return var0 + var2 * var3;
}
@Deprecated
public static float rotWrap(double var0) {
while (var0 >= 180.0D)
while(var0 >= 180.0D)
var0 -= 360.0D;
while (var0 < -180.0D)
while(var0 < -180.0D)
var0 += 360.0D;
return (float) var0;
}

View File

@@ -61,13 +61,13 @@ public class MCAPalettedContainer<T> implements MCAPaletteResize<T> {
}
private void setBits(int var0) {
if (var0 == this.bits)
if(var0 == this.bits)
return;
this.bits = var0;
if (this.bits <= 4) {
if(this.bits <= 4) {
this.bits = 4;
this.palette = new MCALinearPalette<>(this.registry, this.bits, this, this.reader);
} else if (this.bits < 9) {
} else if(this.bits < 9) {
this.palette = new MCAHashMapPalette<>(this.registry, this.bits, this, this.reader, this.writer);
} else {
this.palette = this.globalPalette;
@@ -81,9 +81,9 @@ public class MCAPalettedContainer<T> implements MCAPaletteResize<T> {
MCABitStorage var2 = this.storage;
MCAPalette<T> var3 = this.palette;
setBits(var0);
for (int var4 = 0; var4 < var2.getSize(); var4++) {
for(int var4 = 0; var4 < var2.getSize(); var4++) {
T var5 = var3.valueFor(var2.get(var4));
if (var5 != null)
if(var5 != null)
set(var4, var5);
}
return this.palette.idFor(var1);
@@ -124,21 +124,21 @@ public class MCAPalettedContainer<T> implements MCAPaletteResize<T> {
public void read(ListTag var0, long[] var1) {
int var2 = Math.max(4, MCAMth.ceillog2(var0.size()));
if (var2 != this.bits)
if(var2 != this.bits)
setBits(var2);
this.palette.read(var0);
int var3 = var1.length * 64 / 4096;
if (this.palette == this.globalPalette) {
if(this.palette == this.globalPalette) {
MCAPalette<T> var4 = new MCAHashMapPalette<>(this.registry, var2, this.dummyPaletteResize, this.reader, this.writer);
var4.read(var0);
MCABitStorage var5 = new MCABitStorage(var2, 4096, var1);
for (int var6 = 0; var6 < 4096; var6++)
for(int var6 = 0; var6 < 4096; var6++)
this.storage.set(var6, this.globalPalette.idFor(var4.valueFor(var5.get(var6))));
} else if (var3 == this.bits) {
} else if(var3 == this.bits) {
System.arraycopy(var1, 0, this.storage.getRaw(), 0, var1.length);
} else {
MCABitStorage var4 = new MCABitStorage(var3, 4096, var1);
for (int var5 = 0; var5 < 4096; var5++)
for(int var5 = 0; var5 < 4096; var5++)
this.storage.set(var5, var4.get(var5));
}
}
@@ -148,9 +148,9 @@ public class MCAPalettedContainer<T> implements MCAPaletteResize<T> {
T var4 = this.defaultValue;
int var5 = var3.idFor(this.defaultValue);
int[] var6 = new int[4096];
for (int i = 0; i < 4096; i++) {
for(int i = 0; i < 4096; i++) {
T t = get(i);
if (t != var4) {
if(t != var4) {
var4 = t;
var5 = var3.idFor(t);
}
@@ -161,7 +161,7 @@ public class MCAPalettedContainer<T> implements MCAPaletteResize<T> {
var0.put(var1, paletteList);
int var8 = Math.max(4, MCAMth.ceillog2(paletteList.size()));
MCABitStorage var9 = new MCABitStorage(var8, 4096);
for (int var10 = 0; var10 < var6.length; var10++) {
for(int var10 = 0; var10 < var6.length; var10++) {
var9.set(var10, var6[var10]);
}
var0.putLongArray(var2, var9.getRaw());

View File

@@ -24,13 +24,14 @@ import java.lang.reflect.Array;
* ArrayTag is an abstract representation of any NBT array tag.
* For implementations see {@link ByteArrayTag}, {@link IntArrayTag}, {@link LongArrayTag}.
*
* @param <T> The array type.
* @param <T>
* The array type.
*/
public abstract class ArrayTag<T> extends Tag<T> {
public ArrayTag(T value) {
super(value);
if (!value.getClass().isArray()) {
if(!value.getClass().isArray()) {
throw new UnsupportedOperationException("type of array tag must be an array");
}
}
@@ -56,7 +57,7 @@ public abstract class ArrayTag<T> extends Tag<T> {
protected String arrayToString(@SuppressWarnings("SameParameterValue") String prefix, @SuppressWarnings("SameParameterValue") String suffix) {
StringBuilder sb = new StringBuilder("[").append(prefix).append("".equals(prefix) ? "" : ";");
for (int i = 0; i < length(); i++) {
for(int i = 0; i < length(); i++) {
sb.append(i == 0 ? "" : ",").append(Array.get(getValue(), i)).append(suffix);
}
sb.append("]");

View File

@@ -89,7 +89,7 @@ public class CompoundTag extends Tag<Map<String, Tag<?>>> implements Iterable<Ma
public <C extends Tag<?>> C get(String key, Class<C> type) {
Tag<?> t = getValue().get(key);
if (t != null) {
if(t != null) {
return type.cast(t);
}
return null;
@@ -254,10 +254,10 @@ public class CompoundTag extends Tag<Map<String, Tag<?>>> implements Iterable<Ma
public String valueToString(int maxDepth) {
StringBuilder sb = new StringBuilder("{");
boolean first = true;
for (Map.Entry<String, Tag<?>> e : getValue().entrySet()) {
for(Map.Entry<String, Tag<?>> e : getValue().entrySet()) {
sb.append(first ? "" : ",")
.append(escapeString(e.getKey(), false)).append(":")
.append(e.getValue().toString(decrementMaxDepth(maxDepth)));
.append(escapeString(e.getKey(), false)).append(":")
.append(e.getValue().toString(decrementMaxDepth(maxDepth)));
first = false;
}
sb.append("}");
@@ -266,15 +266,15 @@ public class CompoundTag extends Tag<Map<String, Tag<?>>> implements Iterable<Ma
@Override
public boolean equals(Object other) {
if (this == other) {
if(this == other) {
return true;
}
if (!super.equals(other) || size() != ((CompoundTag) other).size()) {
if(!super.equals(other) || size() != ((CompoundTag) other).size()) {
return false;
}
for (Map.Entry<String, Tag<?>> e : getValue().entrySet()) {
for(Map.Entry<String, Tag<?>> e : getValue().entrySet()) {
Tag<?> v;
if ((v = ((CompoundTag) other).get(e.getKey())) == null || !e.getValue().equals(v)) {
if((v = ((CompoundTag) other).get(e.getKey())) == null || !e.getValue().equals(v)) {
return false;
}
}
@@ -289,7 +289,7 @@ public class CompoundTag extends Tag<Map<String, Tag<?>>> implements Iterable<Ma
@Override
public CompoundTag clone() {
CompoundTag copy = new CompoundTag();
for (Map.Entry<String, Tag<?>> e : getValue().entrySet()) {
for(Map.Entry<String, Tag<?>> e : getValue().entrySet()) {
copy.put(e.getKey(), e.getValue().clone());
}
return copy;

View File

@@ -48,13 +48,16 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
}
/**
* @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}
* @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) {
if(typeClass == EndTag.class) {
throw new IllegalArgumentException("cannot create ListTag with EndTag elements");
}
this.typeClass = Objects.requireNonNull(typeClass);
@@ -78,8 +81,10 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
/**
* <p>Creates an empty mutable list to be used as empty value of ListTags.</p>
*
* @param <T> Type of the list elements
* @param initialCapacity The initial capacity of the returned List
* @param <T>
* Type of the list elements
* @param initialCapacity
* The initial capacity of the returned List
* @return An instance of {@link List} with an initial capacity of 3
*/
private static <T> List<T> createEmptyValue(@SuppressWarnings("SameParameterValue") int initialCapacity) {
@@ -141,7 +146,8 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
/**
* Adds a Tag to this ListTag after the last index.
*
* @param t The element to be added.
* @param t
* The element to be added.
*/
public void add(T t) {
add(size(), t);
@@ -149,26 +155,26 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
public void add(int index, T t) {
Objects.requireNonNull(t);
if (typeClass == null || typeClass == EndTag.class) {
if(typeClass == null || typeClass == EndTag.class) {
typeClass = t.getClass();
} else if (typeClass != t.getClass()) {
} else if(typeClass != t.getClass()) {
throw new ClassCastException(
String.format("cannot add %s to ListTag<%s>",
t.getClass().getSimpleName(),
typeClass.getSimpleName()));
String.format("cannot add %s to ListTag<%s>",
t.getClass().getSimpleName(),
typeClass.getSimpleName()));
}
getValue().add(index, t);
}
public void addAll(Collection<T> t) {
for (T tt : t) {
for(T tt : t) {
add(tt);
}
}
public void addAll(int index, Collection<T> t) {
int i = 0;
for (T tt : t) {
for(T tt : t) {
add(index + i, tt);
i++;
}
@@ -287,7 +293,7 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
@Override
public String valueToString(int maxDepth) {
StringBuilder sb = new StringBuilder("{\"type\":\"").append(getTypeClass().getSimpleName()).append("\",\"list\":[");
for (int i = 0; i < size(); i++) {
for(int i = 0; i < size(); i++) {
sb.append(i > 0 ? "," : "").append(get(i).valueToString(decrementMaxDepth(maxDepth)));
}
sb.append("]}");
@@ -296,14 +302,14 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
@Override
public boolean equals(Object other) {
if (this == other) {
if(this == other) {
return true;
}
if (!super.equals(other) || size() != ((ListTag<?>) other).size() || getTypeClass() != ((ListTag<?>) other).getTypeClass()) {
if(!super.equals(other) || size() != ((ListTag<?>) other).size() || getTypeClass() != ((ListTag<?>) other).getTypeClass()) {
return false;
}
for (int i = 0; i < size(); i++) {
if (!get(i).equals(((ListTag<?>) other).get(i))) {
for(int i = 0; i < size(); i++) {
if(!get(i).equals(((ListTag<?>) other).get(i))) {
return false;
}
}
@@ -326,7 +332,7 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
ListTag<T> copy = new ListTag<>();
// assure type safety for clone
copy.typeClass = typeClass;
for (T t : getValue()) {
for(T t : getValue()) {
copy.add((T) t.clone());
}
return copy;
@@ -335,19 +341,19 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
//TODO: make private
@SuppressWarnings("unchecked")
public void addUnchecked(Tag<?> tag) {
if (typeClass != null && typeClass != tag.getClass() && typeClass != EndTag.class) {
if(typeClass != null && typeClass != tag.getClass() && typeClass != EndTag.class) {
throw new IllegalArgumentException(String.format(
"cannot add %s to ListTag<%s>",
tag.getClass().getSimpleName(), typeClass.getSimpleName()));
"cannot add %s to ListTag<%s>",
tag.getClass().getSimpleName(), typeClass.getSimpleName()));
}
add(size(), (T) tag);
}
private void checkTypeClass(Class<?> clazz) {
if (typeClass != null && typeClass != EndTag.class && typeClass != clazz) {
if(typeClass != null && typeClass != EndTag.class && typeClass != clazz) {
throw new ClassCastException(String.format(
"cannot cast ListTag<%s> to ListTag<%s>",
typeClass.getSimpleName(), clazz.getSimpleName()));
"cannot cast ListTag<%s> to ListTag<%s>",
typeClass.getSimpleName(), clazz.getSimpleName()));
}
}
}

View File

@@ -140,7 +140,7 @@ class NonNullEntrySet<K, V> implements Set<Map.Entry<K, V>> {
@Override
public V setValue(V value) {
if (value == null) {
if(value == null) {
throw new NullPointerException(getClass().getSimpleName() + " does not allow setting null");
}
return entry.setValue(value);

View File

@@ -49,7 +49,8 @@ import java.util.regex.Pattern;
* is no guarantee that {@code MaxDepthReachedException}s are thrown for them. The respective class
* will document this behavior accordingly.</p>
*
* @param <T> The type of the contained value
* @param <T>
* The type of the contained value
*/
public abstract class Tag<T> implements Cloneable {
@@ -79,7 +80,8 @@ public abstract class Tag<T> implements Cloneable {
* Initializes this Tag with some value. If the value is {@code null}, it will
* throw a {@code NullPointerException}
*
* @param value The value to be set for this Tag.
* @param value
* The value to be set for this Tag.
*/
public Tag(T value) {
setValue(value);
@@ -89,21 +91,23 @@ public abstract class Tag<T> implements Cloneable {
* 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.
* @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()) {
while(m.find()) {
m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
}
m.appendTail(sb);
m = NON_QUOTE_PATTERN.matcher(s);
if (!lenient || !m.matches()) {
if(!lenient || !m.matches()) {
sb.insert(0, "\"").append("\"");
}
return sb.toString();
@@ -124,8 +128,10 @@ public abstract class Tag<T> implements Cloneable {
/**
* Sets the value for this Tag directly.
*
* @param value The value to be set.
* @throws NullPointerException If the value is null
* @param value
* The value to be set.
* @throws NullPointerException
* If the value is null
*/
protected void setValue(T value) {
this.value = checkValue(value);
@@ -134,9 +140,11 @@ public abstract class Tag<T> implements Cloneable {
/**
* Checks if the value {@code value} is {@code null}.
*
* @param value The value to check
* @param value
* The value to check
* @return The parameter {@code value}
* @throws NullPointerException If {@code value} was {@code null}
* @throws NullPointerException
* If {@code value} was {@code null}
*/
protected T checkValue(T value) {
return Objects.requireNonNull(value);
@@ -145,7 +153,8 @@ public abstract class Tag<T> implements Cloneable {
/**
* Calls {@link Tag#toString(int)} with an initial depth of {@code 0}.
*
* @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
* @throws MaxDepthReachedException
* If the maximum nesting depth is exceeded.
* @see Tag#toString(int)
*/
@Override
@@ -156,20 +165,23 @@ public abstract class Tag<T> implements Cloneable {
/**
* Creates a string representation of this Tag in a valid JSON format.
*
* @param maxDepth The maximum nesting depth.
* @param maxDepth
* The maximum nesting depth.
* @return The string representation of this Tag.
* @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
* @throws MaxDepthReachedException
* If the maximum nesting depth is exceeded.
*/
public String toString(int maxDepth) {
return "{\"type\":\"" + getClass().getSimpleName() + "\"," +
"\"value\":" + valueToString(maxDepth) + "}";
"\"value\":" + valueToString(maxDepth) + "}";
}
/**
* Calls {@link Tag#valueToString(int)} with {@link Tag#DEFAULT_MAX_DEPTH}.
*
* @return The string representation of the value of this Tag.
* @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
* @throws MaxDepthReachedException
* If the maximum nesting depth is exceeded.
*/
public String valueToString() {
return valueToString(DEFAULT_MAX_DEPTH);
@@ -178,9 +190,11 @@ public abstract class Tag<T> implements Cloneable {
/**
* Returns a JSON representation of the value of this Tag.
*
* @param maxDepth The maximum nesting depth.
* @param maxDepth
* The maximum nesting depth.
* @return The string representation of the value of this Tag.
* @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
* @throws MaxDepthReachedException
* If the maximum nesting depth is exceeded.
*/
public abstract String valueToString(int maxDepth);
@@ -190,7 +204,8 @@ public abstract class Tag<T> implements Cloneable {
* Custom Tag implementations should overwrite this but check the result
* of this {@code super}-method while comparing.
*
* @param other The Tag to compare to.
* @param other
* The Tag to compare to.
* @return {@code true} if they are equal based on the conditions mentioned above.
*/
@Override