Skip to content

Instantly share code, notes, and snippets.

@ItsLiyua
ItsLiyua / NBTEditor.java
Created January 16, 2021 22:57
A method for setting NBT-Tags for items in spigot. Please note, the NBT-Tag with the path "test.helloworld" (for example) will look like this: {test:{helloworld:<data>}}
public class NBTEditor {
public static ItemStack setNBTValue(ItemStack is, String path, String value) {
path = "null." + path;
String[] pathArray = path.split("\\.");
pathArray[0] = null;
net.minecraft.server.v1_16_R3.ItemStack nms = CraftItemStack.asNMSCopy(is);
NBTTagCompound[] nbts = new NBTTagCompound[pathArray.length - 1];
for (int i = 0; i < pathArray.length; i++) {
String part = pathArray[i];
if (i == 0) {