v1.7.3
This commit is contained in:
parent
920c5ff445
commit
d0af42f291
|
@ -1,5 +1,7 @@
|
||||||
package com.io.yutian.aulib.nbt;
|
package com.io.yutian.aulib.nbt;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class NBTCompound implements INBT {
|
public class NBTCompound implements INBT {
|
||||||
|
@ -225,7 +227,31 @@ public class NBTCompound implements INBT {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
NBTCompound that = (NBTCompound) o;
|
NBTCompound that = (NBTCompound) o;
|
||||||
return Objects.equals(nbtMap, that.nbtMap);
|
Map<String, INBT> nbtMap1 = this.nbtMap;
|
||||||
|
Map<String, INBT> nbtMap2 = that.nbtMap;
|
||||||
|
if (nbtMap1.size() != nbtMap2.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, INBT> entry : nbtMap1.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
INBT value = entry.getValue();
|
||||||
|
if (!nbtMap2.containsKey(key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
INBT nbt2 = nbtMap2.get(key);
|
||||||
|
Object object1 = value.getValue();
|
||||||
|
Object object2 = nbt2.getValue();
|
||||||
|
if (value == null && nbt2 != null) {
|
||||||
|
return false;
|
||||||
|
} else if (object1 instanceof Number && object2 instanceof Number) {
|
||||||
|
if (Double.compare(((Number) object1).doubleValue(), ((Number) object2).doubleValue()) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!object1.equals(object2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,9 +2,10 @@ package com.io.yutian.aulib.serialize.serializers;
|
||||||
|
|
||||||
import com.io.yutian.aulib.serialize.Serializer;
|
import com.io.yutian.aulib.serialize.Serializer;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.*;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class ItemStackSerializer implements Serializer<ItemStack> {
|
public class ItemStackSerializer implements Serializer<ItemStack> {
|
||||||
|
@ -16,10 +17,66 @@ public class ItemStackSerializer implements Serializer<ItemStack> {
|
||||||
jsonObject.put("id", nmsItemStack.c().k().g().a());
|
jsonObject.put("id", nmsItemStack.c().k().g().a());
|
||||||
jsonObject.put("Count", nmsItemStack.J());
|
jsonObject.put("Count", nmsItemStack.J());
|
||||||
NBTTagCompound nbtTagCompound = nmsItemStack.u();
|
NBTTagCompound nbtTagCompound = nmsItemStack.u();
|
||||||
jsonObject.put("tag", new JSONObject(nbtTagCompound.toString()));
|
JSONObject tagJsonObject = new JSONObject();
|
||||||
|
for (String key : nbtTagCompound.d()) {
|
||||||
|
NBTBase nbtBase = nbtTagCompound.c(key);
|
||||||
|
tagJsonObject.put(key, serializeNBT(nbtBase));
|
||||||
|
}
|
||||||
|
jsonObject.put("tag", tagJsonObject);
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object serializeNBT(NBTBase nbtBase) {
|
||||||
|
byte type = nbtBase.a();
|
||||||
|
switch (type) {
|
||||||
|
case 1:
|
||||||
|
NBTTagByte nbtTagByte = (NBTTagByte) nbtBase;
|
||||||
|
return nbtTagByte.h();
|
||||||
|
case 2:
|
||||||
|
NBTTagShort nbtTagShort = (NBTTagShort) nbtBase;
|
||||||
|
return nbtTagShort.g();
|
||||||
|
case 3:
|
||||||
|
NBTTagInt nbtTagInt = (NBTTagInt) nbtBase;
|
||||||
|
return nbtTagInt.f();
|
||||||
|
case 4:
|
||||||
|
NBTTagLong nbtTagLong = (NBTTagLong) nbtBase;
|
||||||
|
return nbtTagLong.e();
|
||||||
|
case 5:
|
||||||
|
NBTTagFloat nbtTagFloat = (NBTTagFloat) nbtBase;
|
||||||
|
return nbtTagFloat.j();
|
||||||
|
case 6:
|
||||||
|
NBTTagDouble nbtTagDouble = (NBTTagDouble) nbtBase;
|
||||||
|
return nbtTagDouble.i();
|
||||||
|
case 7:
|
||||||
|
NBTTagByteArray tagByteArray = (NBTTagByteArray) nbtBase;
|
||||||
|
return tagByteArray.d();
|
||||||
|
case 8:
|
||||||
|
NBTTagString nbtTagString = (NBTTagString) nbtBase;
|
||||||
|
return nbtTagString.e_();
|
||||||
|
case 9:
|
||||||
|
NBTTagList nbtTagList = (NBTTagList) nbtBase;
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
for (net.minecraft.nbt.NBTBase base : nbtTagList) {
|
||||||
|
jsonArray.put(serializeNBT(base));
|
||||||
|
}
|
||||||
|
return jsonArray;
|
||||||
|
case 10:
|
||||||
|
NBTTagCompound nbtTagCompound = (NBTTagCompound) nbtBase;
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
for (String key : nbtTagCompound.d()) {
|
||||||
|
jsonObject.put(key, serializeNBT(nbtTagCompound.c(key)));
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
|
case 11:
|
||||||
|
NBTTagIntArray nbtTagIntArray = (NBTTagIntArray) nbtBase;
|
||||||
|
return nbtTagIntArray.f();
|
||||||
|
case 12:
|
||||||
|
NBTTagLongArray nbtTagLongArray = (NBTTagLongArray) nbtBase;
|
||||||
|
return nbtTagLongArray.f();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack deserialize(Object value) {
|
public ItemStack deserialize(Object value) {
|
||||||
JSONObject jsonObject = (JSONObject) value;
|
JSONObject jsonObject = (JSONObject) value;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: AuLib
|
name: AuLib
|
||||||
main: com.io.yutian.aulib.AuLib
|
main: com.io.yutian.aulib.AuLib
|
||||||
version: 1.7
|
version: 1.7.3
|
||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
author: SuperYuTian
|
author: SuperYuTian
|
Loading…
Reference in New Issue
Block a user