docs: add godoc comments to all exported functions and methods
This commit is contained in:
@@ -174,6 +174,7 @@ type Attribute struct {
|
||||
Base float64
|
||||
}
|
||||
|
||||
// ReadLevelData reads and decodes the level.dat NBT file from a reader.
|
||||
func ReadLevelData(r io.Reader) (l Level, err error) {
|
||||
var lDataWrapped struct{ Data Level }
|
||||
err = nbt.ReadFile(r, &lDataWrapped)
|
||||
|
||||
@@ -52,6 +52,7 @@ type ChunkHeader struct {
|
||||
Chunk, Time [ChunksRegionFile]int32
|
||||
}
|
||||
|
||||
// ReadChunkHeader reads the chunk header from an MCA region file.
|
||||
func ReadChunkHeader(r *os.File) (ch *ChunkHeader, err error) {
|
||||
var h ChunkHeader
|
||||
err = binary.Read(r, binary.BigEndian, &h)
|
||||
|
||||
@@ -10,6 +10,7 @@ type Chunk struct {
|
||||
Version string
|
||||
}
|
||||
|
||||
// ReadChunkFromChunkPacketData decodes chunk packet data from a reader into a Chunk.
|
||||
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (c *Chunk, err error) {
|
||||
c = &Chunk{}
|
||||
c.Version = version
|
||||
|
||||
@@ -94,6 +94,7 @@ type Structure struct {
|
||||
Version string
|
||||
}
|
||||
|
||||
// LoadFromPath loads a litematic file from disk.
|
||||
func LoadFromPath(path string) (s *Structure, err error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
@@ -104,6 +105,7 @@ func LoadFromPath(path string) (s *Structure, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// LoadFromFile reads and parses a litematic file from a reader.
|
||||
func LoadFromFile(r io.Reader) (s *Structure, err error) {
|
||||
n, err := nbt.ReadUnstructuredFile(r)
|
||||
if err != nil {
|
||||
@@ -112,6 +114,7 @@ func LoadFromFile(r io.Reader) (s *Structure, err error) {
|
||||
return Load(n.Value)
|
||||
}
|
||||
|
||||
// Load decodes raw NBT data into a litematic Structure.
|
||||
func Load(v any) (s *Structure, err error) {
|
||||
s = &Structure{}
|
||||
err = mapstructure.Decode(v, &s.File)
|
||||
|
||||
@@ -30,6 +30,7 @@ type Section struct {
|
||||
Blocks, Biomes *Storage
|
||||
}
|
||||
|
||||
// MakeBiomeFormat returns the StorageFormat for biome data at the given version.
|
||||
func MakeBiomeFormat(version string) StorageFormat {
|
||||
directBpe := uint8(math.Ceil(math.Log2(float64(len(data2.BiomesForVersion(version))))))
|
||||
return StorageFormat{
|
||||
@@ -39,6 +40,7 @@ func MakeBiomeFormat(version string) StorageFormat {
|
||||
}
|
||||
}
|
||||
|
||||
// MakeBlockFormat returns the StorageFormat for block data at the given version.
|
||||
func MakeBlockFormat(version string) StorageFormat {
|
||||
directBpe := uint8(math.Ceil(math.Log2(float64(len(data2.BlocksForVersion(version))))))
|
||||
return StorageFormat{
|
||||
@@ -51,6 +53,7 @@ func MakeBlockFormat(version string) StorageFormat {
|
||||
|
||||
var BadPaletteLenErr = errors.New("bad palette length")
|
||||
|
||||
// ReadSectionStorage reads a packed section storage from a reader.
|
||||
func ReadSectionStorage(r io.Reader, format StorageFormat) (s *Storage, err error) {
|
||||
var bpe uint8
|
||||
err = binary.Read(r, binary.BigEndian, &bpe)
|
||||
@@ -97,6 +100,7 @@ func ReadSectionStorage(r io.Reader, format StorageFormat) (s *Storage, err erro
|
||||
return format.ImportFromReader(r, bpe, pallette)
|
||||
}
|
||||
|
||||
// WriteSectionStorage writes a packed section storage to a writer.
|
||||
func WriteSectionStorage(w io.Writer, s *Storage) (err error) {
|
||||
err = binary.Write(w, binary.BigEndian, s.bpe)
|
||||
if err != nil {
|
||||
@@ -122,6 +126,7 @@ func WriteSectionStorage(w io.Writer, s *Storage) (err error) {
|
||||
return binary.Write(w, binary.BigEndian, s.data)
|
||||
}
|
||||
|
||||
// SectionDecodePacket decodes a chunk section from the Minecraft packet wire format.
|
||||
func SectionDecodePacket(r io.Reader, version string) (s Section, err error) {
|
||||
s = Section{}
|
||||
err = binary.Read(r, binary.BigEndian, &s.BlockCount)
|
||||
@@ -136,6 +141,7 @@ func SectionDecodePacket(r io.Reader, version string) (s Section, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// SectionEncodePacket encodes a chunk section to the Minecraft packet wire format.
|
||||
func SectionEncodePacket(w io.Writer, s Section) (err error) {
|
||||
err = binary.Write(w, binary.BigEndian, s.BlockCount)
|
||||
if err != nil {
|
||||
@@ -149,6 +155,7 @@ func SectionEncodePacket(w io.Writer, s Section) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// SectionEquals returns whether two sections are equal.
|
||||
func SectionEquals(a, b Section) bool {
|
||||
if a.BlockCount != b.BlockCount {
|
||||
return false
|
||||
|
||||
@@ -250,6 +250,7 @@ func (r *Storage) Equals(other *Storage) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// CountStorage counts the number of elements in the storage that match the given value.
|
||||
func CountStorage(s *Storage, v int32) (a int) {
|
||||
for i := range s.format.Len {
|
||||
if w, _ := s.Get(i); w == v {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
)
|
||||
|
||||
// Load reads a structure NBT file and returns the decoded Structure.
|
||||
func Load(fileName string) (s *Structure, err error) {
|
||||
n, err := nbt.ReadUnstructuredFilePath(fileName)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user