This repository was archived by the owner on Oct 2, 2022. It is now read-only.
Repository navigation
NBT
Zoyn edited this page Aug 30, 2018
·
2 revisions
When we want to edit the nbt of the ItemStack, we usually call nms directly or use reflection.
But this util has done a lot of work for you, you don't need to use reflection anymore.
When we just want to add some string or integer to item, we can do like this.
TagCompound compound = new TagCompound()
.putInt("int", 123)
.putString("string", "§6Test?");
// if you don't want to over ride the nbt, then you can use NBTUtils.getItemStackNBT()
// TagCompound compound = NBTUtils.getItemStackNBT(itemStack)
// .putInt("int", 123)
// .putString("string", "§6Test?");
Object nbtTag = compound.build();
System.out.println(nbtTag);
ItemStack itemStack2 = NBTUtils.setItemStackNBT(nbtTag, itemStack);
The output
{
string: "§6Test?",
int: 123
}
Just see the code..
TagCompound damageTag = new TagCompound()
.putString("AttributeName", "generic.attackDamage")
.putString("Name", "Damage")
.putInt("Amount", 20)
.putInt("Operation", 0)
.putInt("UUIDLeast", 20000)
.putInt("UUIDMost", 1000)
.putString("Slot", "mainhand");
TagCompound compound = NBTUtils.getItemStackNBT(itemStack)
.putInt("int", 123)
.putListCompound("AttributeModifiers", Lists.newArrayList(damageTag));
Object nbtTag = compound.build();
System.out.println(nbtTag);
ItemStack itemStack2 = NBTUtils.setItemStackNBT(nbtTag, itemStack);
The output
{
int: 123,
AttributeModifiers: [{
UUIDMost: 1000,
UUIDLeast: 20000,
Amount: 20,
Slot: "mainhand",
AttributeName: "generic.attackDamage",
Operation: 0,
Name: "Damage"
}]
}
This wiki hopes to help you!
没有中文教程...自己看代码吧..