nbt

package
v0.0.0-...-7ad0317 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TagTypeNames = map[TagID]string{
	TagEnd:       "TAG_End",
	TagByte:      "TAG_Byte",
	TagShort:     "TAG_Short",
	TagInt:       "TAG_Int",
	TagLong:      "TAG_Long",
	TagFloat:     "TAG_Float",
	TagDouble:    "TAG_Double",
	TagByteArray: "TAG_Byte_Array",
	TagString:    "TAG_String",
	TagList:      "TAG_List",
	TagCompound:  "TAG_Compound",
	TagIntArray:  "TAG_Int_Array",
	TagLongArray: "TAG_Long_Array",
}

TagTypeNames maps TagIDs to their string representations.

Functions

func CompareTags

func CompareTags(a, b Tag, partial bool) bool

CompareTags compares two NBT tags for equality. If partial is true, it checks if `a` is a subset of `b`. This version is more explicit and avoids reflect.DeepEqual pitfalls.

func StructureToSnbt

func StructureToSnbt(tag *CompoundTag) (string, error)

StructureToSnbt converts a structure CompoundTag to its SNBT representation, applying the special packing rules from NbtUtils.

func ToCompactSNBT

func ToCompactSNBT(tag Tag) string

ToCompactSNBT converts a tag to its compact SNBT representation.

func ToPrettySNBT

func ToPrettySNBT(tag Tag) string

ToPrettySNBT converts a tag to its pretty-printed SNBT representation.

func Write

func Write(w io.Writer, nbt NamedTag) error

Write writes a single named tag to the given writer. The data will not be compressed.

func WriteCompressed

func WriteCompressed(w io.Writer, nbt NamedTag) error

WriteCompressed writes a single named tag to a writer, compressing it with GZIP.

Types

type ByteArrayTag

type ByteArrayTag struct{ Value []int8 }

func (*ByteArrayTag) Copy

func (t *ByteArrayTag) Copy() Tag

func (*ByteArrayTag) ID

func (t *ByteArrayTag) ID() TagID

func (*ByteArrayTag) String

func (t *ByteArrayTag) String() string

type ByteTag

type ByteTag struct{ Value int8 }

func (*ByteTag) Copy

func (t *ByteTag) Copy() Tag

func (*ByteTag) ID

func (t *ByteTag) ID() TagID

func (*ByteTag) String

func (t *ByteTag) String() string

type CompoundTag

type CompoundTag struct {
	Value map[string]Tag
}

func NewCompoundTag

func NewCompoundTag() *CompoundTag

func ParseSNBT

func ParseSNBT(data string) (*CompoundTag, error)

ParseSNBT converts an SNBT string into a Tag. It expects a CompoundTag.

func SnbtToStructure

func SnbtToStructure(snbt string) (*CompoundTag, error)

SnbtToStructure converts an SNBT string back into a structure CompoundTag, applying the special unpacking rules.

func (*CompoundTag) Copy

func (t *CompoundTag) Copy() Tag

func (*CompoundTag) Get

func (t *CompoundTag) Get(key string) (Tag, bool)

func (*CompoundTag) GetCompound

func (t *CompoundTag) GetCompound(key string) (*CompoundTag, bool)

func (*CompoundTag) GetInt

func (t *CompoundTag) GetInt(key string) (int32, bool)

func (*CompoundTag) GetList

func (t *CompoundTag) GetList(key string) (*ListTag, bool)

func (*CompoundTag) GetString

func (t *CompoundTag) GetString(key string) (string, bool)

func (*CompoundTag) ID

func (t *CompoundTag) ID() TagID

func (*CompoundTag) Put

func (t *CompoundTag) Put(key string, tag Tag)

func (*CompoundTag) String

func (t *CompoundTag) String() string

type DoubleTag

type DoubleTag struct{ Value float64 }

func (*DoubleTag) Copy

func (t *DoubleTag) Copy() Tag

func (*DoubleTag) ID

func (t *DoubleTag) ID() TagID

func (*DoubleTag) String

func (t *DoubleTag) String() string

type EndTag

