base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,196 @@
package net.minecraft.nbt;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.util.ReportedException;
public class CompressedStreamTools
{
/**
* Load the gzipped compound from the inputstream.
*/
public static NBTTagCompound readCompressed(InputStream is) throws IOException
{
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(is)));
NBTTagCompound nbttagcompound;
try
{
nbttagcompound = read(datainputstream, NBTSizeTracker.INFINITE);
}
finally
{
datainputstream.close();
}
return nbttagcompound;
}
/**
* Write the compound, gzipped, to the outputstream.
*/
public static void writeCompressed(NBTTagCompound compound, OutputStream outputStream) throws IOException
{
DataOutputStream dataoutputstream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(outputStream)));
try
{
write(compound, dataoutputstream);
}
finally
{
dataoutputstream.close();
}
}
public static void safeWrite(NBTTagCompound compound, File fileIn) throws IOException
{
File file1 = new File(fileIn.getAbsolutePath() + "_tmp");
if (file1.exists())
{
file1.delete();
}
write(compound, file1);
if (fileIn.exists())
{
fileIn.delete();
}
if (fileIn.exists())
{
throw new IOException("Failed to delete " + fileIn);
}
else
{
file1.renameTo(fileIn);
}
}
/**
* Reads from a CompressedStream.
*/
public static NBTTagCompound read(DataInputStream inputStream) throws IOException
{
return read(inputStream, NBTSizeTracker.INFINITE);
}
/**
* Reads the given DataInput, constructs, and returns an NBTTagCompound with the data from the DataInput
*/
public static NBTTagCompound read(DataInput input, NBTSizeTracker accounter) throws IOException
{
NBTBase nbtbase = read(input, 0, accounter);
if (nbtbase instanceof NBTTagCompound)
{
return (NBTTagCompound)nbtbase;
}
else
{
throw new IOException("Root tag must be a named compound tag");
}
}
public static void write(NBTTagCompound compound, DataOutput output) throws IOException
{
writeTag(compound, output);
}
private static void writeTag(NBTBase tag, DataOutput output) throws IOException
{
output.writeByte(tag.getId());
if (tag.getId() != 0)
{
output.writeUTF("");
tag.write(output);
}
}
private static NBTBase read(DataInput input, int depth, NBTSizeTracker accounter) throws IOException
{
byte b0 = input.readByte();
accounter.read(8); // Forge: Count everything!
if (b0 == 0)
{
return new NBTTagEnd();
}
else
{
NBTSizeTracker.readUTF(accounter, input.readUTF()); //Forge: Count this string.
accounter.read(32); //Forge: 4 extra bytes for the object allocation.
NBTBase nbtbase = NBTBase.createNewByType(b0);
try
{
nbtbase.read(input, depth, accounter);
return nbtbase;
}
catch (IOException ioexception)
{
CrashReport crashreport = CrashReport.makeCrashReport(ioexception, "Loading NBT data");
CrashReportCategory crashreportcategory = crashreport.makeCategory("NBT Tag");
crashreportcategory.addCrashSection("Tag type", Byte.valueOf(b0));
throw new ReportedException(crashreport);
}
}
}
public static void write(NBTTagCompound compound, File fileIn) throws IOException
{
DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(fileIn));
try
{
write(compound, dataoutputstream);
}
finally
{
dataoutputstream.close();
}
}
@Nullable
public static NBTTagCompound read(File fileIn) throws IOException
{
if (!fileIn.exists())
{
return null;
}
else
{
DataInputStream datainputstream = new DataInputStream(new FileInputStream(fileIn));
NBTTagCompound nbttagcompound;
try
{
nbttagcompound = read(datainputstream, NBTSizeTracker.INFINITE);
}
finally
{
datainputstream.close();
}
return nbttagcompound;
}
}
}

View File

