Last active
August 16, 2016 22:05
-
-
Save towerofnix/971fa1d2e2fc1bbb64177c6d335d75c8 to your computer and use it in GitHub Desktop.
Get NBT Data Tag from Item Stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do note this is for NMS ItemStacks, not Bukkit ItemStacks. | |
// You'll need to use CraftItemStack.asCraftCopy/CraftItemStack.asCraftCopy | |
// if you plan on using Bukkit ItemStacks. | |
// Imports at top of file | |
import net.minecraft.server.v1_10_R1.NBTTagCompound; | |
import net.minecraft.server.v1_10_R1.ItemStack; | |
// Add this is a method to whatever | |
private NBTTagCompound getTag(ItemStack stack) { | |
NBTTagCompound tag = null; | |
if (!stack.hasTag()) { | |
tag = new NBTTagCompound(); | |
stack.setTag(tag); | |
} | |
if (tag == null) tag = stack.getTag(); | |
return tag; | |
} | |
// To get the NBT of a NMS ItemStack: | |
NBTTagCompound tag = getTag(stack); | |
// To update the NBT of a NMS ItemStack: | |
stack.setTag(tag); | |
// If you run into an issue with ItemStack already being defined or overwritten by the new import, | |
// YOU LOSE. http://stackoverflow.com/q/2447880/4633828 | |
// My friend zro is all "pls terminology", so here you go: | |
// * NBT: Named Binary Tag, so kinda like JSON but for Minecraft. Does cool things. | |
// For example: http://minecraft.gamepedia.com/Chunk_format | |
// * NMS: Node Minecraft Server. Spigot wants you to only use Spigot APIs but I (a bukkit | |
// developer for three hours) don't think you should. After all Spigot doesn't let you | |
// deal with NBT easily! | |
// * Bukkit: lol |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment