Class NBTUtils

java.lang.Object
me.desht.pneumaticcraft.common.util.NBTUtils

public class NBTUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<net.minecraft.network.chat.Component>
    deserializeTextComponents(net.minecraft.nbt.ListTag l)
     
    static boolean
    fromTag(net.minecraft.nbt.CompoundTag tag, String name, boolean def)
     
    static float
    fromTag(net.minecraft.nbt.CompoundTag tag, String name, float def)
     
    static int
    fromTag(net.minecraft.nbt.CompoundTag tag, String name, int def)
     
    static String
    fromTag(net.minecraft.nbt.CompoundTag tag, String name, String def)
     
    static boolean
    getBoolean(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a Boolean value of the given tag from the CompoundTag of the given ItemStack.
    static byte
    getByte(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a Byte value of the given tag from the CompoundTag of the given ItemStack.
    static net.minecraft.nbt.CompoundTag
    getCompoundTag(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a CompoundTag value of the given tag from the CompoundTag of the given ItemStack.
    static double
    getDouble(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a Double value of the given tag from the CompoundTag of the given ItemStack.
    static float
    getFloat(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a Float value of the given tag from the CompoundTag of the given ItemStack.
    static int
    getInteger(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets an Integer value of the given tag from the CompoundTag of the given ItemStack.
    static long
    getLong(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a Long value of the given tag from the CompoundTag of the given ItemStack.
    static net.minecraft.core.BlockPos
    getPos(net.minecraft.nbt.CompoundTag tag)
     
    static net.minecraft.core.BlockPos
    getPos(net.minecraft.world.item.ItemStack stack)
     
    static short
    getShort(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a Short value of the given tag from the CompoundTag of the given ItemStack.
    static String
    getString(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Gets a String value of the given tag from the CompoundTag of the given ItemStack.
    static boolean
    hasTag(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Checks if the CompoundTag of the given ItemStack has a given tag.
    static void
    initNBTTagCompound(net.minecraft.world.item.ItemStack itemStack)
    Initializes the CompoundTag for the given ItemStack if it is null.
    static void
    removeTag(net.minecraft.world.item.ItemStack itemStack, String tagName)
    Removes the given tag from the CompoundTag of the given ItemStack.
    static net.minecraft.nbt.ListTag
    serializeTextComponents(List<net.minecraft.network.chat.Component> textComponents)
     
    static void
    setBoolean(net.minecraft.world.item.ItemStack itemStack, String tagName, boolean tagValue)
    Sets the given boolean value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setByte(net.minecraft.world.item.ItemStack itemStack, String tagName, byte tagValue)
    Sets the given byte value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setCompoundTag(net.minecraft.world.item.ItemStack itemStack, String tagName, net.minecraft.nbt.Tag tagValue)
    Sets the given CompoundTag value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setDouble(net.minecraft.world.item.ItemStack itemStack, String tagName, double tagValue)
    Sets the given double value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setFloat(net.minecraft.world.item.ItemStack itemStack, String tagName, float tagValue)
    Sets the given float value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setInteger(net.minecraft.world.item.ItemStack itemStack, String tagName, int tagValue)
    Sets the given integer value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setLong(net.minecraft.world.item.ItemStack itemStack, String tagName, long tagValue)
    Sets the given long value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setPos(net.minecraft.nbt.CompoundTag tag, net.minecraft.core.Vec3i vec)
     
    static void
    setPos(net.minecraft.world.item.ItemStack stack, net.minecraft.core.Vec3i vec)
     
    static void
    setShort(net.minecraft.world.item.ItemStack itemStack, String tagName, short tagValue)
    Sets the given short value for the given tag on the CompoundTag of the given ItemStack.
    static void
    setString(net.minecraft.world.item.ItemStack itemStack, String tagName, String tagValue)
    Sets the given String value for the given tag on the CompoundTag of the given ItemStack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NBTUtils

      public NBTUtils()
  • Method Details

    • initNBTTagCompound

      public static void initNBTTagCompound(net.minecraft.world.item.ItemStack itemStack)
      Initializes the CompoundTag for the given ItemStack if it is null.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
    • hasTag

      public static boolean hasTag(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Checks if the CompoundTag of the given ItemStack has a given tag.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be checked.
      Returns:
      True if the CompoundTag has the tag otherwise false.
    • removeTag

      public static void removeTag(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Removes the given tag from the CompoundTag of the given ItemStack.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be removed.
    • getString

      public static String getString(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a String value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a String or an empty String if the NBT Tag Compound has no such key.
    • setString

      public static void setString(net.minecraft.world.item.ItemStack itemStack, String tagName, String tagValue)
      Sets the given String value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a String.
    • getBoolean

      public static boolean getBoolean(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a Boolean value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a Boolean or false if the NBT Tag Compound has no such key.
    • setBoolean

      public static void setBoolean(net.minecraft.world.item.ItemStack itemStack, String tagName, boolean tagValue)
      Sets the given boolean value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a boolean.
    • getByte

      public static byte getByte(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a Byte value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a Byte or 0 if the NBT Tag Compound has no such key.
    • setByte

      public static void setByte(net.minecraft.world.item.ItemStack itemStack, String tagName, byte tagValue)
      Sets the given byte value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a byte.
    • getShort

      public static short getShort(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a Short value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a Short or 0 if the NBT Tag Compound has no such key.
    • setShort

      public static void setShort(net.minecraft.world.item.ItemStack itemStack, String tagName, short tagValue)
      Sets the given short value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a short.
    • getInteger

      public static int getInteger(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets an Integer value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as an Integer or 0 if the NBT Tag Compound has no such key.
    • setInteger

      public static void setInteger(net.minecraft.world.item.ItemStack itemStack, String tagName, int tagValue)
      Sets the given integer value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as an integer.
    • getLong

      public static long getLong(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a Long value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a Long or 0 if the NBT Tag Compound has no such key.
    • setLong

      public static void setLong(net.minecraft.world.item.ItemStack itemStack, String tagName, long tagValue)
      Sets the given long value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a long.
    • getFloat

      public static float getFloat(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a Float value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a Float or 0 if the NBT Tag Compound has no such key.
    • setFloat

      public static void setFloat(net.minecraft.world.item.ItemStack itemStack, String tagName, float tagValue)
      Sets the given float value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a float.
    • getDouble

      public static double getDouble(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a Double value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a Double or 0 if the NBT Tag Compound has no such key.
    • setDouble

      public static void setDouble(net.minecraft.world.item.ItemStack itemStack, String tagName, double tagValue)
      Sets the given double value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a double.
    • getCompoundTag

      public static net.minecraft.nbt.CompoundTag getCompoundTag(net.minecraft.world.item.ItemStack itemStack, String tagName)
      Gets a CompoundTag value of the given tag from the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag for which the value should be determined.
      Returns:
      The value of the given tag as a CompoundTag.
    • setCompoundTag

      public static void setCompoundTag(net.minecraft.world.item.ItemStack itemStack, String tagName, net.minecraft.nbt.Tag tagValue)
      Sets the given CompoundTag value for the given tag on the CompoundTag of the given ItemStack. If the CompoundTag is null it will be initialized.
      Parameters:
      itemStack - The ItemStack which holds the CompoundTag.
      tagName - The name of the tag which should be set.
      tagValue - The value which should be set to the given tag as a CompoundTag.
    • setPos

      public static void setPos(net.minecraft.world.item.ItemStack stack, net.minecraft.core.Vec3i vec)
    • getPos

      public static net.minecraft.core.BlockPos getPos(net.minecraft.world.item.ItemStack stack)
    • setPos

      public static void setPos(net.minecraft.nbt.CompoundTag tag, net.minecraft.core.Vec3i vec)
    • getPos

      public static net.minecraft.core.BlockPos getPos(net.minecraft.nbt.CompoundTag tag)
    • fromTag

      public static boolean fromTag(net.minecraft.nbt.CompoundTag tag, String name, boolean def)
    • fromTag

      public static int fromTag(net.minecraft.nbt.CompoundTag tag, String name, int def)
    • fromTag

      public static String fromTag(net.minecraft.nbt.CompoundTag tag, String name, String def)
    • fromTag

      public static float fromTag(net.minecraft.nbt.CompoundTag tag, String name, float def)
    • serializeTextComponents

      public static net.minecraft.nbt.ListTag serializeTextComponents(List<net.minecraft.network.chat.Component> textComponents)
    • deserializeTextComponents

      public static List<net.minecraft.network.chat.Component> deserializeTextComponents(net.minecraft.nbt.ListTag l)