@@ -0,0 +1,456 @@
package net.minecraft.nbt;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.regex.Pattern;
public class JsonToNBT
{
private static final Pattern DOUBLE_PATTERN_NOSUFFIX = Pattern.compile("[-+]?(?:[0-9]+[.]|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?", 2);
private static final Pattern DOUBLE_PATTERN = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?d", 2);
private static final Pattern FLOAT_PATTERN = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?f", 2);
private static final Pattern BYTE_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)b", 2);
private static final Pattern LONG_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)l", 2);
private static final Pattern SHORT_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)s", 2);
private static final Pattern INT_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)");
private final String string;
private int cursor;
public static NBTTagCompound getTagFromJson(String jsonString) throws NBTException
{
return (new JsonToNBT(jsonString)).readSingleStruct();
}
@VisibleForTesting
NBTTagCompound readSingleStruct() throws NBTException
{
NBTTagCompound nbttagcompound = this.readStruct();
this.skipWhitespace();
if (this.canRead())
{
++this.cursor;
throw this.exception("Trailing data found");
}
else
{
return nbttagcompound;
}
}
@VisibleForTesting
JsonToNBT(String stringIn)
{
this.string = stringIn;
}
protected String readKey() throws NBTException
{
this.skipWhitespace();
if (!this.canRead())
{
throw this.exception("Expected key");
}
else
{
return this.peek() == '"' ? this.readQuotedString() : this.readString();
}
}
private NBTException exception(String message)
{
return new NBTException(message, this.string, this.cursor);
}
protected NBTBase readTypedValue() throws NBTException
{
this.skipWhitespace();
if (this.peek() == '"')
{
return new NBTTagString(this.readQuotedString());
}
else
{
String s = this.readString();
if (s.isEmpty())
{
throw this.exception("Expected value");
}
else
{
return this.type(s);
}
}
}
private NBTBase type(String stringIn)
{
try
{
if (FLOAT_PATTERN.matcher(stringIn).matches())
{
return new NBTTagFloat(Float.parseFloat(stringIn.substring(0, stringIn.length() - 1)));
}
if (BYTE_PATTERN.matcher(stringIn).matches())
{
return new NBTTagByte(Byte.parseByte(stringIn.substring(0, stringIn.length() - 1)));
}
if (LONG_PATTERN.matcher(stringIn).matches())
{
return new NBTTagLong(Long.parseLong(stringIn.substring(0, stringIn.length() - 1)));
}
if (SHORT_PATTERN.matcher(stringIn).matches())
{
return new NBTTagShort(Short.parseShort(stringIn.substring(0, stringIn.length() - 1)));
}
if (INT_PATTERN.matcher(stringIn).matches())
{
return new NBTTagInt(Integer.parseInt(stringIn));
}
if (DOUBLE_PATTERN.matcher(stringIn).matches())
{
return new NBTTagDouble(Double.parseDouble(stringIn.substring(0, stringIn.length() - 1)));
}
if (DOUBLE_PATTERN_NOSUFFIX.matcher(stringIn).matches())
{
return new NBTTagDouble(Double.parseDouble(stringIn));
}
if ("true".equalsIgnoreCase(stringIn))
{
return new NBTTagByte((byte)1);
}
if ("false".equalsIgnoreCase(stringIn))
{
return new NBTTagByte((byte)0);
}
}
catch (NumberFormatException var3)
{
;
}
return new NBTTagString(stringIn);
}
private String readQuotedString() throws NBTException
{
int i = ++this.cursor;
StringBuilder stringbuilder = null;
boolean flag = false;
while (this.canRead())
{
char c0 = this.pop();
if (flag)
{
if (c0 != '\\' && c0 != '"')
{
throw this.exception("Invalid escape of '" + c0 + "'");
}
flag = false;
}
else
{
if (c0 == '\\')
{
flag = true;
if (stringbuilder == null)
{
stringbuilder = new StringBuilder(this.string.substring(i, this.cursor - 1));
}
continue;
}
if (c0 == '"')
{
return stringbuilder == null ? this.string.substring(i, this.cursor - 1) : stringbuilder.toString();
}
}
if (stringbuilder != null)
{
stringbuilder.append(c0);
}
}
throw this.exception("Missing termination quote");
}
private String readString()
{
int i;
for (i = this.cursor; this.canRead() && this.isAllowedInKey(this.peek()); ++this.cursor)
{
;
}
return this.string.substring(i, this.cursor);
}
protected NBTBase readValue() throws NBTException
{
this.skipWhitespace();
if (!this.canRead())
{
throw this.exception("Expected value");
}
else
{
char c0 = this.peek();
if (c0 == '{')
{
return this.readStruct();
}
else
{
return c0 == '[' ? this.readList() : this.readTypedValue();
}
}
}
protected NBTBase readList() throws NBTException
{
return this.canRead(2) && this.peek(1) != '"' && this.peek(2) == ';' ? this.readArrayTag() : this.readListTag();
}
protected NBTTagCompound readStruct() throws NBTException
{
this.expect('{');
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.skipWhitespace();
while (this.canRead() && this.peek() != '}')
{
String s = this.readKey();
if (s.isEmpty())
{
throw this.exception("Expected non-empty key");
}
this.expect(':');
nbttagcompound.setTag(s, this.readValue());
if (!this.hasElementSeparator())
{
break;
}
if (!this.canRead())
{
throw this.exception("Expected key");
}
}
this.expect('}');
return nbttagcompound;
}
private NBTBase readListTag() throws NBTException
{
this.expect('[');
this.skipWhitespace();
if (!this.canRead())
{
throw this.exception("Expected value");
}
else
{
NBTTagList nbttaglist = new NBTTagList();
int i = -1;
while (this.peek() != ']')
{
NBTBase nbtbase = this.readValue();
int j = nbtbase.getId();
if (i < 0)
{
i = j;
}
else if (j != i)
{
throw this.exception("Unable to insert " + NBTBase.getTagTypeName(j) + " into ListTag of type " + NBTBase.getTagTypeName(i));
}
nbttaglist.appendTag(nbtbase);
if (!this.hasElementSeparator())
{
break;
}
if (!this.canRead())
{
throw this.exception("Expected value");
}
}
this.expect(']');
return nbttaglist;
}
}
private NBTBase readArrayTag() throws NBTException
{
this.expect('[');
char c0 = this.pop();
this.pop();
this.skipWhitespace();
if (!this.canRead())
{
throw this.exception("Expected value");
}
else if (c0 == 'B')
{
return new NBTTagByteArray(this.readArray((byte)7, (byte)1));
}
else if (c0 == 'L')
{
return new NBTTagLongArray(this.readArray((byte)12, (byte)4));
}
else if (c0 == 'I')
{
return new NBTTagIntArray(this.readArray((byte)11, (byte)3));
}
else
{
throw this.exception("Invalid array type '" + c0 + "' found");
}
}
private <T extends Number> List<T> readArray(byte p_193603_1_, byte p_193603_2_) throws NBTException
{
List<T> list = Lists.<T>newArrayList();
while (true)
{
if (this.peek() != ']')
{
NBTBase nbtbase = this.readValue();
int i = nbtbase.getId();
if (i != p_193603_2_)
{
throw this.exception("Unable to insert " + NBTBase.getTagTypeName(i) + " into " + NBTBase.getTagTypeName(p_193603_1_));
}
if (p_193603_2_ == 1)
{
list.add((T)Byte.valueOf(((NBTPrimitive)nbtbase).getByte()));
}
else if (p_193603_2_ == 4)
{
list.add((T)Long.valueOf(((NBTPrimitive)nbtbase).getLong()));
}
else
{
list.add((T)Integer.valueOf(((NBTPrimitive)nbtbase).getInt()));
}
if (this.hasElementSeparator())
{
if (!this.canRead())
{
throw this.exception("Expected value");
}
continue;
}
}
this.expect(']');
return list;
}
}
private void skipWhitespace()
{
while (this.canRead() && Character.isWhitespace(this.peek()))
{
++this.cursor;
}
}
private boolean hasElementSeparator()
{
this.skipWhitespace();
if (this.canRead() && this.peek() == ',')
{
++this.cursor;
this.skipWhitespace();
return true;
}
else
{
return false;
}
}
private void expect(char expected) throws NBTException
{
this.skipWhitespace();
boolean flag = this.canRead();
if (flag && this.peek() == expected)
{
++this.cursor;
}
else
{
throw new NBTException("Expected '" + expected + "' but got '" + (flag ? this.peek() : "<EOF>") + "'", this.string, this.cursor + 1);
}
}
protected boolean isAllowedInKey(char charIn)
{
return charIn >= '0' && charIn <= '9' || charIn >= 'A' && charIn <= 'Z' || charIn >= 'a' && charIn <= 'z' || charIn == '_' || charIn == '-' || charIn == '.' || charIn == '+';
}
private boolean canRead(int p_193608_1_)
{
return this.cursor + p_193608_1_ < this.string.length();
}
boolean canRead()
{
return this.canRead(0);
}
private char peek(int p_193597_1_)
{
return this.string.charAt(this.cursor + p_193597_1_);
}
private char peek()
{
return this.peek(0);
}
private char pop()
{
return this.string.charAt(this.cursor++);
}
}

View File

@@ -0,0 +1,127 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public abstract class NBTBase
{
public static final String[] NBT_TYPES = new String[] {"END", "BYTE", "SHORT", "INT", "LONG", "FLOAT", "DOUBLE", "BYTE[]", "STRING", "LIST", "COMPOUND", "INT[]", "LONG[]"};
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
abstract void write(DataOutput output) throws IOException;
abstract void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException;
public abstract String toString();
/**
* Gets the type byte for the tag.
*/
public abstract byte getId();
/**
* Creates a new NBTBase object that corresponds with the passed in id.
*/
protected static NBTBase createNewByType(byte id)
{
switch (id)
{
case 0:
return new NBTTagEnd();
case 1:
return new NBTTagByte();
case 2:
return new NBTTagShort();
case 3:
return new NBTTagInt();
case 4:
return new NBTTagLong();
case 5:
return new NBTTagFloat();
case 6:
return new NBTTagDouble();
case 7:
return new NBTTagByteArray();
case 8:
return new NBTTagString();
case 9:
return new NBTTagList();
case 10:
return new NBTTagCompound();
case 11:
return new NBTTagIntArray();
case 12:
return new NBTTagLongArray();
default:
return null;
}
}
public static String getTagTypeName(int p_193581_0_)
{
switch (p_193581_0_)
{
case 0:
return "TAG_End";
case 1:
return "TAG_Byte";
case 2:
return "TAG_Short";
case 3:
return "TAG_Int";
case 4:
return "TAG_Long";
case 5:
return "TAG_Float";
case 6:
return "TAG_Double";
case 7:
return "TAG_Byte_Array";
case 8:
return "TAG_String";
case 9:
return "TAG_List";
case 10:
return "TAG_Compound";
case 11:
return "TAG_Int_Array";
case 12:
return "TAG_Long_Array";
case 99:
return "Any Numeric Tag";
default:
return "UNKNOWN";
}
}
/**
* Creates a clone of the tag.
*/
public abstract NBTBase copy();
/**
* Return whether this compound has no tags.
*/
public boolean hasNoTags()
{
return false;
}
public boolean equals(Object p_equals_1_)
{
return p_equals_1_ instanceof NBTBase && this.getId() == ((NBTBase)p_equals_1_).getId();
}
public int hashCode()
{
return this.getId();
}
protected String getString()
{
return this.toString();
}
}

