Time for a break

This commit is contained in:
nossr50 2019-09-30 17:53:57 -07:00
parent 0509f4f63e
commit 433f6d085d

View File

@ -1,9 +1,11 @@
package com.gmail.nossr50.util.nbt;
import net.minecraft.server.v1_14_R1.Item;
import net.minecraft.server.v1_14_R1.NBTBase;
import net.minecraft.server.v1_14_R1.NBTList;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer;
import org.bukkit.entity.Player;
@ -41,6 +43,29 @@ public class NBTManager {
player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size());
printNBT(nbtTagCompound, player);
player.sendMessage("-- END OF NBT REPORT --");
player.sendMessage("Attempting to add NBT key named - Herp");
addFloatNBT(nbtTagCompound, "herp", 13.37F);
player.sendMessage("(After HERP) Total NBT Entries: "+nbtTagCompound.getKeys().size());
printNBT(nbtTagCompound, player);
player.sendMessage("-- END OF NBT REPORT --");
player.sendMessage("Attempting to save NBT data...");
player.getInventory().setItemInMainHand(saveNBT(itemStack, nbtTagCompound));
player.updateInventory();
}
public static ItemStack saveNBT(ItemStack itemStack, NBTTagCompound nbtTagCompound) {
net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = getNMSItemStack(itemStack);
nmsItemStack.save(nbtTagCompound);
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(nmsItemStack);
itemStack.setItemMeta(craftItemStack.getItemMeta());
return itemStack;
}
public static net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack);
}
@Nullable
@ -49,6 +74,10 @@ public class NBTManager {
return nmsItemStack.getTag();
}
public static void addFloatNBT(NBTTagCompound nbtTagCompound, String key, float value) {
nbtTagCompound.setFloat(key, value);
}
public static NBTBase constructNBT(String nbtString) {
try {
return CraftNBTTagConfigSerializer.deserialize(nbtString);