
NBTTagCompound tag = new NBTTagCompound ( ) EntityPlayer nmsPlayer = ( (CraftPlayer )player ).
NBTEXPLORER 1.12 CODE
What the code does is to first get the item in the players main hand, then convert it to a NMS ItemStack and lastly get (or create) the item tag. We will first need to get or create the item tag.
NBTEXPLORER 1.12 HOW TO
I will be covering how to modify enchants and attributes.

So, you are now familiar with the NBT structure so let's get to writing the code. To get a list from a compound we need to know the list type ID which can be found below: They start at 0 and will also be able to store any type of variable. Lists are ordered by in which order they were added. What differs lists from compounds is exactly what you would expect. The tag will contain all additional information (such as enchants, attributes, display name, lore, etc). There could also be another compound within the items compound, this is called the item tag. It will also contain a string which will be the items ID (ex. If you take any items compound, it will contain 2 bytes, one for the count (amount of items) and one for the slot (where the item is placed in your inventory). Whenever you create a new item (in the inventory) or entity a new item compound will be created to store all information. It can contain any type of all the "variables", even itself.Ĭompounds will work as a mix of variables that can be accessed in any order and defined and accessible by their "name". The "main" variable type is the compound. Bytes, shorts, integers, doubles, strings, etc. You can think of NBT as a tree of different types of variables (tags) all nested within each other. If you do not feel like installing NBTExplorer and only want it explained, then you can continue taking my basic description on how NBT is structured below. Here is an example of an item I created which I viewed it in NBTExplorer, something I strongly recommend before continuing which would make it easier to understand the entire "learning the NBT structure part".

Note: When I talk about compounds I will be referring to NBTTagCompounds.Ī good way to learn an items NBT structure is to actually look at it yourself. If you want to take a look at some more advanced NBT modification code you can take a look at my plugin here. I will also try to answer questions or issues that I myself met along the way. This resource will have as a goal to give you at least a basic understanding of how to modify existing entities or inventory items NBT. The intent is to give you a basic understanding of how NBT tags works and how to edit them. The intent of this resource is not to learn you how to add enchantments/attributes. If you use 1.14+, NBT modification is not always needed (see comments). The version will be based on 1.13 but you can follow the tutorial with minimal change for versions 1.12.2 to 1.14.4. Note: I will be underlining all terms that should be paid attention to as they are important.