View File

@@ -0,0 +1,24 @@
package net.minecraft.nbt;
public class NBTException extends Exception
{
public NBTException(String message, String json, int p_i47523_3_)
{
super(message + " at: " + slice(json, p_i47523_3_));
}
private static String slice(String json, int p_193592_1_)
{
StringBuilder stringbuilder = new StringBuilder();
int i = Math.min(json.length(), p_193592_1_);
if (i > 35)
{
stringbuilder.append("...");
}
stringbuilder.append(json.substring(Math.max(0, i - 35), i));
stringbuilder.append("<--[HERE]");
return stringbuilder.toString();
}
}

View File

@@ -0,0 +1,16 @@
package net.minecraft.nbt;
public abstract class NBTPrimitive extends NBTBase
{
public abstract long getLong();
public abstract int getInt();
public abstract short getShort();
public abstract byte getByte();
public abstract double getDouble();
public abstract float getFloat();
}

View File

@@ -0,0 +1,64 @@
package net.minecraft.nbt;
public class NBTSizeTracker
{
public static final NBTSizeTracker INFINITE = new NBTSizeTracker(0L)
{
/**
* Tracks the reading of the given amount of bits(!)
*/
public void read(long bits)
{
}
};
private final long max;
private long read;
public NBTSizeTracker(long max)
{
this.max = max;
}
/**
* Tracks the reading of the given amount of bits(!)
*/
public void read(long bits)
{
this.read += bits / 8L;
if (this.read > this.max)
{
throw new RuntimeException("Tried to read NBT tag that was too big; tried to allocate: " + this.read + "bytes where max allowed: " + this.max);
}
}
/*
* UTF8 is not a simple encoding system, each character can be either
* 1, 2, or 3 bytes. Depending on where it's numerical value falls.
* We have to count up each character individually to see the true
* length of the data.
*
* Basic concept is that it uses the MSB of each byte as a 'read more' signal.
* So it has to shift each 7-bit segment.
*
* This will accurately count the correct byte length to encode this string, plus the 2 bytes for it's length prefix.
*/
public static void readUTF(NBTSizeTracker tracker, String data)
{
tracker.read(16); //Header length
if (data == null)
return;
int len = data.length();
int utflen = 0;
for (int i = 0; i < len; i++)
{
int c = data.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) utflen += 1;
else if (c > 0x07FF) utflen += 3;
else utflen += 2;
}
tracker.read(8 * utflen);
}
}

View File

