Class Nbt

java.lang.Object
net.orbyfied.j8.util.nbt.Nbt

public class Nbt extends Object
Utilities for working with Minecraft NBT tags.
  • Constructor Details

    • Nbt

      public Nbt()
  • Method Details

    • getOrCreateObject

      public static <T> CompoundObjectTag<T> getOrCreateObject(net.minecraft.nbt.CompoundTag sourceTag, String key, Supplier<Object> objectSupplier)
      Tries to get an object tag with the provided key from the source tag. If doesn't exist, it gets the object from the supplier and creates a new CompoundObjectTag with it. Then it puts it into the source tag under the correct key and returns. If a tag with that key already exists, it will first check if it has already been loaded as an object, and if so, return it immediately. Otherwise, it will load the object tag, replace the existent one with the new object tag and return afterwards.
      Type Parameters:
      T - The object type.
      Parameters:
      sourceTag - The source tag to get from.
      key - The key in the source tag.
      objectSupplier - The object value supplier.
      Returns:
      The newly created or retrieved tag.
    • getOrLoadObject

      public static <T> CompoundObjectTag<T> getOrLoadObject(net.minecraft.nbt.CompoundTag sourceTag, String key)
      Tries to get an object tag with the provided key from the source tag. If a tag with that key already exists, it will first check if it has already been loaded as an object, and if so, return it immediately. Otherwise, it will load the object tag, replace the existent one with the new object tag and return afterwards.
      Type Parameters:
      T - The object type.
      Parameters:
      sourceTag - The source tag to get from.
      key - The key in the source tag.
      Returns:
      The retrieved tag or null.
    • getOrCreateCompound

      public static net.minecraft.nbt.CompoundTag getOrCreateCompound(net.minecraft.nbt.CompoundTag sourceTag, String key)
      Tries to get a compound tag with the provided key from the source tag. If it doesn't exist, it creates a new one, puts it in the source tag and then returns it. Otherwise it just returns the tag.
      Parameters:
      sourceTag - The source tag.
      key - The key in the source tag.
      Returns:
      The newly created or retrieved tag.
    • getOrCreateList

      public static net.minecraft.nbt.ListTag getOrCreateList(net.minecraft.nbt.CompoundTag sourceTag, String key, int type)
      Tries to get a list tag with the provided key from the source tag. If it doesn't exist, it creates a new one, puts it in the source tag and then returns it. Otherwise it just returns the tag.
      Parameters:
      sourceTag - The source tag.
      key - The key in the source tag.
      Returns:
      The newly created or retrieved tag.