This commit is contained in:
YuTian 2024-07-20 02:59:21 +08:00
parent 30dd5edd4e
commit 920c5ff445
13 changed files with 180 additions and 6 deletions

View File

@ -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{" +

View File

@ -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{" +

View File

@ -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{" +

View File

@ -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{" +

View File

@ -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{" +

View File

@ -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{" +

View File

@ -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);
}
}

View File

@ -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<T extends INBT> implements INBT {
@ -66,6 +67,22 @@ public class NBTList<T extends INBT> 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{" +

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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 +
'}';
}
}

View File

@ -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{" +

View File

@ -16,7 +16,7 @@ public class ItemStackSerializer implements Serializer<ItemStack> {
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<ItemStack> {
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);
}
}