Package com.ranull.graves.util
Class NBTUtil
java.lang.Object
com.ranull.graves.util.NBTUtil
Utility class for handling raw SNBT (Stringified NBT) data on ItemStacks and block entities.
Provides methods to read the full NBT data as SNBT strings and to apply SNBT payloads without direct use of NMS, leveraging the de.tr7zw.nbtapi library.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.inventory.ItemStackapplyRawNBTToItem(org.bukkit.inventory.ItemStack item, String rawSNBT) Applies the given SNBT payload to a clone of the specified ItemStack and returns the resulting ItemStack.static StringgetBlockRawNBT(org.bukkit.block.Block block) Retrieves the SNBT data of the given block's tile-entity, if present.static StringgetItemRawNBT(org.bukkit.inventory.ItemStack item) Retrieves the full SNBT representation of the given ItemStack, including its id, count, and all nested tag data.static voidplaceBlockWithRawNBT(org.bukkit.Location loc, org.bukkit.Material material, String rawSNBT) Places a block of the specified Material at the given Location and merges the provided SNBT payload into its tile-entity data.static voidsetBlockRawNBT(org.bukkit.block.Block block, String rawSNBT) Applies the given SNBT payload to the specified block, replacing its existing tile-entity data.
-
Constructor Details
-
NBTUtil
public NBTUtil()
-
-
Method Details
-
getItemRawNBT
Retrieves the full SNBT representation of the given ItemStack, including its id, count, and all nested tag data.- Parameters:
item- the ItemStack to read NBT from; may be null- Returns:
- a SNBT string containing the item's NBT, or "{}" if the item is null or has no data
-
getBlockRawNBT
Retrieves the SNBT data of the given block's tile-entity, if present.- Parameters:
block- the Block whose tile-entity NBT should be read; may be null- Returns:
- a SNBT string of the block-entity's data, or "{}" if the block is null or has no tile-entity
-
setBlockRawNBT
Applies the given SNBT payload to the specified block, replacing its existing tile-entity data. Does nothing if the block is null.- Parameters:
block- the Block whose NBT should be set; must not be nullrawSNBT- the SNBT string to apply to the block's tile-entity; must be valid SNBT
-
placeBlockWithRawNBT
public static void placeBlockWithRawNBT(org.bukkit.Location loc, org.bukkit.Material material, String rawSNBT) Places a block of the specified Material at the given Location and merges the provided SNBT payload into its tile-entity data. Does nothing if the Location or its world is null.- Parameters:
loc- the Location where the block should be placed; must not be nullmaterial- the Material of the block to place; must not be nullrawSNBT- the SNBT string to apply to the placed block's tile-entity; must be valid SNBT
-
applyRawNBTToItem
public static org.bukkit.inventory.ItemStack applyRawNBTToItem(org.bukkit.inventory.ItemStack item, String rawSNBT) Applies the given SNBT payload to a clone of the specified ItemStack and returns the resulting ItemStack. Returns null if the input item is null.- Parameters:
item- the ItemStack to modify; if null, this method returns nullrawSNBT- the SNBT string to merge into the item; must be valid SNBT- Returns:
- a new ItemStack with the SNBT applied, or null if the input item was null
-