diff --git a/common/src/main/java/common/entity/Entity.java b/common/src/main/java/common/entity/Entity.java index 7d5c36e..64e5b4e 100755 --- a/common/src/main/java/common/entity/Entity.java +++ b/common/src/main/java/common/entity/Entity.java @@ -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); diff --git a/common/src/main/java/common/entity/animal/EntityWolf.java b/common/src/main/java/common/entity/animal/EntityWolf.java index ef9a419..af2159d 100755 --- a/common/src/main/java/common/entity/animal/EntityWolf.java +++ b/common/src/main/java/common/entity/animal/EntityWolf.java @@ -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"))); } /** diff --git a/common/src/main/java/common/entity/projectile/EntityArrow.java b/common/src/main/java/common/entity/projectile/EntityArrow.java index 5751b7e..508ae4e 100755 --- a/common/src/main/java/common/entity/projectile/EntityArrow.java +++ b/common/src/main/java/common/entity/projectile/EntityArrow.java @@ -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"); diff --git a/common/src/main/java/common/entity/projectile/EntityHook.java b/common/src/main/java/common/entity/projectile/EntityHook.java index 559912b..b57e1f0 100755 --- a/common/src/main/java/common/entity/projectile/EntityHook.java +++ b/common/src/main/java/common/entity/projectile/EntityHook.java @@ -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() diff --git a/common/src/main/java/common/entity/projectile/EntityProjectile.java b/common/src/main/java/common/entity/projectile/EntityProjectile.java index 03d67e2..bd69c99 100755 --- a/common/src/main/java/common/entity/projectile/EntityProjectile.java +++ b/common/src/main/java/common/entity/projectile/EntityProjectile.java @@ -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 { diff --git a/common/src/main/java/common/entity/types/EntityThrowable.java b/common/src/main/java/common/entity/types/EntityThrowable.java index 69e13ac..9752a68 100755 --- a/common/src/main/java/common/entity/types/EntityThrowable.java +++ b/common/src/main/java/common/entity/types/EntityThrowable.java @@ -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"); // diff --git a/common/src/main/java/common/tags/Tag.java b/common/src/main/java/common/tags/Tag.java index 5d464c7..000856f 100755 --- a/common/src/main/java/common/tags/Tag.java +++ b/common/src/main/java/common/tags/Tag.java @@ -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(); } } diff --git a/common/src/main/java/common/tags/TagBool.java b/common/src/main/java/common/tags/TagBool.java new file mode 100644 index 0000000..062b9e1 --- /dev/null +++ b/common/src/main/java/common/tags/TagBool.java @@ -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; + } +} diff --git a/common/src/main/java/common/tags/TagByte.java b/common/src/main/java/common/tags/TagByte.java index 96b471e..a93cf11 100755 --- a/common/src/main/java/common/tags/TagByte.java +++ b/common/src/main/java/common/tags/TagByte.java @@ -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; + } } diff --git a/common/src/main/java/common/tags/TagByteArray.java b/common/src/main/java/common/tags/TagByteArray.java index 0579c12..4c6bc72 100755 --- a/common/src/main/java/common/tags/TagByteArray.java +++ b/common/src/main/java/common/tags/TagByteArray.java @@ -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() { diff --git a/common/src/main/java/common/tags/TagChar.java b/common/src/main/java/common/tags/TagChar.java new file mode 100644 index 0000000..8a0ee36 --- /dev/null +++ b/common/src/main/java/common/tags/TagChar.java @@ -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; + } +} diff --git a/common/src/main/java/common/tags/TagDouble.java b/common/src/main/java/common/tags/TagDouble.java index 4c9152b..b155968 100755 --- a/common/src/main/java/common/tags/TagDouble.java +++ b/common/src/main/java/common/tags/TagDouble.java @@ -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; + } } diff --git a/common/src/main/java/common/tags/TagDoubleList.java b/common/src/main/java/common/tags/TagDoubleList.java deleted file mode 100644 index dad8e01..0000000 --- a/common/src/main/java/common/tags/TagDoubleList.java +++ /dev/null @@ -1,27 +0,0 @@ -package common.tags; - -public class TagDoubleList extends TagList { - protected byte getId() { - return 14; - } - - protected byte getType() { - return 6; - } - - protected TagList 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)); - } -} diff --git a/common/src/main/java/common/tags/TagFloat.java b/common/src/main/java/common/tags/TagFloat.java index 97265f0..9122edf 100755 --- a/common/src/main/java/common/tags/TagFloat.java +++ b/common/src/main/java/common/tags/TagFloat.java @@ -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; + } } diff --git a/common/src/main/java/common/tags/TagFloatList.java b/common/src/main/java/common/tags/TagFloatList.java deleted file mode 100644 index 1c62d1f..0000000 --- a/common/src/main/java/common/tags/TagFloatList.java +++ /dev/null @@ -1,27 +0,0 @@ -package common.tags; - -public class TagFloatList extends TagList { - protected byte getId() { - return 13; - } - - protected byte getType() { - return 5; - } - - protected TagList 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)); - } -} diff --git a/common/src/main/java/common/tags/TagInt.java b/common/src/main/java/common/tags/TagInt.java index c795914..75e355b 100755 --- a/common/src/main/java/common/tags/TagInt.java +++ b/common/src/main/java/common/tags/TagInt.java @@ -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; + } } diff --git a/common/src/main/java/common/tags/TagIntArray.java b/common/src/main/java/common/tags/TagIntArray.java index 56e0626..cf7d34f 100755 --- a/common/src/main/java/common/tags/TagIntArray.java +++ b/common/src/main/java/common/tags/TagIntArray.java @@ -32,8 +32,8 @@ class TagIntArray extends Tag { } } - protected byte getId() { - return (byte)11; + protected TagType getType() { + return TagType.INT_ARRAY; } public String toString() { diff --git a/common/src/main/java/common/tags/TagIntArrayList.java b/common/src/main/java/common/tags/TagIntArrayList.java deleted file mode 100644 index e051872..0000000 --- a/common/src/main/java/common/tags/TagIntArrayList.java +++ /dev/null @@ -1,27 +0,0 @@ -package common.tags; - -public class TagIntArrayList extends TagList { - protected byte getId() { - return 15; - } - - protected byte getType() { - return 11; - } - - protected TagList 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)); - } -} diff --git a/common/src/main/java/common/tags/TagInterpreter.java b/common/src/main/java/common/tags/TagInterpreter.java index d401d36..abe0f1e 100755 --- a/common/src/main/java/common/tags/TagInterpreter.java +++ b/common/src/main/java/common/tags/TagInterpreter.java @@ -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); diff --git a/common/src/main/java/common/tags/TagList.java b/common/src/main/java/common/tags/TagList.java index f74d206..ffedf00 100755 --- a/common/src/main/java/common/tags/TagList.java +++ b/common/src/main/java/common/tags/TagList.java @@ -27,14 +27,14 @@ abstract class TagList extends Tag { tracker.read(4 * len); this.list = new ArrayList(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 createInstance(); protected abstract K getDefault(); diff --git a/common/src/main/java/common/tags/TagLong.java b/common/src/main/java/common/tags/TagLong.java index c3979da..b5648c6 100755 --- a/common/src/main/java/common/tags/TagLong.java +++ b/common/src/main/java/common/tags/TagLong.java @@ -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; + } } diff --git a/common/src/main/java/common/tags/TagNull.java b/common/src/main/java/common/tags/TagNull.java index caeab7f..eb9d27c 100755 --- a/common/src/main/java/common/tags/TagNull.java +++ b/common/src/main/java/common/tags/TagNull.java @@ -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() { diff --git a/common/src/main/java/common/tags/TagObject.java b/common/src/main/java/common/tags/TagObject.java index 129f9c7..afa3b73 100755 --- a/common/src/main/java/common/tags/TagObject.java +++ b/common/src/main/java/common/tags/TagObject.java @@ -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); } diff --git a/common/src/main/java/common/tags/TagObjectList.java b/common/src/main/java/common/tags/TagObjectList.java index fb1a78b..c4b5245 100644 --- a/common/src/main/java/common/tags/TagObjectList.java +++ b/common/src/main/java/common/tags/TagObjectList.java @@ -1,12 +1,12 @@ package common.tags; public class TagObjectList extends TagList { - 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 createInstance() { diff --git a/common/src/main/java/common/tags/TagShort.java b/common/src/main/java/common/tags/TagShort.java index 26df0df..321eef6 100755 --- a/common/src/main/java/common/tags/TagShort.java +++ b/common/src/main/java/common/tags/TagShort.java @@ -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; + } } diff --git a/common/src/main/java/common/tags/TagString.java b/common/src/main/java/common/tags/TagString.java index 296bc87..4f11bd0 100755 --- a/common/src/main/java/common/tags/TagString.java +++ b/common/src/main/java/common/tags/TagString.java @@ -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() { diff --git a/common/src/main/java/common/tags/TagStringList.java b/common/src/main/java/common/tags/TagStringList.java index 1f4f89a..242fb1b 100644 --- a/common/src/main/java/common/tags/TagStringList.java +++ b/common/src/main/java/common/tags/TagStringList.java @@ -1,12 +1,12 @@ package common.tags; public class TagStringList extends TagList { - 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 createInstance() { diff --git a/common/src/main/java/common/tags/TagType.java b/common/src/main/java/common/tags/TagType.java new file mode 100644 index 0000000..239d0c3 --- /dev/null +++ b/common/src/main/java/common/tags/TagType.java @@ -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 ""; + } + + 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; + } +} diff --git a/server/src/main/java/server/Server.java b/server/src/main/java/server/Server.java index b28b429..e87c6ed 100755 --- a/server/src/main/java/server/Server.java +++ b/server/src/main/java/server/Server.java @@ -80,8 +80,6 @@ import common.packet.SPacketSkin; import common.packet.SPacketTimeUpdate; import common.packet.SPacketWorld; import common.potion.PotionEffect; -import common.tags.TagDoubleList; -import common.tags.TagFloatList; import common.tags.TagLoader; import common.tags.TagObject; import common.util.BlockPos; @@ -329,13 +327,11 @@ public final class Server implements IThreadListener { TagObject tag = this.loadPlayerData(user); if(tag == null) return null; - TagDoubleList pos = tag.getDoubleList("Pos"); - TagFloatList rot = tag.getFloatList("Rotation"); - double posX = pos.get(0); - double posY = pos.get(1); - double posZ = pos.get(2); - float rotYaw = rot.get(0); - float rotPitch = rot.get(1); + double posX = tag.getDouble("PosX"); + double posY = tag.getDouble("PosY"); + double posZ = tag.getDouble("PosZ"); + float rotYaw = tag.getFloat("Yaw"); + float rotPitch = tag.getFloat("Pitch"); int dimension = tag.getInt("Dimension"); return new Position(posX, posY, posZ, rotYaw, rotPitch, dimension); } diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index e1caeac..6f2596f 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -101,7 +101,6 @@ import common.packet.CPacketAction.Action; import common.packet.SPacketMessage.Type; import common.potion.Potion; import common.potion.PotionEffect; -import common.tags.TagDoubleList; import common.tags.TagObject; import common.tags.TagObjectList; import common.tileentity.IInteractionObject; @@ -1636,10 +1635,9 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer if(info != null && info.isEmpty()) info = null; Alignment align = Alignment.getByName(tag.getString("Align")); - TagDoubleList position = tag.getDoubleList("Pos"); Dimension dimension = UniverseRegistry.getDimension(tag.getInt("Dimension")); String dim = dimension == null ? "???" : dimension.getFormattedName(false); - BlockPos pos = new BlockPos(position.get(0), position.get(1), position.get(2)); + BlockPos pos = new BlockPos(tag.getDouble("PosX"), tag.getDouble("PosY"), tag.getDouble("PosZ")); String type = EntityRegistry.getEntityName(tag.getString("id")); int level = tag.getInt("XpLevel"); return new PlayerCharacter(name, info, align, dim, pos, type, level); diff --git a/server/src/main/java/server/world/Converter.java b/server/src/main/java/server/world/Converter.java index 4fc55ba..b4e68c6 100644 --- a/server/src/main/java/server/world/Converter.java +++ b/server/src/main/java/server/world/Converter.java @@ -68,8 +68,6 @@ import common.init.TileRegistry; import common.init.UniverseRegistry; import common.log.Log; import common.rng.Random; -import common.tags.TagDoubleList; -import common.tags.TagFloatList; import common.tags.TagLoader; import common.tags.TagObject; import common.tags.TagObjectList; @@ -997,22 +995,6 @@ public abstract class Converter { return idx >= 0 ? name.substring(idx + 1) : name; // save compat } - private static TagFloatList getList(float[] values) { - TagFloatList nlist = new TagFloatList(); - for(int z = 0; z < values.length; z++) { - nlist.add(values[z]); - } - return nlist; - } - - private static TagDoubleList getList(double[] values) { - TagDoubleList nlist = new TagDoubleList(); - for(int z = 0; z < values.length; z++) { - nlist.add(values[z]); - } - return nlist; - } - private static TagObject convertChunkData(NbtTag tag, boolean legacy) { TagObject ntag = new TagObject(); tag = tag.getTag("Level"); @@ -1092,9 +1074,14 @@ public abstract class Converter { if(pos.length != 3 || motion.length != 3 || rotation.length != 2) continue; boolean ground = ent.getByte("OnGround") != 0; - nent.setDoubleList("Pos", getList(pos)); - nent.setDoubleList("Motion", getList(motion)); - nent.setFloatList("Rotation", getList(rotation)); + nent.setDouble("PosX", pos[0]); + nent.setDouble("PosY", pos[1]); + nent.setDouble("PosZ", pos[2]); + nent.setDouble("MotionX", motion[0]); + nent.setDouble("MotionY", motion[1]); + nent.setDouble("MotionZ", motion[2]); + nent.setFloat("Yaw", rotation[0]); + nent.setFloat("Pitch", rotation[1]); nent.setBool("OnGround", ground); nent.setInt("Dimension", 1); nent.setString("id", mapped); @@ -1123,6 +1110,7 @@ public abstract class Converter { entities = new TagObjectList(); for(NbtTag sect : sects) { TagObject nsect = new TagObject(); + nsect.setInt("Y", sect.getByte("Y")); byte[] blocks = sect.getByteArray("Blocks"); NibbleArray data = new NibbleArray(sect.getByteArray("Data")); byte[] add = sect.getByteArray("Add"); diff --git a/server/src/main/java/server/worldgen/structure/StructureBoundingBox.java b/server/src/main/java/server/worldgen/structure/StructureBoundingBox.java index b0dda2b..a4b8110 100755 --- a/server/src/main/java/server/worldgen/structure/StructureBoundingBox.java +++ b/server/src/main/java/server/worldgen/structure/StructureBoundingBox.java @@ -41,6 +41,16 @@ public class StructureBoundingBox } } + public StructureBoundingBox(int[] coords, int offset) + { + this.minX = coords[offset + 0]; + this.minY = coords[offset + 1]; + this.minZ = coords[offset + 2]; + this.maxX = coords[offset + 3]; + this.maxY = coords[offset + 4]; + this.maxZ = coords[offset + 5]; + } + /** * returns a new StructureBoundingBox with MAX values */ @@ -212,4 +222,14 @@ public class StructureBoundingBox { return new int[] {this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ}; } + + public void toIntArray(int[] data, int offset) + { + data[offset + 0] = this.minX; + data[offset + 1] = this.minY; + data[offset + 2] = this.minZ; + data[offset + 3] = this.maxX; + data[offset + 4] = this.maxY; + data[offset + 5] = this.maxZ; + } } diff --git a/server/src/main/java/server/worldgen/structure/StructureMineshaft.java b/server/src/main/java/server/worldgen/structure/StructureMineshaft.java index c4baaef..a586573 100755 --- a/server/src/main/java/server/worldgen/structure/StructureMineshaft.java +++ b/server/src/main/java/server/worldgen/structure/StructureMineshaft.java @@ -9,7 +9,6 @@ import common.init.Items; import common.item.RngLoot; import common.rng.Random; import common.rng.WeightedList; -import common.tags.TagIntArrayList; import common.tags.TagObject; import common.tileentity.TileEntity; import common.tileentity.TileEntityMobSpawner; @@ -712,23 +711,23 @@ public class StructureMineshaft protected void writeTags(TagObject tag) { - TagIntArrayList list = new TagIntArrayList(); + int[] rooms = new int[this.roomsLinkedToTheRoom.size() * 6]; - for (StructureBoundingBox bb : this.roomsLinkedToTheRoom) + for (int z = 0; z < rooms.length / 6; z++) { - list.add(bb.toIntArray()); + this.roomsLinkedToTheRoom.get(z).toIntArray(rooms, z * 6); } - tag.setIntArrayList("Entrances", list); + tag.setIntArray("Entrances", rooms); } protected void readTags(TagObject tag) { - TagIntArrayList list = tag.getIntArrayList("Entrances"); + int[] rooms = tag.getIntArray("Entrances"); - for (int i = 0; i < list.size(); ++i) + for (int z = 0; z < rooms.length / 6; z++) { - this.roomsLinkedToTheRoom.add(new StructureBoundingBox(list.get(i))); + this.roomsLinkedToTheRoom.add(new StructureBoundingBox(rooms, z * 6)); } } }