浏览代码

Target the tag compound

nossr50 5 年之前
父节点
当前提交
4bff07bd2b
共有 1 个文件被更改,包括 16 次插入4 次删除
  1. 16 4
      mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java

+ 16 - 4
mcmmo-core/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java

@@ -59,29 +59,41 @@ public class NBTManager {
     @NonNull
     public NBTTagCompound getNBTCopy(ItemStack itemStack) {
         net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
-        return nmsItemStack.save(new NBTTagCompound());
+        NBTTagCompound freshNBTCopy = nmsItemStack.save(new NBTTagCompound());
+
+        if(!freshNBTCopy.hasKeyOfType("tag", 10)) {
+            freshNBTCopy.set("tag", new NBTTagCompound());
+        }
+
+        return freshNBTCopy;
     }
 
     public void addFloatNBT(ItemStack itemStack, String key, float value) {
         //NBT Copied off Item
         net.minecraft.server.v1_14_R1.ItemStack nmsIS = getNMSItemStack(itemStack);
-        NBTTagCompound freshNBTCopy = nmsIS.save(new NBTTagCompound());
+        NBTTagCompound freshNBTCopy = getNBTCopy(itemStack);
 
         //New Float NBT Value
         NBTTagCompound updatedNBT = new NBTTagCompound();
         updatedNBT.setFloat(key, value);
 
         //Merge
-        freshNBTCopy.a(updatedNBT);
+        mergeToTagCompound(freshNBTCopy, updatedNBT);
 
         //Invoke load() time
-        applyNBT(nmsIS, updatedNBT);
+        applyNBT(nmsIS, freshNBTCopy);
 
         //Apply Item Meta (Not sure if needed)
         CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsIS);
         itemStack.setItemMeta(craftItemStack.getItemMeta());
     }
 
+    public void mergeToTagCompound(NBTTagCompound targetCompound, NBTTagCompound modificationCompound) {
+        NBTTagCompound tagCompound = (NBTTagCompound) targetCompound.get("tag");
+        tagCompound.a(modificationCompound);
+    }
+
+
 
     public void applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) {