Target the tag compound

This commit is contained in:
nossr50 2019-10-01 16:52:35 -07:00
parent 365938f351
commit 4bff07bd2b

View File

@ -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) {