@@ -0,0 +1,95 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagByte extends NBTPrimitive
{
/** The byte value for the tag. */
private byte data;
NBTTagByte()
{
}
public NBTTagByte(byte data)
{
this.data = data;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeByte(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(72L);
this.data = input.readByte();
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 1;
}
public String toString()
{
return this.data + "b";
}
/**
* Creates a clone of the tag.
*/
public NBTTagByte copy()
{
return new NBTTagByte(this.data);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && this.data == ((NBTTagByte)p_equals_1_).data;
}
public int hashCode()
{
return super.hashCode() ^ this.data;
}
public long getLong()
{
return (long)this.data;
}
public int getInt()
{
return this.data;
}
public short getShort()
{
return (short)this.data;
}
public byte getByte()
{
return this.data;
}
public double getDouble()
{
return (double)this.data;
}
public float getFloat()
{
return (float)this.data;
}
}

View File

@@ -0,0 +1,108 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class NBTTagByteArray extends NBTBase
{
/** The byte array stored in the tag. */
private byte[] data;
NBTTagByteArray()
{
}
public NBTTagByteArray(byte[] data)
{
this.data = data;
}
public NBTTagByteArray(List<Byte> p_i47529_1_)
{
this(toArray(p_i47529_1_));
}
private static byte[] toArray(List<Byte> p_193589_0_)
{
byte[] abyte = new byte[p_193589_0_.size()];
for (int i = 0; i < p_193589_0_.size(); ++i)
{
Byte obyte = p_193589_0_.get(i);
abyte[i] = obyte == null ? 0 : obyte.byteValue();
}
return abyte;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeInt(this.data.length);
output.write(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(192L);
int i = input.readInt();
sizeTracker.read((long)(8 * i));
this.data = new byte[i];
input.readFully(this.data);
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 7;
}
public String toString()
{
StringBuilder stringbuilder = new StringBuilder("[B;");
for (int i = 0; i < this.data.length; ++i)
{
if (i != 0)
{
stringbuilder.append(',');
}
stringbuilder.append((int)this.data[i]).append('B');
}
return stringbuilder.append(']').toString();
}
/**
* Creates a clone of the tag.
*/
public NBTBase copy()
{
byte[] abyte = new byte[this.data.length];
System.arraycopy(this.data, 0, abyte, 0, this.data.length);
return new NBTTagByteArray(abyte);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && Arrays.equals(this.data, ((NBTTagByteArray)p_equals_1_).data);
}
public int hashCode()
{
return super.hashCode() ^ Arrays.hashCode(this.data);
}
public byte[] getByteArray()
{
return this.data;
}
}

View File

@@ -0,0 +1,648 @@
package net.minecraft.nbt;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.crash.ICrashReportDetail;
import net.minecraft.util.ReportedException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class NBTTagCompound extends NBTBase
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Pattern SIMPLE_VALUE = Pattern.compile("[A-Za-z0-9._+-]+");
/** The key-value pairs for the tag. Each key is a UTF string, each value is a tag. */
private final Map<String, NBTBase> tagMap = Maps.<String, NBTBase>newHashMap();
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
for (String s : this.tagMap.keySet())
{
NBTBase nbtbase = this.tagMap.get(s);
writeEntry(s, nbtbase, output);
}
output.writeByte(0);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(384L);
if (depth > 512)
{
throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512");
}
else
{
this.tagMap.clear();
byte b0;
while ((b0 = readType(input, sizeTracker)) != 0)
{
String s = readKey(input, sizeTracker);
sizeTracker.read((long)(224 + 16 * s.length()));
NBTBase nbtbase = readNBT(b0, s, input, depth + 1, sizeTracker);
if (this.tagMap.put(s, nbtbase) != null)
{
sizeTracker.read(288L);
}
}
}
}
/**
* Gets a set with the names of the keys in the tag compound.
*/
public Set<String> getKeySet()
{
return this.tagMap.keySet();
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 10;
}
public int getSize()
{
return this.tagMap.size();
}
/**
* Stores the given tag into the map with the given string key. This is mostly used to store tag lists.
*/
public void setTag(String key, NBTBase value)
{
this.tagMap.put(key, value);
}
/**
* Stores a new NBTTagByte with the given byte value into the map with the given string key.
*/
public void setByte(String key, byte value)
{
this.tagMap.put(key, new NBTTagByte(value));
}
/**
* Stores a new NBTTagShort with the given short value into the map with the given string key.
*/
public void setShort(String key, short value)
{
this.tagMap.put(key, new NBTTagShort(value));
}
/**
* Stores a new NBTTagInt with the given integer value into the map with the given string key.
*/
public void setInteger(String key, int value)
{
this.tagMap.put(key, new NBTTagInt(value));
}
/**
* Stores a new NBTTagLong with the given long value into the map with the given string key.
*/
public void setLong(String key, long value)
{
this.tagMap.put(key, new NBTTagLong(value));
}
public void setUniqueId(String key, UUID value)
{
this.setLong(key + "Most", value.getMostSignificantBits());
this.setLong(key + "Least", value.getLeastSignificantBits());
}
@Nullable
public UUID getUniqueId(String key)
{
return new UUID(this.getLong(key + "Most"), this.getLong(key + "Least"));
}
public boolean hasUniqueId(String key)
{
return this.hasKey(key + "Most", 99) && this.hasKey(key + "Least", 99);
}
/**
* Stores a new NBTTagFloat with the given float value into the map with the given string key.
*/
public void setFloat(String key, float value)
{
this.tagMap.put(key, new NBTTagFloat(value));
}
/**
* Stores a new NBTTagDouble with the given double value into the map with the given string key.
*/
public void setDouble(String key, double value)
{
this.tagMap.put(key, new NBTTagDouble(value));
}
/**
* Stores a new NBTTagString with the given string value into the map with the given string key.
*/
public void setString(String key, String value)
{
this.tagMap.put(key, new NBTTagString(value));
}
/**
* Stores a new NBTTagByteArray with the given array as data into the map with the given string key.
*/
public void setByteArray(String key, byte[] value)
{
this.tagMap.put(key, new NBTTagByteArray(value));
}
/**
* Stores a new NBTTagIntArray with the given array as data into the map with the given string key.
*/
public void setIntArray(String key, int[] value)
{
this.tagMap.put(key, new NBTTagIntArray(value));
}
/**
* Stores the given boolean value as a NBTTagByte, storing 1 for true and 0 for false, using the given string key.
*/
public void setBoolean(String key, boolean value)
{
this.setByte(key, (byte)(value ? 1 : 0));
}
/**
* gets a generic tag with the specified name
*/
public NBTBase getTag(String key)
{
return this.tagMap.get(key);
}
/**
* Gets the ID byte for the given tag key
*/
public byte getTagId(String key)
{
NBTBase nbtbase = this.tagMap.get(key);
return nbtbase == null ? 0 : nbtbase.getId();
}
/**
* Returns whether the given string has been previously stored as a key in the map.
*/
public boolean hasKey(String key)
{
return this.tagMap.containsKey(key);
}
/**
* Returns whether the given string has been previously stored as a key in this tag compound as a particular type,
* denoted by a parameter in the form of an ordinal. If the provided ordinal is 99, this method will match tag types
* representing numbers.
*/
public boolean hasKey(String key, int type)
{
int i = this.getTagId(key);
if (i == type)
{
return true;
}
else if (type != 99)
{
return false;
}
else
{
return i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6;
}
}
/**
* Retrieves a byte value using the specified key, or 0 if no such key was stored.
*/
public byte getByte(String key)
{
try
{
if (this.hasKey(key, 99))
{
return ((NBTPrimitive)this.tagMap.get(key)).getByte();
}
}
catch (ClassCastException var3)
{
;
}
return 0;
}
/**
* Retrieves a short value using the specified key, or 0 if no such key was stored.
*/
public short getShort(String key)
{
try
{
if (this.hasKey(key, 99))
{
return ((NBTPrimitive)this.tagMap.get(key)).getShort();
}
}
catch (ClassCastException var3)
{
;
}
return 0;
}
/**
* Retrieves an integer value using the specified key, or 0 if no such key was stored.
*/
public int getInteger(String key)
{
try
{
if (this.hasKey(key, 99))
{
return ((NBTPrimitive)this.tagMap.get(key)).getInt();
}
}
catch (ClassCastException var3)
{
;
}
return 0;
}
/**
* Retrieves a long value using the specified key, or 0 if no such key was stored.
*/
public long getLong(String key)
{
try
{
if (this.hasKey(key, 99))
{
return ((NBTPrimitive)this.tagMap.get(key)).getLong();
}
}
catch (ClassCastException var3)
{
;
}
return 0L;
}
/**
* Retrieves a float value using the specified key, or 0 if no such key was stored.
*/
public float getFloat(String key)
{
try
{
if (this.hasKey(key, 99))
{
return ((NBTPrimitive)this.tagMap.get(key)).getFloat();
}
}
catch (ClassCastException var3)
{
;
}
return 0.0F;
}
/**
* Retrieves a double value using the specified key, or 0 if no such key was stored.
*/
public double getDouble(String key)
{
try
{
if (this.hasKey(key, 99))
{
return ((NBTPrimitive)this.tagMap.get(key)).getDouble();
}
}
catch (ClassCastException var3)
{
;
}
return 0.0D;
}
/**
* Retrieves a string value using the specified key, or an empty string if no such key was stored.
*/
public String getString(String key)
{
try
{
if (this.hasKey(key, 8))
{
return ((NBTBase)this.tagMap.get(key)).getString();
}
}
catch (ClassCastException var3)
{
;
}
return "";
}
/**
* Retrieves a byte array using the specified key, or a zero-length array if no such key was stored.
*/
public byte[] getByteArray(String key)
{
try
{
if (this.hasKey(key, 7))
{
return ((NBTTagByteArray)this.tagMap.get(key)).getByteArray();
}
}
catch (ClassCastException classcastexception)
{
throw new ReportedException(this.createCrashReport(key, 7, classcastexception));
}
return new byte[0];
}
/**
* Retrieves an int array using the specified key, or a zero-length array if no such key was stored.
*/
public int[] getIntArray(String key)
{
try
{
if (this.hasKey(key, 11))
{
return ((NBTTagIntArray)this.tagMap.get(key)).getIntArray();
}
}
catch (ClassCastException classcastexception)
{
throw new ReportedException(this.createCrashReport(key, 11, classcastexception));
}
return new int[0];
}
/**
* Retrieves a NBTTagCompound subtag matching the specified key, or a new empty NBTTagCompound if no such key was
* stored.
*/
public NBTTagCompound getCompoundTag(String key)
{
try
{
if (this.hasKey(key, 10))
{
return (NBTTagCompound)this.tagMap.get(key);
}
}
catch (ClassCastException classcastexception)
{
throw new ReportedException(this.createCrashReport(key, 10, classcastexception));
}
return new NBTTagCompound();
}
/**
* Gets the NBTTagList object with the given name.
*/
public NBTTagList getTagList(String key, int type)
{
try
{
if (this.getTagId(key) == 9)
{
NBTTagList nbttaglist = (NBTTagList)this.tagMap.get(key);
if (!nbttaglist.hasNoTags() && nbttaglist.getTagType() != type)
{
return new NBTTagList();
}
return nbttaglist;
}
}
catch (ClassCastException classcastexception)
{
throw new ReportedException(this.createCrashReport(key, 9, classcastexception));
}
return new NBTTagList();
}
/**
* Retrieves a boolean value using the specified key, or false if no such key was stored. This uses the getByte
* method.
*/
public boolean getBoolean(String key)
{
return this.getByte(key) != 0;
}
/**
* Remove the specified tag.
*/
public void removeTag(String key)
{
this.tagMap.remove(key);
}
public String toString()
{
StringBuilder stringbuilder = new StringBuilder("{");
Collection<String> collection = this.tagMap.keySet();
if (LOGGER.isDebugEnabled())
{
List<String> list = Lists.newArrayList(this.tagMap.keySet());
Collections.sort(list);
collection = list;
}
for (String s : collection)
{
if (stringbuilder.length() != 1)
{
stringbuilder.append(',');
}
stringbuilder.append(handleEscape(s)).append(':').append(this.tagMap.get(s));
}
return stringbuilder.append('}').toString();
}
/**
* Return whether this compound has no tags.
*/
public boolean hasNoTags()
{
return this.tagMap.isEmpty();
}
/**
* Create a crash report which indicates a NBT read error.
*/
private CrashReport createCrashReport(final String key, final int expectedType, ClassCastException ex)
{
CrashReport crashreport = CrashReport.makeCrashReport(ex, "Reading NBT data");
CrashReportCategory crashreportcategory = crashreport.makeCategoryDepth("Corrupt NBT tag", 1);
crashreportcategory.addDetail("Tag type found", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
return NBTBase.NBT_TYPES[((NBTBase)NBTTagCompound.this.tagMap.get(key)).getId()];
}
});
crashreportcategory.addDetail("Tag type expected", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
return NBTBase.NBT_TYPES[expectedType];
}
});
crashreportcategory.addCrashSection("Tag name", key);
return crashreport;
}
/**
* Creates a clone of the tag.
*/
public NBTTagCompound copy()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
for (String s : this.tagMap.keySet())
{
nbttagcompound.setTag(s, ((NBTBase)this.tagMap.get(s)).copy());
}
return nbttagcompound;
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && Objects.equals(this.tagMap.entrySet(), ((NBTTagCompound)p_equals_1_).tagMap.entrySet());
}
public int hashCode()
{
return super.hashCode() ^ this.tagMap.hashCode();
}
private static void writeEntry(String name, NBTBase data, DataOutput output) throws IOException
{
output.writeByte(data.getId());
if (data.getId() != 0)
{
output.writeUTF(name);
data.write(output);
}
}
private static byte readType(DataInput input, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(8);
return input.readByte();
}
private static String readKey(DataInput input, NBTSizeTracker sizeTracker) throws IOException
{
return input.readUTF();
}
static NBTBase readNBT(byte id, String key, DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(32); //Forge: 4 extra bytes for the object allocation.
NBTBase nbtbase = NBTBase.createNewByType(id);
try
{
nbtbase.read(input, depth, sizeTracker);
return nbtbase;
}
catch (IOException ioexception)
{
CrashReport crashreport = CrashReport.makeCrashReport(ioexception, "Loading NBT data");
CrashReportCategory crashreportcategory = crashreport.makeCategory("NBT Tag");
crashreportcategory.addCrashSection("Tag name", key);
crashreportcategory.addCrashSection("Tag type", Byte.valueOf(id));
throw new ReportedException(crashreport);
}
}
/**
* Merges copies of data contained in {@code other} into this compound tag.
*/
public void merge(NBTTagCompound other)
{
for (String s : other.tagMap.keySet())
{
NBTBase nbtbase = other.tagMap.get(s);
if (nbtbase.getId() == 10)
{
if (this.hasKey(s, 10))
{
NBTTagCompound nbttagcompound = this.getCompoundTag(s);
nbttagcompound.merge((NBTTagCompound)nbtbase);
}
else
{
this.setTag(s, nbtbase.copy());
}
}
else
{
this.setTag(s, nbtbase.copy());
}
}
}
protected static String handleEscape(String p_193582_0_)
{
return SIMPLE_VALUE.matcher(p_193582_0_).matches() ? p_193582_0_ : NBTTagString.quoteAndEscape(p_193582_0_);
}
}

View File

@@ -0,0 +1,97 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import net.minecraft.util.math.MathHelper;
public class NBTTagDouble extends NBTPrimitive
{
/** The double value for the tag. */
private double data;
NBTTagDouble()
{
}
public NBTTagDouble(double data)
{
this.data = data;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeDouble(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(128L);
this.data = input.readDouble();
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 6;
}
public String toString()
{
return this.data + "d";
}
/**
* Creates a clone of the tag.
*/
public NBTTagDouble copy()
{
return new NBTTagDouble(this.data);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && this.data == ((NBTTagDouble)p_equals_1_).data;
}
public int hashCode()
{
long i = Double.doubleToLongBits(this.data);
return super.hashCode() ^ (int)(i ^ i >>> 32);
}
public long getLong()
{
return (long)Math.floor(this.data);
}
public int getInt()
{
return MathHelper.floor(this.data);
}
public short getShort()
{
return (short)(MathHelper.floor(this.data) & 65535);
}
public byte getByte()
{
return (byte)(MathHelper.floor(this.data) & 255);
}
public double getDouble()
{
return this.data;
}
public float getFloat()
{
return (float)this.data;
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagEnd extends NBTBase
{
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(64L);
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 0;
}
public String toString()
{
return "END";
}
/**
* Creates a clone of the tag.
*/
public NBTTagEnd copy()
{
return new NBTTagEnd();
}
}

View File

@@ -0,0 +1,96 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import net.minecraft.util.math.MathHelper;
public class NBTTagFloat extends NBTPrimitive
{
/** The float value for the tag. */
private float data;
NBTTagFloat()
{
}
public NBTTagFloat(float data)
{
this.data = data;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeFloat(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(96L);
this.data = input.readFloat();
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 5;
}
public String toString()
{
return this.data + "f";
}
/**
* Creates a clone of the tag.
*/
public NBTTagFloat copy()
{
return new NBTTagFloat(this.data);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && this.data == ((NBTTagFloat)p_equals_1_).data;
}
public int hashCode()
{
return super.hashCode() ^ Float.floatToIntBits(this.data);
}
public long getLong()
{
return (long)this.data;
}
public int getInt()
{
return MathHelper.floor(this.data);
}
public short getShort()
{
return (short)(MathHelper.floor(this.data) & 65535);
}
public byte getByte()
{
return (byte)(MathHelper.floor(this.data) & 255);
}
public double getDouble()
{
return (double)this.data;
}
public float getFloat()
{
return this.data;
}
}

View File

@@ -0,0 +1,95 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagInt extends NBTPrimitive
{
/** The integer value for the tag. */
private int data;
NBTTagInt()
{
}
public NBTTagInt(int data)
{
this.data = data;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeInt(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(96L);
this.data = input.readInt();
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 3;
}
public String toString()
{
return String.valueOf(this.data);
}
/**
* Creates a clone of the tag.
*/
public NBTTagInt copy()
{
return new NBTTagInt(this.data);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && this.data == ((NBTTagInt)p_equals_1_).data;
}
public int hashCode()
{
return super.hashCode() ^ this.data;
}
public long getLong()
{
return (long)this.data;
}
public int getInt()
{
return this.data;
}
public short getShort()
{
return (short)(this.data & 65535);
}
public byte getByte()
{
return (byte)(this.data & 255);
}
public double getDouble()
{
return (double)this.data;
}
public float getFloat()
{
return (float)this.data;
}
}

View File

@@ -0,0 +1,116 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class NBTTagIntArray extends NBTBase
{
/** The array of saved integers */
private int[] intArray;
NBTTagIntArray()
{
}
public NBTTagIntArray(int[] p_i45132_1_)
{
this.intArray = p_i45132_1_;
}
public NBTTagIntArray(List<Integer> p_i47528_1_)
{
this(toArray(p_i47528_1_));
}
private static int[] toArray(List<Integer> p_193584_0_)
{
int[] aint = new int[p_193584_0_.size()];
for (int i = 0; i < p_193584_0_.size(); ++i)
{
Integer integer = p_193584_0_.get(i);
aint[i] = integer == null ? 0 : integer.intValue();
}
return aint;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeInt(this.intArray.length);
for (int i : this.intArray)
{
output.writeInt(i);
}
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(192L);
int i = input.readInt();
sizeTracker.read((long)(32 * i));
this.intArray = new int[i];
for (int j = 0; j < i; ++j)
{
this.intArray[j] = input.readInt();
}
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 11;
}
public String toString()
{
StringBuilder stringbuilder = new StringBuilder("[I;");
for (int i = 0; i < this.intArray.length; ++i)
{
if (i != 0)
{
stringbuilder.append(',');
}
stringbuilder.append(this.intArray[i]);
}
return stringbuilder.append(']').toString();
}
/**
* Creates a clone of the tag.
*/
public NBTTagIntArray copy()
{
int[] aint = new int[this.intArray.length];
System.arraycopy(this.intArray, 0, aint, 0, this.intArray.length);
return new NBTTagIntArray(aint);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && Arrays.equals(this.intArray, ((NBTTagIntArray)p_equals_1_).intArray);
}
public int hashCode()
{
return super.hashCode() ^ Arrays.hashCode(this.intArray);
}
public int[] getIntArray()
{
return this.intArray;
}
}

View File

@@ -0,0 +1,321 @@
package net.minecraft.nbt;
import com.google.common.collect.Lists;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class NBTTagList extends NBTBase implements java.lang.Iterable<NBTBase>
{
private static final Logger LOGGER = LogManager.getLogger();
/** The array list containing the tags encapsulated in this list. */
public List<NBTBase> tagList = Lists.<NBTBase>newArrayList();
/** The type byte for the tags in the list - they must all be of the same type. */
private byte tagType = 0;
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
if (this.tagList.isEmpty())
{
this.tagType = 0;
}
else
{
this.tagType = ((NBTBase)this.tagList.get(0)).getId();
}
output.writeByte(this.tagType);
output.writeInt(this.tagList.size());
for (int i = 0; i < this.tagList.size(); ++i)
{
((NBTBase)this.tagList.get(i)).write(output);
}
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(296L);
if (depth > 512)
{
throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512");
}
else
{
this.tagType = input.readByte();
int i = input.readInt();
if (this.tagType == 0 && i > 0)
{
throw new RuntimeException("Missing type on ListTag");
}
else
{
sizeTracker.read(32L * (long)i);
this.tagList = Lists.<NBTBase>newArrayListWithCapacity(i);
for (int j = 0; j < i; ++j)
{
NBTBase nbtbase = NBTBase.createNewByType(this.tagType);
nbtbase.read(input, depth + 1, sizeTracker);
this.tagList.add(nbtbase);
}
}
}
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 9;
}
public String toString()
{
StringBuilder stringbuilder = new StringBuilder("[");
for (int i = 0; i < this.tagList.size(); ++i)
{
if (i != 0)
{
stringbuilder.append(',');
}
stringbuilder.append(this.tagList.get(i));
}
return stringbuilder.append(']').toString();
}
/**
* Adds the provided tag to the end of the list. There is no check to verify this tag is of the same type as any
* previous tag.
*/
public void appendTag(NBTBase nbt)
{
if (nbt.getId() == 0)
{
LOGGER.warn("Invalid TagEnd added to ListTag");
}
else
{
if (this.tagType == 0)
{
this.tagType = nbt.getId();
}
else if (this.tagType != nbt.getId())
{
LOGGER.warn("Adding mismatching tag types to tag list");
return;
}
this.tagList.add(nbt);
}
}
/**
* Set the given index to the given tag
*/
public void set(int idx, NBTBase nbt)
{
if (nbt.getId() == 0)
{
LOGGER.warn("Invalid TagEnd added to ListTag");
}
else if (idx >= 0 && idx < this.tagList.size())
{
if (this.tagType == 0)
{
this.tagType = nbt.getId();
}
else if (this.tagType != nbt.getId())
{
LOGGER.warn("Adding mismatching tag types to tag list");
return;
}
this.tagList.set(idx, nbt);
}
else
{
LOGGER.warn("index out of bounds to set tag in tag list");
}
}
/**
* Removes a tag at the given index.
*/
public NBTBase removeTag(int i)
{
return this.tagList.remove(i);
}
/**
* Return whether this compound has no tags.
*/
public boolean hasNoTags()
{
return this.tagList.isEmpty();
}
/**
* Retrieves the NBTTagCompound at the specified index in the list
*/
public NBTTagCompound getCompoundTagAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = this.tagList.get(i);
if (nbtbase.getId() == 10)
{
return (NBTTagCompound)nbtbase;
}
}
return new NBTTagCompound();
}
public int getIntAt(int p_186858_1_)
{
if (p_186858_1_ >= 0 && p_186858_1_ < this.tagList.size())
{
NBTBase nbtbase = this.tagList.get(p_186858_1_);
if (nbtbase.getId() == 3)
{
return ((NBTTagInt)nbtbase).getInt();
}
}
return 0;
}
public int[] getIntArrayAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = this.tagList.get(i);
if (nbtbase.getId() == 11)
{
return ((NBTTagIntArray)nbtbase).getIntArray();
}
}
return new int[0];
}
public double getDoubleAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = this.tagList.get(i);
if (nbtbase.getId() == 6)
{
return ((NBTTagDouble)nbtbase).getDouble();
}
}
return 0.0D;
}
public float getFloatAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = this.tagList.get(i);
if (nbtbase.getId() == 5)
{
return ((NBTTagFloat)nbtbase).getFloat();
}
}
return 0.0F;
}
/**
* Retrieves the tag String value at the specified index in the list
*/
public String getStringTagAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = this.tagList.get(i);
return nbtbase.getId() == 8 ? nbtbase.getString() : nbtbase.toString();
}
else
{
return "";
}
}
/**
* Get the tag at the given position
*/
public NBTBase get(int idx)
{
return (NBTBase)(idx >= 0 && idx < this.tagList.size() ? (NBTBase)this.tagList.get(idx) : new NBTTagEnd());
}
/**
* Returns the number of tags in the list.
*/
public int tagCount()
{
return this.tagList.size();
}
/**
* Creates a clone of the tag.
*/
public NBTTagList copy()
{
NBTTagList nbttaglist = new NBTTagList();
nbttaglist.tagType = this.tagType;
for (NBTBase nbtbase : this.tagList)
{
NBTBase nbtbase1 = nbtbase.copy();
nbttaglist.tagList.add(nbtbase1);
}
return nbttaglist;
}
public boolean equals(Object p_equals_1_)
{
if (!super.equals(p_equals_1_))
{
return false;
}
else
{
NBTTagList nbttaglist = (NBTTagList)p_equals_1_;
return this.tagType == nbttaglist.tagType && Objects.equals(this.tagList, nbttaglist.tagList);
}
}
public int hashCode()
{
return super.hashCode() ^ this.tagList.hashCode();
}
public int getTagType()
{
return this.tagType;
}
@Override public java.util.Iterator<NBTBase> iterator() {return tagList.iterator();}
}