type EndTag struct{}

func (*EndTag) Copy

func (t *EndTag) Copy() Tag

func (*EndTag) ID

func (t *EndTag) ID() TagID

func (*EndTag) String

func (t *EndTag) String() string

type FloatTag

type FloatTag struct{ Value float32 }

func (*FloatTag) Copy

func (t *FloatTag) Copy() Tag

func (*FloatTag) ID

func (t *FloatTag) ID() TagID

func (*FloatTag) String

func (t *FloatTag) String() string

type IntArrayTag

type IntArrayTag struct{ Value []int32 }

func (*IntArrayTag) Copy

func (t *IntArrayTag) Copy() Tag

func (*IntArrayTag) ID

func (t *IntArrayTag) ID() TagID

func (*IntArrayTag) String

func (t *IntArrayTag) String() string

type IntTag

type IntTag struct{ Value int32 }

func (*IntTag) Copy

func (t *IntTag) Copy() Tag

func (*IntTag) ID

func (t *IntTag) ID() TagID

func (*IntTag) String

func (t *IntTag) String() string

type ListTag

type ListTag struct {
	Type  TagID
	Value []Tag
}

func (*ListTag) Add

func (t *ListTag) Add(tag Tag) error

func (*ListTag) Copy

func (t *ListTag) Copy() Tag

func (*ListTag) ID

func (t *ListTag) ID() TagID

func (*ListTag) String

func (t *ListTag) String() string

type LongArrayTag

type LongArrayTag struct{ Value []int64 }

func (*LongArrayTag) Copy

func (t *LongArrayTag) Copy() Tag

func (*LongArrayTag) ID

func (t *LongArrayTag) ID() TagID

func (*LongArrayTag) String

func (t *LongArrayTag) String() string

type LongTag

type LongTag struct{ Value int64 }

func (*LongTag) Copy

func (t *LongTag) Copy() Tag

func (*LongTag) ID

func (t *LongTag) ID() TagID

func (*LongTag) String

func (t *LongTag) String() string

type NamedTag

type NamedTag struct {
	Name string
	Tag  Tag
}

NamedTag represents a tag with a name, used as the root of an NBT file.

func Read

func Read(r io.Reader) (NamedTag, error)

Read reads a single named tag from the given reader. The NBT format must not be compressed.

func ReadCompressed

func ReadCompressed(r io.Reader) (NamedTag, error)

ReadCompressed reads a single named tag from a GZIP-compressed reader.

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer converts an NBT Tag to its SNBT string representation.

func NewCompactPrinter

func NewCompactPrinter() *Printer

NewCompactPrinter creates a new SNBT printer for compact, single-line output.

func NewPrettyPrinter

func NewPrettyPrinter(indent string) *Printer

NewPrettyPrinter creates a new SNBT printer for formatted, human-readable output.

func (*Printer) Print

func (p *Printer) Print(tag Tag) string

Print converts the tag to an SNBT string using the printer's mode.

type ShortTag

type ShortTag struct{ Value int16 }

func (*ShortTag) Copy

func (t *ShortTag) Copy() Tag

func (*ShortTag) ID

func (t *ShortTag) ID() TagID

func (*ShortTag) String

func (t *ShortTag) String() string

type StringTag

type StringTag struct{ Value string }

func (*StringTag) Copy

func (t *StringTag) Copy() Tag

func (*StringTag) ID

func (t *StringTag) ID() TagID

func (*StringTag) String

func (t *StringTag) String() string

type Tag

type Tag interface {
	// ID returns the numeric type ID of the tag.
	ID() TagID
	// String returns the SNBT representation of the tag.
	String() string

	// Copy creates a deep copy of the tag.
	Copy() Tag
	// contains filtered or unexported methods
}

Tag represents a single NBT tag.

type TagID

type TagID = byte

TagID represents the type of an NBT tag.

const (
	TagEnd TagID = iota
	TagByte
	TagShort
	TagInt
	TagLong
	TagFloat
	TagDouble
	TagByteArray
	TagString
	TagList
	TagCompound
	TagIntArray
	TagLongArray
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL