Package net.glowstone.io.nbt
Class NbtSerialization
java.lang.Object
net.glowstone.io.nbt.NbtSerialization
Utility methods for transforming various objects to and from NBT. All strings in this class are
subtag names and thus not localizable.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.Location
listTagsToLocation
(org.bukkit.World world, CompoundTag tag) Read a Location from the "Pos" and "Rotation" children of a tag.static org.bukkit.util.Vector
listToVector
(List<Double> list) Create a Vector from a list of doubles.static void
locationToListTags
(org.bukkit.Location loc, CompoundTag tag) Write a Location to the "Pos" and "Rotation" children of a tag.static org.bukkit.NamespacedKey
namespacedKeyFromString
(String keyRaw) static org.bukkit.block.data.BlockData
readBlockData
(CompoundTag tag) static org.bukkit.inventory.ItemStack[]
readInventory
(List<CompoundTag> tagList, int start, int size) Read a full inventory (players, chests, etc.) from a compound list.static org.bukkit.inventory.ItemStack
readItem
(CompoundTag tag) Read an item stack in from an NBT tag.static org.bukkit.World
readWorld
(GlowServer server, CompoundTag compound) Attempt to resolve a world based on the contents of a compound tag.vectorToList
(org.bukkit.util.Vector vec) Create a list of doubles from a Vector.static CompoundTag
writeBlockData
(org.bukkit.block.data.BlockData blockData) static List<CompoundTag>
writeInventory
(org.bukkit.inventory.ItemStack[] items, int start) Write a full inventory (players, chests, etc.) to a compound list.static CompoundTag
writeItem
(org.bukkit.inventory.ItemStack stack, int slot) Write an item stack to an NBT tag.static void
writeWorld
(org.bukkit.World world, CompoundTag compound) Save world identifiers (UUID and dimension) to a compound tag for later lookup.
-
Method Details
-
readItem
Read an item stack in from an NBT tag.Returns null if no item exists.
- Parameters:
tag
- The tag to read from.- Returns:
- The resulting ItemStack, or null.
-
writeItem
Write an item stack to an NBT tag.Null stacks produce an empty tag, and if slot is negative it is omitted from the result.
- Parameters:
stack
- The stack to write, or null.slot
- The slot, or negative to omit.- Returns:
- The resulting tag.
-
readBlockData
-
writeBlockData
-
readInventory
public static org.bukkit.inventory.ItemStack[] readInventory(List<CompoundTag> tagList, int start, int size) Read a full inventory (players, chests, etc.) from a compound list.- Parameters:
tagList
- The list of CompoundTags to read from.start
- The slot number to consider the inventory's start.size
- The desired size of the inventory.- Returns:
- An array with the contents of the inventory.
-
writeInventory
Write a full inventory (players, chests, etc.) to a compound list.- Parameters:
items
- An array with the contents of the inventory.start
- The slot number to consider the inventory's start.- Returns:
- The list of CompoundTags.
-
readWorld
Attempt to resolve a world based on the contents of a compound tag.- Parameters:
server
- The server to look up worlds in.compound
- The tag to read the world from.- Returns:
- The world, or null if none could be found.
-
writeWorld
Save world identifiers (UUID and dimension) to a compound tag for later lookup.- Parameters:
world
- The world to identify.compound
- The tag to write to.
-
listTagsToLocation
Read a Location from the "Pos" and "Rotation" children of a tag.If "Pos" is absent or invalid, null is returned.
If "Rotation" is absent or invalid, it is skipped and a location without rotation is returned.
- Parameters:
world
- The world of the location (see readWorld).tag
- The tag to read from.- Returns:
- The location, or null.
-
locationToListTags
Write a Location to the "Pos" and "Rotation" children of a tag.Does not save world information, use writeWorld instead.
- Parameters:
loc
- The location to write.tag
- The tag to write to.
-
listToVector
Create a Vector from a list of doubles.If the list is invalid, a zero vector is returned.
- Parameters:
list
- The list to read from.- Returns:
- The Vector.
-
vectorToList
Create a list of doubles from a Vector.- Parameters:
vec
- The vector to write.- Returns:
- The list.
-
namespacedKeyFromString
-