Class NBTHandler

java.lang.Object
me.pauleff.common.handlers.NBTHandler

public final class NBTHandler extends Object
Provides utilities for reading, writing, and inspecting Minecraft NBT files.
  • Method Details

    • isNBTFile

      public static boolean isNBTFile(File file)
      Determines whether a file can be parsed as a valid NBT document.

      Attempts to read the file via NBTUtil.read(File), which detects GZIP and NBT headers. Parse failures (including invalid gzip or tag IDs) are treated as non-NBT.

      Parameters:
      file - the file to inspect
      Returns:
      true if the file parses as NBT; false otherwise
    • copyPlayerDataNBT

      public static void copyPlayerDataNBT(Path nbtSource, Path nbtDest) throws IOException
      Writes playerdata from nbtSource to nbtDest, preserving selected tags from the destination when it already exists.

      Loads the source compound, then for each path in the default keep-list copies the corresponding tag from the destination into the source before writing. Nested paths use dot notation (e.g. abilities.flying). The destination is written with GZIP compression as handled by the Querz NBT library.

      Parameters:
      nbtSource - the path to the source NBT playerdata file
      nbtDest - the path to write the merged playerdata to
      Throws:
      IOException - if reading or writing either NBT file fails