mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-19 00:45:27 +01:00
Target the tag compound
This commit is contained in:
parent
365938f351
commit
4bff07bd2b
@ -59,29 +59,41 @@ public class NBTManager {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public NBTTagCompound getNBTCopy(ItemStack itemStack) {
|
public NBTTagCompound getNBTCopy(ItemStack itemStack) {
|
||||||
net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(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) {
|
public void addFloatNBT(ItemStack itemStack, String key, float value) {
|
||||||
//NBT Copied off Item
|
//NBT Copied off Item
|
||||||
net.minecraft.server.v1_14_R1.ItemStack nmsIS = getNMSItemStack(itemStack);
|
net.minecraft.server.v1_14_R1.ItemStack nmsIS = getNMSItemStack(itemStack);
|
||||||
NBTTagCompound freshNBTCopy = nmsIS.save(new NBTTagCompound());
|
NBTTagCompound freshNBTCopy = getNBTCopy(itemStack);
|
||||||
|
|
||||||
//New Float NBT Value
|
//New Float NBT Value
|
||||||
NBTTagCompound updatedNBT = new NBTTagCompound();
|
NBTTagCompound updatedNBT = new NBTTagCompound();
|
||||||
updatedNBT.setFloat(key, value);
|
updatedNBT.setFloat(key, value);
|
||||||
|
|
||||||
//Merge
|
//Merge
|
||||||
freshNBTCopy.a(updatedNBT);
|
mergeToTagCompound(freshNBTCopy, updatedNBT);
|
||||||
|
|
||||||
//Invoke load() time
|
//Invoke load() time
|
||||||
applyNBT(nmsIS, updatedNBT);
|
applyNBT(nmsIS, freshNBTCopy);
|
||||||
|
|
||||||
//Apply Item Meta (Not sure if needed)
|
//Apply Item Meta (Not sure if needed)
|
||||||
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsIS);
|
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsIS);
|
||||||
itemStack.setItemMeta(craftItemStack.getItemMeta());
|
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) {
|
public void applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user