mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-18 08:25:27 +01:00
Target the tag compound
This commit is contained in:
parent
365938f351
commit
4bff07bd2b
@ -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) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user