From 920c5ff44535bce9caf1f728986e7ba2f24735de Mon Sep 17 00:00:00 2001 From: YuTian <2953516620@qq.com> Date: Sat, 20 Jul 2024 02:59:21 +0800 Subject: [PATCH] v1.7.2 --- .../java/com/io/yutian/aulib/nbt/NBTByte.java | 14 ++++++++++++++ .../com/io/yutian/aulib/nbt/NBTByteArray.java | 14 ++++++++++++++ .../com/io/yutian/aulib/nbt/NBTCompound.java | 19 +++++++++++++++---- .../com/io/yutian/aulib/nbt/NBTDouble.java | 14 ++++++++++++++ .../com/io/yutian/aulib/nbt/NBTFloat.java | 14 ++++++++++++++ .../java/com/io/yutian/aulib/nbt/NBTInt.java | 14 ++++++++++++++ .../com/io/yutian/aulib/nbt/NBTIntArray.java | 15 +++++++++++++++ .../java/com/io/yutian/aulib/nbt/NBTList.java | 17 +++++++++++++++++ .../java/com/io/yutian/aulib/nbt/NBTLong.java | 14 ++++++++++++++ .../com/io/yutian/aulib/nbt/NBTLongArray.java | 15 +++++++++++++++ .../com/io/yutian/aulib/nbt/NBTShort.java | 15 +++++++++++++++ .../com/io/yutian/aulib/nbt/NBTString.java | 16 ++++++++++++++++ .../serializers/ItemStackSerializer.java | 5 +++-- 13 files changed, 180 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTByte.java b/src/main/java/com/io/yutian/aulib/nbt/NBTByte.java index 4f14919..61f0b6c 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTByte.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTByte.java @@ -57,6 +57,20 @@ public class NBTByte extends NBTNumber { return var0 ? new NBTByte((byte) 1) : new NBTByte((byte) 0); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTByte nbtByte = (NBTByte) o; + return value == nbtByte.value; + } + + @Override + public int hashCode() { + return value; + } + @Override public String toString() { return "NBTByte{" + diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java b/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java index a61c438..d1b5b4d 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java @@ -26,6 +26,20 @@ public class NBTByteArray implements INBT { return TYPE_ID; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTByteArray that = (NBTByteArray) o; + return Arrays.equals(value, that.value); + } + + @Override + public int hashCode() { + return Arrays.hashCode(value); + } + @Override public String toString() { return "NBTByteArray{" + diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTCompound.java b/src/main/java/com/io/yutian/aulib/nbt/NBTCompound.java index a6e62b8..48d3ffe 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTCompound.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTCompound.java @@ -1,9 +1,6 @@ package com.io.yutian.aulib.nbt; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; public class NBTCompound implements INBT { @@ -222,6 +219,20 @@ public class NBTCompound implements INBT { return TYPE_ID; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTCompound that = (NBTCompound) o; + return Objects.equals(nbtMap, that.nbtMap); + } + + @Override + public int hashCode() { + return Objects.hashCode(nbtMap); + } + @Override public String toString() { return "NBTCompound{" + diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTDouble.java b/src/main/java/com/io/yutian/aulib/nbt/NBTDouble.java index 9edc6ad..8357608 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTDouble.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTDouble.java @@ -53,6 +53,20 @@ public class NBTDouble extends NBTNumber { return (float) this.value; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTDouble nbtDouble = (NBTDouble) o; + return Double.compare(value, nbtDouble.value) == 0; + } + + @Override + public int hashCode() { + return Double.hashCode(value); + } + @Override public String toString() { return "NBTDouble{" + diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTFloat.java b/src/main/java/com/io/yutian/aulib/nbt/NBTFloat.java index cba626a..81aba44 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTFloat.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTFloat.java @@ -50,6 +50,20 @@ public class NBTFloat extends NBTNumber { return this.value; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTFloat nbtFloat = (NBTFloat) o; + return Float.compare(value, nbtFloat.value) == 0; + } + + @Override + public int hashCode() { + return Float.hashCode(value); + } + @Override public String toString() { return "NBTFloat{" + diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTInt.java b/src/main/java/com/io/yutian/aulib/nbt/NBTInt.java index 24b77e5..dd0a092 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTInt.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTInt.java @@ -50,6 +50,20 @@ public class NBTInt extends NBTNumber { return this.value; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTInt nbtInt = (NBTInt) o; + return value == nbtInt.value; + } + + @Override + public int hashCode() { + return value; + } + @Override public String toString() { return "NBTInt{" + diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java b/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java index e04f2c4..093b4a0 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java @@ -1,5 +1,7 @@ package com.io.yutian.aulib.nbt; +import java.util.Arrays; + public class NBTIntArray implements INBT { public static byte TYPE_ID = 11; @@ -24,4 +26,17 @@ public class NBTIntArray implements INBT { return TYPE_ID; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTIntArray that = (NBTIntArray) o; + return Arrays.equals(value, that.value); + } + + @Override + public int hashCode() { + return Arrays.hashCode(value); + } } diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTList.java b/src/main/java/com/io/yutian/aulib/nbt/NBTList.java index 488513a..4166675 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTList.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTList.java @@ -2,6 +2,7 @@ package com.io.yutian.aulib.nbt; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class NBTList implements INBT { @@ -66,6 +67,22 @@ public class NBTList implements INBT { return type; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTList nbtList = (NBTList) o; + return type == nbtList.type && Objects.equals(value, nbtList.value); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(value); + result = 31 * result + type; + return result; + } + @Override public String toString() { return "NBTList{" + diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTLong.java b/src/main/java/com/io/yutian/aulib/nbt/NBTLong.java index 31c33de..d2d83cd 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTLong.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTLong.java @@ -59,4 +59,18 @@ public class NBTLong extends NBTNumber { "value=" + value + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTLong nbtLong = (NBTLong) o; + return value == nbtLong.value; + } + + @Override + public int hashCode() { + return Long.hashCode(value); + } } diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java b/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java index 221ca91..a834945 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java @@ -1,5 +1,7 @@ package com.io.yutian.aulib.nbt; +import java.util.Arrays; + public class NBTLongArray implements INBT { public static byte TYPE_ID = 12; @@ -24,4 +26,17 @@ public class NBTLongArray implements INBT { return TYPE_ID; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTLongArray that = (NBTLongArray) o; + return Arrays.equals(value, that.value); + } + + @Override + public int hashCode() { + return Arrays.hashCode(value); + } } diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTShort.java b/src/main/java/com/io/yutian/aulib/nbt/NBTShort.java index c9e7c53..c77903e 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTShort.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTShort.java @@ -53,10 +53,25 @@ public class NBTShort extends NBTNumber { return this.value; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTShort nbtShort = (NBTShort) o; + return value == nbtShort.value; + } + + @Override + public int hashCode() { + return value; + } + @Override public String toString() { return "NBTShort{" + "value=" + value + '}'; } + } diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTString.java b/src/main/java/com/io/yutian/aulib/nbt/NBTString.java index b20d99d..ed1cd57 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTString.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTString.java @@ -1,5 +1,7 @@ package com.io.yutian.aulib.nbt; +import java.util.Objects; + public class NBTString implements INBT { public static byte TYPE_ID = 8; @@ -27,6 +29,20 @@ public class NBTString implements INBT { return TYPE_ID; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NBTString nbtString = (NBTString) o; + return Objects.equals(value, nbtString.value); + } + + @Override + public int hashCode() { + return Objects.hashCode(value); + } + @Override public String toString() { return "NBTString{" + diff --git a/src/main/java/com/io/yutian/aulib/serialize/serializers/ItemStackSerializer.java b/src/main/java/com/io/yutian/aulib/serialize/serializers/ItemStackSerializer.java index a29a288..da16f24 100644 --- a/src/main/java/com/io/yutian/aulib/serialize/serializers/ItemStackSerializer.java +++ b/src/main/java/com/io/yutian/aulib/serialize/serializers/ItemStackSerializer.java @@ -16,7 +16,7 @@ public class ItemStackSerializer implements Serializer { jsonObject.put("id", nmsItemStack.c().k().g().a()); jsonObject.put("Count", nmsItemStack.J()); NBTTagCompound nbtTagCompound = nmsItemStack.u(); - jsonObject.put("tag", nbtTagCompound.toString()); + jsonObject.put("tag", new JSONObject(nbtTagCompound.toString())); return jsonObject; } @@ -31,7 +31,8 @@ public class ItemStackSerializer implements Serializer { e.printStackTrace(); return null; } - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.a(nbtTagCompound)); + net.minecraft.world.item.ItemStack nmsItemStack = net.minecraft.world.item.ItemStack.a(nbtTagCompound); + return CraftItemStack.asCraftMirror(nmsItemStack); } }