public class NbtDataUtil extends Object
ItemStack
s
and various other objects that interact with NBTTagCompound
s. Also
provided is a static set of fields of the various "id"s of various bits of
data that may be stored on ItemStack
s and/or NBTTagCompound
s
used to store information.Modifier and Type | Field and Description |
---|---|
static String |
BLOCK_ENTITY_ID |
static String |
BLOCK_ENTITY_TAG |
static String |
SIGN |
static byte |
TAG_BYTE |
static byte |
TAG_BYTE_ARRAY |
static byte |
TAG_COMPOUND |
static byte |
TAG_DOUBLE |
static byte |
TAG_END |
static byte |
TAG_FLOAT |
static byte |
TAG_INT |
static byte |
TAG_INT_ARRAY |
static byte |
TAG_LIST |
static byte |
TAG_LONG |
static byte |
TAG_SHORT |
static byte |
TAG_STRING |
Constructor and Description |
---|
NbtDataUtil() |
Modifier and Type | Method and Description |
---|---|
static Optional<net.minecraft.nbt.NBTTagCompound> |
getItemCompound(net.minecraft.item.ItemStack itemStack)
Gets the main
NBTTagCompound as an Optional . |
static net.minecraft.nbt.NBTTagCompound |
getOrCreateCompound(net.minecraft.item.ItemStack itemStack)
Gets or creates a new
NBTTagCompound as the main compound of the
provided ItemStack . |
static net.minecraft.nbt.NBTTagCompound |
getOrCreateSubCompound(net.minecraft.nbt.NBTTagCompound mainCompound,
String key)
Similar to
getOrCreateCompound(ItemStack) , this will check the
provided NBTTagCompound whether an internal compound is already
set and created by the provided String key. |
public static final String BLOCK_ENTITY_TAG
public static final String BLOCK_ENTITY_ID
public static final String SIGN
public static final byte TAG_END
public static final byte TAG_BYTE
public static final byte TAG_SHORT
public static final byte TAG_INT
public static final byte TAG_LONG
public static final byte TAG_FLOAT
public static final byte TAG_DOUBLE
public static final byte TAG_BYTE_ARRAY
public static final byte TAG_STRING
public static final byte TAG_LIST
public static final byte TAG_COMPOUND
public static final byte TAG_INT_ARRAY
public static Optional<net.minecraft.nbt.NBTTagCompound> getItemCompound(net.minecraft.item.ItemStack itemStack)
NBTTagCompound
as an Optional
. The issue
with ItemStack
s is that the main compound is never instantiated
by default, so null
s are permitted. Of course, another issue
is that ItemStack.getTagCompound()
does not perform any
null
checks, and therefor, may return null
as
well. This method is provided to ensure that if the main compound does
not exist, none are created. To create a new compound regardless,
getOrCreateCompound(ItemStack)
is recommended.itemStack
- The itemstack to get the compound frompublic static net.minecraft.nbt.NBTTagCompound getOrCreateCompound(net.minecraft.item.ItemStack itemStack)
NBTTagCompound
as the main compound of the
provided ItemStack
. If there is one already created, this simply
returns the already created main compound. If there is no compound,
one is created and set back onto the ItemStack
.itemStack
- The itemstack to get the main compound frompublic static net.minecraft.nbt.NBTTagCompound getOrCreateSubCompound(net.minecraft.nbt.NBTTagCompound mainCompound, String key)
getOrCreateCompound(ItemStack)
, this will check the
provided NBTTagCompound
whether an internal compound is already
set and created by the provided String
key. If there is no
NBTTagCompound
already created, a new one is made and set for
the key.mainCompound
- The main compound to query forkey
- The key