change compressed data tree ids and clean up

This commit is contained in:
Sen 2025-05-28 11:29:49 +02:00
parent 6c55d59f1f
commit f76d3c8b89
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
33 changed files with 633 additions and 682 deletions

View file

@ -28,8 +28,6 @@ import common.item.Item;
import common.item.ItemStack;
import common.model.ParticleType;
import common.rng.Random;
import common.tags.TagDoubleList;
import common.tags.TagFloatList;
import common.tags.TagObject;
import common.util.BlockPos;
import common.util.BoundingBox;
@ -1496,10 +1494,15 @@ public abstract class Entity
// if(this.tag != null) {
// tagCompund.setString("ObjectTag", this.tag);
// }
tag.setDoubleList("Pos", this.newDoubleList(this.posX, this.posY, this.posZ));
tag.setDoubleList("Motion", this.newDoubleList(this.motionX, this.motionY, this.motionZ));
tag.setFloatList("Rotation", this.newFloatList(this.rotYaw, this.rotPitch));
tag.setDouble("PosX", this.posX);
tag.setDouble("PosY", this.posY);
tag.setDouble("PosZ", this.posZ);
tag.setDouble("MotionX", this.motionX);
tag.setDouble("MotionY", this.motionY);
tag.setDouble("MotionZ", this.motionZ);
tag.setFloat("Yaw", this.rotYaw);
tag.setFloat("Pitch", this.rotPitch);
tag.setFloat("FallDistance", this.fallDistance);
tag.setShort("Fire", (short)this.fire);
// tagCompund.setShort("Air", (short)this.getAir());
@ -1543,12 +1546,9 @@ public abstract class Entity
// this.setPersistentId(tagCompund.getLong("PersistID"));
// this.setTag(tagCompund.getString("ObjectTag"));
TagDoubleList pos = tag.getDoubleList("Pos");
TagDoubleList motion = tag.getDoubleList("Motion");
TagFloatList rotation = tag.getFloatList("Rotation");
this.motionX = motion.get(0);
this.motionY = motion.get(1);
this.motionZ = motion.get(2);
this.motionX = tag.getDouble("MotionX");
this.motionY = tag.getDouble("MotionY");
this.motionZ = tag.getDouble("MotionZ");
if (Math.abs(this.motionX) > 10.0D)
{
@ -1565,11 +1565,11 @@ public abstract class Entity
this.motionZ = 0.0D;
}
this.prevX = this.lastTickPosX = this.posX = pos.get(0);
this.prevY = this.lastTickPosY = this.posY = pos.get(1);
this.prevZ = this.lastTickPosZ = this.posZ = pos.get(2);
this.prevYaw = this.rotYaw = rotation.get(0);
this.prevPitch = this.rotPitch = rotation.get(1);
this.prevX = this.lastTickPosX = this.posX = tag.getDouble("PosX");
this.prevY = this.lastTickPosY = this.posY = tag.getDouble("PosY");
this.prevZ = this.lastTickPosZ = this.posZ = tag.getDouble("PosZ");
this.prevYaw = this.rotYaw = tag.getFloat("Yaw");
this.prevPitch = this.rotPitch = tag.getFloat("Pitch");
this.setRotationYawHead(this.rotYaw);
this.setRenderYawOffset(this.rotYaw);
this.fallDistance = tag.getFloat("FallDistance");
@ -1625,36 +1625,6 @@ public abstract class Entity
{
}
/**
* creates a list from the array of doubles passed to this function
*/
protected TagDoubleList newDoubleList(double... numbers)
{
TagDoubleList list = new TagDoubleList();
for (double d0 : numbers)
{
list.add(d0);
}
return list;
}
/**
* Returns a new list filled with the specified floats
*/
protected TagFloatList newFloatList(float... numbers)
{
TagFloatList list = new TagFloatList();
for (float f : numbers)
{
list.add(f);
}
return list;
}
public EntityItem dropItem(Item itemIn, int size)
{
return this.dropItemWithOffset(itemIn, size, 0.0F);

View file

@ -153,11 +153,7 @@ public class EntityWolf extends EntityTameable
{
super.readEntity(tagCompund);
this.setAngry(tagCompund.getBool("Angry"));
if (tagCompund.hasByte("CollarColor"))
{
this.setCollarColor(DyeColor.byDyeDamage(tagCompund.getByte("CollarColor")));
}
this.setCollarColor(DyeColor.byDyeDamage(tagCompund.getByte("CollarColor")));
}
/**

View file

@ -483,7 +483,7 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
}
tagCompound.setByte("inData", (byte)this.inData);
tagCompound.setByte("shake", (byte)this.arrowShake);
tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
tagCompound.setBool("inGround", this.inGround);
tagCompound.setByte("pickup", (byte)this.canBePickedUp);
tagCompound.setDouble("damage", this.damage);
}
@ -509,7 +509,7 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
this.inData = tagCompund.getByte("inData") & 255;
this.arrowShake = tagCompund.getByte("shake") & 255;
this.inGround = tagCompund.getByte("inGround") == 1;
this.inGround = tagCompund.getBool("inGround");
this.damage = tagCompund.getDouble("damage");

View file

@ -527,7 +527,7 @@ public class EntityHook extends Entity implements IObjectData
tagCompound.setString("inTile", id == null ? "" : id.toString());
}
tagCompound.setByte("shake", (byte)this.shake);
tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
tagCompound.setBool("inGround", this.inGround);
}
/**
@ -549,7 +549,7 @@ public class EntityHook extends Entity implements IObjectData
}
this.shake = tagCompund.getByte("shake") & 255;
this.inGround = tagCompund.getByte("inGround") == 1;
this.inGround = tagCompund.getBool("inGround");
}
public int handleHookRetraction()

View file

@ -9,7 +9,6 @@ import common.entity.EntityType;
import common.entity.types.EntityLiving;
import common.init.BlockRegistry;
import common.model.ParticleType;
import common.tags.TagDoubleList;
import common.tags.TagObject;
import common.util.BlockPos;
import common.util.BoundingBox;
@ -259,10 +258,14 @@ public abstract class EntityProjectile extends Entity
tagCompound.setShort("xTile", (short)this.xTile);
tagCompound.setShort("yTile", (short)this.yTile);
tagCompound.setShort("zTile", (short)this.zTile);
String resourcelocation = BlockRegistry.REGISTRY.getNameForObject(this.inTile);
tagCompound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
tagCompound.setDoubleList("direction", this.newDoubleList(this.motionX, this.motionY, this.motionZ));
if(this.inTile != null) {
String id = BlockRegistry.REGISTRY.getNameForObject(this.inTile);
tagCompound.setString("inTile", id == null ? "" : id.toString());
}
tagCompound.setBool("inGround", this.inGround);
tagCompound.setDouble("dirX", this.motionX);
tagCompound.setDouble("dirY", this.motionY);
tagCompound.setDouble("dirZ", this.motionZ);
tagCompound.setInt("Age", this.age);
}
@ -281,17 +284,16 @@ public abstract class EntityProjectile extends Entity
}
else
{
this.inTile = BlockRegistry.getBlockById(tagCompund.getByte("inTile") & 255);
this.inTile = null;
}
this.inGround = tagCompund.getByte("inGround") == 1;
this.inGround = tagCompund.getBool("inGround");
if (tagCompund.hasDoubleList("direction"))
if (tagCompund.hasDouble("dirX") && tagCompund.hasDouble("dirY") && tagCompund.hasDouble("dirZ"))
{
TagDoubleList nbttaglist = tagCompund.getDoubleList("direction");
this.motionX = nbttaglist.get(0);
this.motionY = nbttaglist.get(1);
this.motionZ = nbttaglist.get(2);
this.motionX = tagCompund.getDouble("dirX");
this.motionY = tagCompund.getDouble("dirY");
this.motionZ = tagCompund.getDouble("dirZ");
}
else
{

View file

@ -313,7 +313,7 @@ public abstract class EntityThrowable extends Entity implements IProjectile
tagCompound.setString("inTile", id == null ? "" : id.toString());
}
tagCompound.setByte("shake", (byte)this.throwableShake);
tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
tagCompound.setBool("inGround", this.inGround);
// if ((this.throwerName == null || this.throwerName.length() == 0) && this.thrower.isPlayer())
// {
@ -342,7 +342,7 @@ public abstract class EntityThrowable extends Entity implements IProjectile
}
this.throwableShake = tagCompund.getByte("shake") & 255;
this.inGround = tagCompund.getByte("inGround") == 1;
this.inGround = tagCompund.getBool("inGround");
// this.thrower = null;
// this.throwerName = tagCompund.getString("ownerName");
//

View file

@ -5,56 +5,17 @@ import java.io.DataOutput;
import java.io.IOException;
public abstract class Tag {
protected static Tag createNewByType(byte id) {
switch(id) {
case 0:
return new TagNull();
case 1:
return new TagByte();
case 2:
return new TagShort();
case 3:
return new TagInt();
case 4:
return new TagLong();
case 5:
return new TagFloat();
case 6:
return new TagDouble();
case 7:
return new TagByteArray();
case 8:
return new TagString();
case 9:
return new TagStringList();
case 10:
return new TagObject();
case 11:
return new TagIntArray();
case 12:
return new TagObjectList();
case 13:
return new TagFloatList();
case 14:
return new TagDoubleList();
case 15:
return new TagIntArrayList();
default:
return null;
}
}
abstract void write(DataOutput output) throws IOException;
abstract void read(DataInput input, int depth, SizeTracker tracker) throws IOException;
public abstract String toString();
protected abstract byte getId();
protected abstract TagType getType();
public abstract Tag copy();
public boolean equals(Object other) {
return other instanceof Tag && this.getId() == ((Tag)other).getId();
return other instanceof Tag && this.getType() == ((Tag)other).getType();
}
public int hashCode() {
return this.getId();
return this.getType().getId();
}
}

View file

@ -0,0 +1,49 @@
package common.tags;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagBool extends Tag {
private boolean data;
TagBool() {
}
public TagBool(boolean data) {
this.data = data;
}
void write(DataOutput output) throws IOException {
output.writeBoolean(this.data);
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(9);
this.data = input.readBoolean();
}
protected TagType getType() {
return TagType.BOOLEAN;
}
public String toString() {
return "" + this.data;
}
public Tag copy() {
return new TagBool(this.data);
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagBool)other).data;
}
public int hashCode() {
return super.hashCode() ^ (this.data ? 1 : 0);
}
public boolean getBool() {
return this.data;
}
}

View file

@ -4,65 +4,46 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagByte extends Tag
{
private byte data;
class TagByte extends Tag {
private byte data;
TagByte()
{
}
TagByte() {
}
public TagByte(byte data)
{
this.data = data;
}
public TagByte(byte data) {
this.data = data;
}
void write(DataOutput output) throws IOException
{
output.writeByte(this.data);
}
void write(DataOutput output) throws IOException {
output.writeByte(this.data);
}
void read(DataInput input, int depth, SizeTracker sizeTracker) throws IOException
{
sizeTracker.read(9);
this.data = input.readByte();
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(9);
this.data = input.readByte();
}
protected byte getId()
{
return (byte)1;
}
protected TagType getType() {
return TagType.BYTE;
}
public String toString()
{
return "" + this.data + "b";
}
public String toString() {
return "" + this.data + "b";
}
public Tag copy()
{
return new TagByte(this.data);
}
public Tag copy() {
return new TagByte(this.data);
}
public boolean equals(Object other)
{
if (super.equals(other))
{
TagByte tag = (TagByte)other;
return this.data == tag.data;
}
else
{
return false;
}
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagByte)other).data;
}
public int hashCode()
{
return super.hashCode() ^ this.data;
}
public int hashCode() {
return super.hashCode() ^ this.data;
}
public byte getByte()
{
return this.data;
}
public byte getByte() {
return this.data;
}
}

View file

@ -28,8 +28,8 @@ class TagByteArray extends Tag {
input.readFully(this.data);
}
protected byte getId() {
return (byte)7;
protected TagType getType() {
return TagType.BYTE_ARRAY;
}
public String toString() {

View file

@ -0,0 +1,49 @@
package common.tags;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagChar extends Tag {
private char data;
TagChar() {
}
public TagChar(char data) {
this.data = data;
}
void write(DataOutput output) throws IOException {
output.writeChar(this.data);
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(10);
this.data = input.readChar();
}
protected TagType getType() {
return TagType.CHAR;
}
public String toString() {
return String.format(Character.isLetterOrDigit(this.data) ? "'%c'" : (this.data >= 256 ? "'\\u%04x'" : "'\\x%02x'"), this.data);
}
public Tag copy() {
return new TagChar(this.data);
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagChar)other).data;
}
public int hashCode() {
return super.hashCode() ^ this.data;
}
public char getChar() {
return this.data;
}
}

View file

@ -4,66 +4,47 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagDouble extends Tag
{
private double data;
class TagDouble extends Tag {
private double data;
TagDouble()
{
}
TagDouble() {
}
public TagDouble(double data)
{
this.data = data;
}
public TagDouble(double data) {
this.data = data;
}
void write(DataOutput output) throws IOException
{
output.writeDouble(this.data);
}
void write(DataOutput output) throws IOException {
output.writeDouble(this.data);
}
void read(DataInput input, int depth, SizeTracker sizeTracker) throws IOException
{
sizeTracker.read(16);
this.data = input.readDouble();
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(16);
this.data = input.readDouble();
}
protected byte getId()
{
return (byte)6;
}
protected TagType getType() {
return TagType.DOUBLE;
}
public String toString()
{
return "" + this.data + "d";
}
public String toString() {
return "" + this.data + "d";
}
public Tag copy()
{
return new TagDouble(this.data);
}
public Tag copy() {
return new TagDouble(this.data);
}
public boolean equals(Object other)
{
if (super.equals(other))
{
TagDouble tag = (TagDouble)other;
return this.data == tag.data;
}
else
{
return false;
}
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagDouble)other).data;
}
public int hashCode()
{
long i = Double.doubleToLongBits(this.data);
return super.hashCode() ^ (int)(i ^ i >>> 32);
}
public int hashCode() {
long l = Double.doubleToLongBits(this.data);
return super.hashCode() ^ (int)(l ^ l >>> 32);
}
public double getDouble()
{
return this.data;
}
public double getDouble() {
return this.data;
}
}

View file

@ -1,27 +0,0 @@
package common.tags;
public class TagDoubleList extends TagList<TagDouble> {
protected byte getId() {
return 14;
}
protected byte getType() {
return 6;
}
protected TagList<TagDouble> createInstance() {
return new TagDoubleList();
}
protected TagDouble getDefault() {
return new TagDouble(0.0);
}
public double get(int index) {
return this.getElem(index).getDouble();
}
public void add(double value) {
this.addElem(new TagDouble(value));
}
}

View file

@ -4,65 +4,46 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagFloat extends Tag
{
private float data;
class TagFloat extends Tag {
private float data;
TagFloat()
{
}
TagFloat() {
}
public TagFloat(float data)
{
this.data = data;
}
public TagFloat(float data) {
this.data = data;
}
void write(DataOutput output) throws IOException
{
output.writeFloat(this.data);
}
void write(DataOutput output) throws IOException {
output.writeFloat(this.data);
}
void read(DataInput input, int depth, SizeTracker sizeTracker) throws IOException
{
sizeTracker.read(12);
this.data = input.readFloat();
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(12);
this.data = input.readFloat();
}
protected byte getId()
{
return (byte)5;
}
protected TagType getType() {
return TagType.FLOAT;
}
public String toString()
{
return "" + this.data + "f";
}
public String toString() {
return "" + this.data + "f";
}
public Tag copy()
{
return new TagFloat(this.data);
}
public Tag copy() {
return new TagFloat(this.data);
}
public boolean equals(Object other)
{
if (super.equals(other))
{
TagFloat tag = (TagFloat)other;
return this.data == tag.data;
}
else
{
return false;
}
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagFloat)other).data;
}
public int hashCode()
{
return super.hashCode() ^ Float.floatToIntBits(this.data);
}
public int hashCode() {
return super.hashCode() ^ Float.floatToIntBits(this.data);
}
public float getFloat()
{
return this.data;
}
public float getFloat() {
return this.data;
}
}

View file

@ -1,27 +0,0 @@
package common.tags;
public class TagFloatList extends TagList<TagFloat> {
protected byte getId() {
return 13;
}
protected byte getType() {
return 5;
}
protected TagList<TagFloat> createInstance() {
return new TagFloatList();
}
protected TagFloat getDefault() {
return new TagFloat(0.0f);
}
public float get(int index) {
return this.getElem(index).getFloat();
}
public void add(float value) {
this.addElem(new TagFloat(value));
}
}

View file

@ -4,65 +4,46 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagInt extends Tag
{
private int data;
class TagInt extends Tag {
private int data;
TagInt()
{
}
TagInt() {
}
public TagInt(int data)
{
this.data = data;
}
public TagInt(int data) {
this.data = data;
}
void write(DataOutput output) throws IOException
{
output.writeInt(this.data);
}
void write(DataOutput output) throws IOException {
output.writeInt(this.data);
}
void read(DataInput input, int depth, SizeTracker sizeTracker) throws IOException
{
sizeTracker.read(12);
this.data = input.readInt();
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(12);
this.data = input.readInt();
}
protected byte getId()
{
return (byte)3;
}
protected TagType getType() {
return TagType.INT;
}
public String toString()
{
return "" + this.data;
}
public String toString() {
return "" + this.data;
}
public Tag copy()
{
return new TagInt(this.data);
}
public Tag copy() {
return new TagInt(this.data);
}
public boolean equals(Object other)
{
if (super.equals(other))
{
TagInt tag = (TagInt)other;
return this.data == tag.data;
}
else
{
return false;
}
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagInt)other).data;
}
public int hashCode()
{
return super.hashCode() ^ this.data;
}
public int hashCode() {
return super.hashCode() ^ this.data;
}
public int getInt()
{
return this.data;
}
public int getInt() {
return this.data;
}
}

View file

@ -32,8 +32,8 @@ class TagIntArray extends Tag {
}
}
protected byte getId() {
return (byte)11;
protected TagType getType() {
return TagType.INT_ARRAY;
}
public String toString() {

View file

@ -1,27 +0,0 @@
package common.tags;
public class TagIntArrayList extends TagList<TagIntArray> {
protected byte getId() {
return 15;
}
protected byte getType() {
return 11;
}
protected TagList<TagIntArray> createInstance() {
return new TagIntArrayList();
}
protected TagIntArray getDefault() {
return new TagIntArray(new int[0]);
}
public int[] get(int index) {
return this.getElem(index).getIntArray();
}
public void add(int[] value) {
this.addElem(new TagIntArray(value));
}
}

View file

@ -420,17 +420,11 @@ public class TagInterpreter
{
Tag tag = any.parse();
if(list == null) {
switch(tag.getId()) {
case 8:
switch(tag.getType()) {
case STRING_LIST:
list = new TagStringList();
case 10:
case OBJECT_LIST:
list = new TagObjectList();
case 5:
list = new TagFloatList();
case 6:
list = new TagDoubleList();
case 11:
list = new TagIntArrayList();
default:
throw new TagException("Type cannot be put in a list: " + any.json);
}
@ -501,7 +495,7 @@ public class TagInterpreter
if (this.jsonValue.equalsIgnoreCase("true") || this.jsonValue.equalsIgnoreCase("false"))
{
return new TagByte((byte)(Boolean.parseBoolean(this.jsonValue) ? 1 : 0));
return new TagBool(Boolean.parseBoolean(this.jsonValue));
}
}
catch (NumberFormatException var6)
@ -533,6 +527,29 @@ public class TagInterpreter
}
else
{
if (this.jsonValue.startsWith("'") && this.jsonValue.endsWith("'"))
{
String s = this.jsonValue.substring(1, this.jsonValue.length() - 1);
if(s.length() == 1 && s.charAt(0) != '\\') {
return new TagChar(s.charAt(0));
}
else if(s.length() == 2 && s.charAt(0) == '\\') {
switch(s.charAt(1)) {
case '\\':
return new TagChar('\\');
case 'n':
return new TagChar('\n');
}
}
else if((s.length() == 4 && s.startsWith("\\x")) || (s.length() == 6 && s.startsWith("\\u"))) {
try {
return new TagChar((char)Integer.parseUnsignedInt(s.substring(2), 16));
}
catch(NumberFormatException e) {
}
}
}
if (this.jsonValue.startsWith("\"") && this.jsonValue.endsWith("\""))
{
this.jsonValue = this.jsonValue.substring(1, this.jsonValue.length() - 1);

View file

@ -27,14 +27,14 @@ abstract class TagList<K extends Tag> extends Tag {
tracker.read(4 * len);
this.list = new ArrayList<K>(len);
for(int z = 0; z < len; z++) {
K tag = (K)Tag.createNewByType(this.getType());
K tag = (K)this.getElemType().createTag();
tag.read(input, depth + 1, tracker);
this.list.add(tag);
}
}
protected abstract byte getId();
protected abstract byte getType();
protected abstract TagType getType();
protected abstract TagType getElemType();
protected abstract TagList<K> createInstance();
protected abstract K getDefault();

View file

@ -4,65 +4,46 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagLong extends Tag
{
private long data;
class TagLong extends Tag {
private long data;
TagLong()
{
}
TagLong() {
}
public TagLong(long data)
{
this.data = data;
}
public TagLong(long data) {
this.data = data;
}
void write(DataOutput output) throws IOException
{
output.writeLong(this.data);
}
void write(DataOutput output) throws IOException {
output.writeLong(this.data);
}
void read(DataInput input, int depth, SizeTracker sizeTracker) throws IOException
{
sizeTracker.read(16);
this.data = input.readLong();
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(16);
this.data = input.readLong();
}
protected byte getId()
{
return (byte)4;
}
protected TagType getType() {
return TagType.LONG;
}
public String toString()
{
return "" + this.data + "L";
}
public String toString() {
return "" + this.data + "L";
}
public Tag copy()
{
return new TagLong(this.data);
}
public Tag copy() {
return new TagLong(this.data);
}
public boolean equals(Object other)
{
if (super.equals(other))
{
TagLong tag = (TagLong)other;
return this.data == tag.data;
}
else
{
return false;
}
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagLong)other).data;
}
public int hashCode()
{
return super.hashCode() ^ (int)(this.data ^ this.data >>> 32);
}
public int hashCode() {
return super.hashCode() ^ (int)(this.data ^ this.data >>> 32);
}
public long getLong()
{
return this.data;
}
public long getLong() {
return this.data;
}
}

View file

@ -12,8 +12,8 @@ class TagNull extends Tag {
void write(DataOutput output) throws IOException {
}
protected byte getId() {
return (byte)0;
protected TagType getType() {
return TagType.NULL;
}
public String toString() {

View file

@ -16,8 +16,8 @@ public class TagObject extends Tag {
void write(DataOutput output) throws IOException {
for(String key : this.tags.keySet()) {
Tag tag = this.tags.get(key);
output.writeByte(tag.getId());
if(tag.getId() != 0) {
output.writeByte(tag.getType().getId());
if(tag.getType() != TagType.NULL) {
output.writeUTF(key);
tag.write(output);
}
@ -34,7 +34,7 @@ public class TagObject extends Tag {
while((id = input.readByte()) != 0) {
String key = input.readUTF();
tracker.read(28 + 2 * key.length());
Tag tag = Tag.createNewByType(id);
Tag tag = TagType.create(id);
tag.read(input, depth + 1, tracker);
if(this.tags.put(key, tag) != null)
tracker.read(36);
@ -45,8 +45,8 @@ public class TagObject extends Tag {
return this.tags.keySet();
}
protected byte getId() {
return (byte)10;
protected TagType getType() {
return TagType.OBJECT;
}
public void set(String key, Tag value) {
@ -57,26 +57,18 @@ public class TagObject extends Tag {
this.tags.put(key, value);
}
public void setFloatList(String key, TagFloatList value) {
this.tags.put(key, value);
}
public void setDoubleList(String key, TagDoubleList value) {
this.tags.put(key, value);
}
public void setStringList(String key, TagStringList value) {
this.tags.put(key, value);
}
public void setIntArrayList(String key, TagIntArrayList value) {
this.tags.put(key, value);
}
public void setObjectList(String key, TagObjectList value) {
this.tags.put(key, value);
}
public void setBool(String key, boolean value) {
this.tags.put(key, new TagBool(value));
}
public void setByte(String key, byte value) {
this.tags.put(key, new TagByte(value));
}
@ -85,6 +77,10 @@ public class TagObject extends Tag {
this.tags.put(key, new TagShort(value));
}
public void setChar(String key, char value) {
this.tags.put(key, new TagChar(value));
}
public void setInt(String key, int value) {
this.tags.put(key, new TagInt(value));
}
@ -113,145 +109,125 @@ public class TagObject extends Tag {
this.tags.put(key, new TagIntArray(value));
}
public void setBool(String key, boolean value) {
this.setByte(key, (byte)(value ? 1 : 0));
}
public Tag get(String key) {
return this.tags.get(key);
}
private boolean has(String key, int type) {
private boolean has(String key, TagType type) {
Tag tag = this.tags.get(key);
return tag != null && tag.getId() == type;
return tag != null && tag.getType() == type;
}
public boolean hasBool(String key) {
return this.hasByte(key);
return this.has(key, TagType.BOOLEAN);
}
public boolean hasByte(String key) {
return this.has(key, 1);
return this.has(key, TagType.BYTE);
}
public boolean hasShort(String key) {
return this.has(key, 2);
return this.has(key, TagType.SHORT);
}
public boolean hasChar(String key) {
return this.has(key, TagType.CHAR);
}
public boolean hasInt(String key) {
return this.has(key, 3);
return this.has(key, TagType.INT);
}
public boolean hasLong(String key) {
return this.has(key, 4);
return this.has(key, TagType.LONG);
}
public boolean hasFloat(String key) {
return this.has(key, 5);
return this.has(key, TagType.FLOAT);
}
public boolean hasDouble(String key) {
return this.has(key, 6);
return this.has(key, TagType.DOUBLE);
}
public boolean hasString(String key) {
return this.has(key, 8);
return this.has(key, TagType.STRING);
}
public boolean hasByteArray(String key) {
return this.has(key, 7);
return this.has(key, TagType.BYTE_ARRAY);
}
public boolean hasIntArray(String key) {
return this.has(key, 11);
return this.has(key, TagType.INT_ARRAY);
}
public boolean hasObject(String key) {
return this.has(key, 10);
}
public boolean hasFloatList(String key) {
return this.has(key, 13);
}
public boolean hasDoubleList(String key) {
return this.has(key, 14);
return this.has(key, TagType.OBJECT);
}
public boolean hasStringList(String key) {
return this.has(key, 9);
}
public boolean hasIntArrayList(String key) {
return this.has(key, 15);
return this.has(key, TagType.STRING_LIST);
}
public boolean hasObjectList(String key) {
return this.has(key, 12);
}
public byte getByte(String key) {
return !this.has(key, 1) ? 0 : ((TagByte)this.tags.get(key)).getByte();
}
public short getShort(String key) {
return !this.has(key, 2) ? 0 : ((TagShort)this.tags.get(key)).getShort();
}
public int getInt(String key) {
return !this.has(key, 3) ? 0 : ((TagInt)this.tags.get(key)).getInt();
}
public long getLong(String key) {
return !this.has(key, 4) ? 0L : ((TagLong)this.tags.get(key)).getLong();
}
public float getFloat(String key) {
return !this.has(key, 5) ? 0.0F : ((TagFloat)this.tags.get(key)).getFloat();
}
public double getDouble(String key) {
return !this.has(key, 6) ? 0.0D : ((TagDouble)this.tags.get(key)).getDouble();
}
public String getString(String key) {
return !this.has(key, 8) ? "" : ((TagString)this.tags.get(key)).getString();
}
public byte[] getByteArray(String key) {
return !this.has(key, 7) ? new byte[0] : ((TagByteArray)this.tags.get(key)).getByteArray();
}
public int[] getIntArray(String key) {
return !this.has(key, 11) ? new int[0] : ((TagIntArray)this.tags.get(key)).getIntArray();
}
public TagObject getObject(String key) {
return !this.has(key, 10) ? new TagObject() : (TagObject)this.tags.get(key);
}
public TagFloatList getFloatList(String key) {
return !this.has(key, 13) ? new TagFloatList() : (TagFloatList)this.tags.get(key);
}
public TagDoubleList getDoubleList(String key) {
return !this.has(key, 14) ? new TagDoubleList() : (TagDoubleList)this.tags.get(key);
}
public TagStringList getStringList(String key) {
return !this.has(key, 9) ? new TagStringList() : (TagStringList)this.tags.get(key);
}
public TagIntArrayList getIntArrayList(String key) {
return !this.has(key, 15) ? new TagIntArrayList() : (TagIntArrayList)this.tags.get(key);
}
public TagObjectList getObjectList(String key) {
return !this.has(key, 12) ? new TagObjectList() : (TagObjectList)this.tags.get(key);
return this.has(key, TagType.OBJECT_LIST);
}
public boolean getBool(String key) {
return this.getByte(key) != 0;
return !this.has(key, TagType.BOOLEAN) ? false : ((TagBool)this.tags.get(key)).getBool();
}
public byte getByte(String key) {
return !this.has(key, TagType.BYTE) ? 0 : ((TagByte)this.tags.get(key)).getByte();
}
public short getShort(String key) {
return !this.has(key, TagType.SHORT) ? 0 : ((TagShort)this.tags.get(key)).getShort();
}
public char getChar(String key) {
return !this.has(key, TagType.CHAR) ? 0 : ((TagChar)this.tags.get(key)).getChar();
}
public int getInt(String key) {
return !this.has(key, TagType.INT) ? 0 : ((TagInt)this.tags.get(key)).getInt();
}
public long getLong(String key) {
return !this.has(key, TagType.LONG) ? 0L : ((TagLong)this.tags.get(key)).getLong();
}
public float getFloat(String key) {
return !this.has(key, TagType.FLOAT) ? 0.0F : ((TagFloat)this.tags.get(key)).getFloat();
}
public double getDouble(String key) {
return !this.has(key, TagType.DOUBLE) ? 0.0D : ((TagDouble)this.tags.get(key)).getDouble();
}
public String getString(String key) {
return !this.has(key, TagType.STRING) ? "" : ((TagString)this.tags.get(key)).getString();
}
public byte[] getByteArray(String key) {
return !this.has(key, TagType.BYTE_ARRAY) ? new byte[0] : ((TagByteArray)this.tags.get(key)).getByteArray();
}
public int[] getIntArray(String key) {
return !this.has(key, TagType.INT_ARRAY) ? new int[0] : ((TagIntArray)this.tags.get(key)).getIntArray();
}
public TagObject getObject(String key) {
return !this.has(key, TagType.OBJECT) ? new TagObject() : (TagObject)this.tags.get(key);
}
public TagStringList getStringList(String key) {
return !this.has(key, TagType.STRING_LIST) ? new TagStringList() : (TagStringList)this.tags.get(key);
}
public TagObjectList getObjectList(String key) {
return !this.has(key, TagType.OBJECT_LIST) ? new TagObjectList() : (TagObjectList)this.tags.get(key);
}
public void remove(String key) {
@ -296,8 +272,8 @@ public class TagObject extends Tag {
public void merge(TagObject other) {
for(String key : other.tags.keySet()) {
Tag tag = other.tags.get(key);
if(tag.getId() == 10) {
if(this.has(key, 10)) {
if(tag.getType() == TagType.OBJECT) {
if(this.has(key, TagType.OBJECT)) {
TagObject comp = this.getObject(key);
comp.merge((TagObject)tag);
}

View file

@ -1,12 +1,12 @@
package common.tags;
public class TagObjectList extends TagList<TagObject> {
protected byte getId() {
return 12;
protected TagType getType() {
return TagType.OBJECT_LIST;
}
protected byte getType() {
return 10;
protected TagType getElemType() {
return TagType.OBJECT;
}
protected TagList<TagObject> createInstance() {

View file

@ -4,65 +4,46 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
class TagShort extends Tag
{
private short data;
class TagShort extends Tag {
private short data;
public TagShort()
{
}
TagShort() {
}
public TagShort(short data)
{
this.data = data;
}
public TagShort(short data) {
this.data = data;
}
void write(DataOutput output) throws IOException
{
output.writeShort(this.data);
}
void write(DataOutput output) throws IOException {
output.writeShort(this.data);
}
void read(DataInput input, int depth, SizeTracker sizeTracker) throws IOException
{
sizeTracker.read(10);
this.data = input.readShort();
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(10);
this.data = input.readShort();
}
protected byte getId()
{
return (byte)2;
}
protected TagType getType() {
return TagType.SHORT;
}
public String toString()
{
return "" + this.data + "s";
}
public String toString() {
return "" + this.data + "s";
}
public Tag copy()
{
return new TagShort(this.data);
}
public Tag copy() {
return new TagShort(this.data);
}
public boolean equals(Object other)
{
if (super.equals(other))
{
TagShort tag = (TagShort)other;
return this.data == tag.data;
}
else
{
return false;
}
}
public boolean equals(Object other) {
return super.equals(other) && this.data == ((TagShort)other).data;
}
public int hashCode()
{
return super.hashCode() ^ this.data;
}
public int hashCode() {
return super.hashCode() ^ this.data;
}
public short getShort()
{
return this.data;
}
public short getShort() {
return this.data;
}
}

View file

@ -7,7 +7,7 @@ import java.io.IOException;
class TagString extends Tag {
private String data;
public TagString() {
TagString() {
this.data = "";
}
@ -27,8 +27,8 @@ class TagString extends Tag {
tracker.read(2 * this.data.length());
}
protected byte getId() {
return (byte)8;
protected TagType getType() {
return TagType.STRING;
}
public String toString() {

View file

@ -1,12 +1,12 @@
package common.tags;
public class TagStringList extends TagList<TagString> {
protected byte getId() {
return 9;
protected TagType getType() {
return TagType.STRING_LIST;
}
protected byte getType() {
return 8;
protected TagType getElemType() {
return TagType.STRING;
}
protected TagList<TagString> createInstance() {

View file

@ -0,0 +1,125 @@
package common.tags;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public enum TagType {
NULL { // 0
public Tag createTag() {
return new TagNull();
}
},
OBJECT { // 1
public Tag createTag() {
return new TagObject();
}
},
BOOLEAN { // 2
public Tag createTag() {
return new TagBool();
}
},
BYTE { // 3
public Tag createTag() {
return new TagByte();
}
},
SHORT { // 4
public Tag createTag() {
return new TagShort();
}
},
CHAR { // 5
public Tag createTag() {
return new TagChar();
}
},
INT { // 6
public Tag createTag() {
return new TagInt();
}
},
LONG { // 7
public Tag createTag() {
return new TagLong();
}
},
FLOAT { // 8
public Tag createTag() {
return new TagFloat();
}
},
DOUBLE { // 9
public Tag createTag() {
return new TagDouble();
}
},
STRING { // 10
public Tag createTag() {
return new TagString();
}
},
OBJECT_LIST { // 11
public Tag createTag() {
return new TagObjectList();
}
},
BYTE_ARRAY { // 12
public Tag createTag() {
return new TagByteArray();
}
},
INT_ARRAY { // 13
public Tag createTag() {
return new TagIntArray();
}
},
STRING_LIST { // 14
public Tag createTag() {
return new TagStringList();
}
};
private static final TagType[] TYPES;
private final byte id;
static {
TYPES = values();
}
static Tag create(byte id) {
return id >= 0 && id < TYPES.length ? TYPES[id].createTag() : new Tag() {
void write(DataOutput output) throws IOException {
throw new IOException("Kann keinen ungültigen Tag mit ID #" + id + " schreiben");
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
throw new IOException("Kann keinen ungültigen Tag mit ID #" + id + " lesen");
}
public String toString() {
return "<invalid>";
}
protected TagType getType() {
return null;
}
public Tag copy() {
return this;
}
};
}
private TagType() {
this.id = (byte)this.ordinal();
}
public abstract Tag createTag();
public byte getId() {
return this.id;
}
}