View File

@@ -0,0 +1,95 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagLong extends NBTPrimitive
{
/** The long value for the tag. */
private long data;
NBTTagLong()
{
}
public NBTTagLong(long data)
{
this.data = data;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeLong(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(128L);
this.data = input.readLong();
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 4;
}
public String toString()
{
return this.data + "L";
}
/**
* Creates a clone of the tag.
*/
public NBTTagLong copy()
{
return new NBTTagLong(this.data);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && this.data == ((NBTTagLong)p_equals_1_).data;
}
public int hashCode()
{
return super.hashCode() ^ (int)(this.data ^ this.data >>> 32);
}
public long getLong()
{
return this.data;
}
public int getInt()
{
return (int)(this.data & -1L);
}
public short getShort()
{
return (short)((int)(this.data & 65535L));
}
public byte getByte()
{
return (byte)((int)(this.data & 255L));
}
public double getDouble()
{
return (double)this.data;
}
public float getFloat()
{
return (float)this.data;
}
}

View File

@@ -0,0 +1,110 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class NBTTagLongArray extends NBTBase
{
private long[] data;
NBTTagLongArray()
{
}
public NBTTagLongArray(long[] p_i47524_1_)
{
this.data = p_i47524_1_;
}
public NBTTagLongArray(List<Long> p_i47525_1_)
{
this(toArray(p_i47525_1_));
}
private static long[] toArray(List<Long> p_193586_0_)
{
long[] along = new long[p_193586_0_.size()];
for (int i = 0; i < p_193586_0_.size(); ++i)
{
Long olong = p_193586_0_.get(i);
along[i] = olong == null ? 0L : olong.longValue();
}
return along;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeInt(this.data.length);
for (long i : this.data)
{
output.writeLong(i);
}
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(192L);
int i = input.readInt();
sizeTracker.read((long)(64 * i));
this.data = new long[i];
for (int j = 0; j < i; ++j)
{
this.data[j] = input.readLong();
}
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 12;
}
public String toString()
{
StringBuilder stringbuilder = new StringBuilder("[L;");
for (int i = 0; i < this.data.length; ++i)
{
if (i != 0)
{
stringbuilder.append(',');
}
stringbuilder.append(this.data[i]).append('L');
}
return stringbuilder.append(']').toString();
}
/**
* Creates a clone of the tag.
*/
public NBTTagLongArray copy()
{
long[] along = new long[this.data.length];
System.arraycopy(this.data, 0, along, 0, this.data.length);
return new NBTTagLongArray(along);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && Arrays.equals(this.data, ((NBTTagLongArray)p_equals_1_).data);
}
public int hashCode()
{
return super.hashCode() ^ Arrays.hashCode(this.data);
}
}

View File

@@ -0,0 +1,95 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagShort extends NBTPrimitive
{
/** The short value for the tag. */
private short data;
public NBTTagShort()
{
}
public NBTTagShort(short data)
{
this.data = data;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeShort(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(80L);
this.data = input.readShort();
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 2;
}
public String toString()
{
return this.data + "s";
}
/**
* Creates a clone of the tag.
*/
public NBTTagShort copy()
{
return new NBTTagShort(this.data);
}
public boolean equals(Object p_equals_1_)
{
return super.equals(p_equals_1_) && this.data == ((NBTTagShort)p_equals_1_).data;
}
public int hashCode()
{
return super.hashCode() ^ this.data;
}
public long getLong()
{
return (long)this.data;
}
public int getInt()
{
return this.data;
}
public short getShort()
{
return this.data;
}
public byte getByte()
{
return (byte)(this.data & 255);
}
public double getDouble()
{
return (double)this.data;
}
public float getFloat()
{
return (float)this.data;
}
}

View File

@@ -0,0 +1,109 @@
package net.minecraft.nbt;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;
public class NBTTagString extends NBTBase
{
/** The string value for the tag (cannot be empty). */
private String data;
public NBTTagString()
{
this("");
}
public NBTTagString(String data)
{
Objects.requireNonNull(data, "Null string not allowed");
this.data = data;
}
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
output.writeUTF(this.data);
}
void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException
{
sizeTracker.read(288L);
this.data = input.readUTF();
NBTSizeTracker.readUTF(sizeTracker, data); // Forge: Correctly read String length including header.
}
/**
* Gets the type byte for the tag.
*/
public byte getId()
{
return 8;
}
public String toString()
{
return quoteAndEscape(this.data);
}
/**
* Creates a clone of the tag.
*/
public NBTTagString copy()
{
return new NBTTagString(this.data);
}
/**
* Return whether this compound has no tags.
*/
public boolean hasNoTags()
{
return this.data.isEmpty();
}
public boolean equals(Object p_equals_1_)
{
if (!super.equals(p_equals_1_))
{
return false;
}
else
{
NBTTagString nbttagstring = (NBTTagString)p_equals_1_;
return this.data == null && nbttagstring.data == null || Objects.equals(this.data, nbttagstring.data);
}
}
public int hashCode()
{
return super.hashCode() ^ this.data.hashCode();
}
public String getString()
{
return this.data;
}
public static String quoteAndEscape(String p_193588_0_)
{
StringBuilder stringbuilder = new StringBuilder("\"");
for (int i = 0; i < p_193588_0_.length(); ++i)
{
char c0 = p_193588_0_.charAt(i);
if (c0 == '\\' || c0 == '"')
{
stringbuilder.append('\\');
}
stringbuilder.append(c0);
}
return stringbuilder.append('"').toString();
}
}

View File

@@ -0,0 +1,332 @@
package net.minecraft.nbt;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.collect.UnmodifiableIterator;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import java.util.UUID;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.BlockPos;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public final class NBTUtil
{
private static final Logger LOGGER = LogManager.getLogger();
/**
* Reads and returns a GameProfile that has been saved to the passed in NBTTagCompound
*/
@Nullable
public static GameProfile readGameProfileFromNBT(NBTTagCompound compound)
{
String s = null;
String s1 = null;
if (compound.hasKey("Name", 8))
{
s = compound.getString("Name");
}
if (compound.hasKey("Id", 8))
{
s1 = compound.getString("Id");
}
try
{
UUID uuid;
try
{
uuid = UUID.fromString(s1);
}
catch (Throwable var12)
{
uuid = null;
}
GameProfile gameprofile = new GameProfile(uuid, s);
if (compound.hasKey("Properties", 10))
{
NBTTagCompound nbttagcompound = compound.getCompoundTag("Properties");
for (String s2 : nbttagcompound.getKeySet())
{
NBTTagList nbttaglist = nbttagcompound.getTagList(s2, 10);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
String s3 = nbttagcompound1.getString("Value");
if (nbttagcompound1.hasKey("Signature", 8))
{
gameprofile.getProperties().put(s2, new Property(s2, s3, nbttagcompound1.getString("Signature")));
}
else
{
gameprofile.getProperties().put(s2, new Property(s2, s3));
}
}
}
}
return gameprofile;
}
catch (Throwable var13)
{
return null;
}
}
/**
* Writes a GameProfile to an NBTTagCompound.
*/
public static NBTTagCompound writeGameProfile(NBTTagCompound tagCompound, GameProfile profile)
{
if (!StringUtils.isNullOrEmpty(profile.getName()))
{
tagCompound.setString("Name", profile.getName());
}
if (profile.getId() != null)
{
tagCompound.setString("Id", profile.getId().toString());
}
if (!profile.getProperties().isEmpty())
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
for (String s : profile.getProperties().keySet())
{
NBTTagList nbttaglist = new NBTTagList();
for (Property property : profile.getProperties().get(s))
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setString("Value", property.getValue());
if (property.hasSignature())
{
nbttagcompound1.setString("Signature", property.getSignature());
}
nbttaglist.appendTag(nbttagcompound1);
}
nbttagcompound.setTag(s, nbttaglist);
}
tagCompound.setTag("Properties", nbttagcompound);
}
return tagCompound;
}
@VisibleForTesting
public static boolean areNBTEquals(NBTBase nbt1, NBTBase nbt2, boolean compareTagList)
{
if (nbt1 == nbt2)
{
return true;
}
else if (nbt1 == null)
{
return true;
}
else if (nbt2 == null)
{
return false;
}
else if (!nbt1.getClass().equals(nbt2.getClass()))
{
return false;
}
else if (nbt1 instanceof NBTTagCompound)
{
NBTTagCompound nbttagcompound = (NBTTagCompound)nbt1;
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbt2;
for (String s : nbttagcompound.getKeySet())
{
NBTBase nbtbase1 = nbttagcompound.getTag(s);
if (!areNBTEquals(nbtbase1, nbttagcompound1.getTag(s), compareTagList))
{
return false;
}
}
return true;
}
else if (nbt1 instanceof NBTTagList && compareTagList)
{
NBTTagList nbttaglist = (NBTTagList)nbt1;
NBTTagList nbttaglist1 = (NBTTagList)nbt2;
if (nbttaglist.hasNoTags())
{
return nbttaglist1.hasNoTags();
}
else
{
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTBase nbtbase = nbttaglist.get(i);
boolean flag = false;
for (int j = 0; j < nbttaglist1.tagCount(); ++j)
{
if (areNBTEquals(nbtbase, nbttaglist1.get(j), compareTagList))
{
flag = true;
break;
}
}
if (!flag)
{
return false;
}
}
return true;
}
}
else
{
return nbt1.equals(nbt2);
}
}
/**
* Creates a new NBTTagCompound which stores a UUID.
*/
public static NBTTagCompound createUUIDTag(UUID uuid)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setLong("M", uuid.getMostSignificantBits());
nbttagcompound.setLong("L", uuid.getLeastSignificantBits());
return nbttagcompound;
}
/**
* Reads a UUID from the passed NBTTagCompound.
*/
public static UUID getUUIDFromTag(NBTTagCompound tag)
{
return new UUID(tag.getLong("M"), tag.getLong("L"));
}
/**
* Creates a BlockPos object from the data stored in the passed NBTTagCompound.
*/
public static BlockPos getPosFromTag(NBTTagCompound tag)
{
return new BlockPos(tag.getInteger("X"), tag.getInteger("Y"), tag.getInteger("Z"));
}
/**
* Creates a new NBTTagCompound from a BlockPos.
*/
public static NBTTagCompound createPosTag(BlockPos pos)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setInteger("X", pos.getX());
nbttagcompound.setInteger("Y", pos.getY());
nbttagcompound.setInteger("Z", pos.getZ());
return nbttagcompound;
}
/**
* Reads a blockstate from the given tag.
*/
public static IBlockState readBlockState(NBTTagCompound tag)
{
if (!tag.hasKey("Name", 8))
{
return Blocks.AIR.getDefaultState();
}
else
{
Block block = Block.REGISTRY.getObject(new ResourceLocation(tag.getString("Name")));
IBlockState iblockstate = block.getDefaultState();
if (tag.hasKey("Properties", 10))
{
NBTTagCompound nbttagcompound = tag.getCompoundTag("Properties");
BlockStateContainer blockstatecontainer = block.getBlockState();
for (String s : nbttagcompound.getKeySet())
{
IProperty<?> iproperty = blockstatecontainer.getProperty(s);
if (iproperty != null)
{
iblockstate = setValueHelper(iblockstate, iproperty, s, nbttagcompound, tag);
}
}
}
return iblockstate;
}
}
private static <T extends Comparable<T>> IBlockState setValueHelper(IBlockState p_193590_0_, IProperty<T> p_193590_1_, String p_193590_2_, NBTTagCompound p_193590_3_, NBTTagCompound p_193590_4_)
{
Optional<T> optional = p_193590_1_.parseValue(p_193590_3_.getString(p_193590_2_));
if (optional.isPresent())
{
return p_193590_0_.withProperty(p_193590_1_, optional.get());
}
else
{
LOGGER.warn("Unable to read property: {} with value: {} for blockstate: {}", p_193590_2_, p_193590_3_.getString(p_193590_2_), p_193590_4_.toString());
return p_193590_0_;
}
}
/**
* Writes the given blockstate to the given tag.
*/
public static NBTTagCompound writeBlockState(NBTTagCompound tag, IBlockState state)
{
tag.setString("Name", ((ResourceLocation)Block.REGISTRY.getNameForObject(state.getBlock())).toString());
if (!state.getProperties().isEmpty())
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
UnmodifiableIterator unmodifiableiterator = state.getProperties().entrySet().iterator();
while (unmodifiableiterator.hasNext())
{
Entry < IProperty<?>, Comparable<? >> entry = (Entry)unmodifiableiterator.next();
IProperty<?> iproperty = (IProperty)entry.getKey();
nbttagcompound.setString(iproperty.getName(), getName(iproperty, entry.getValue()));
}
tag.setTag("Properties", nbttagcompound);
}
return tag;
}
@SuppressWarnings("unchecked")
private static <T extends Comparable<T>> String getName(IProperty<T> p_190010_0_, Comparable<?> p_190010_1_)
{
return p_190010_0_.getName((T)p_190010_1_);
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.nbt;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;