anvil

package
v0.0.0-...-cbdf446 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChunkCount is the number of chunks in a region file
	ChunkCount = 32 * 32 // 1024

	// Sector is a data sector for region format
	Sector = 4 * ChunkCount

	// LocationsBytes is a offset for chunks location in a region file
	LocationsBytes = Sector // 4 = (offset 3bytes, count 1byte)

	// TimestampsBytes is a offset for chunks's timestamp in a region file
	TimestampsBytes = Sector // 4 = timestamp 4 bytes

	// InformationSector is a information sector for chunk data
	InformationSector = LocationsBytes + TimestampsBytes
)
View Source
const (
	// CompressionGZip compresses chunk data with gzip for chunk data
	CompressionGZip = iota + 1

	// CompressionZlib compresses chunk data with zlib for chunk data
	CompressionZlib
)

Variables

View Source
var (
	// RegionFileMCRegion returns a region file name for mcregion
	RegionFileMCRegion = func(x, y int) string {
		return "r." + strconv.Itoa(x) + "." + strconv.Itoa(y) + ".mcr"
	}

	// RegionFileAnvil returns a region file name for mcregion
	RegionFileAnvil = func(x, y int) string {
		return "r." + strconv.Itoa(x) + "." + strconv.Itoa(y) + ".mca"
	}
)

Functions

func ToNibble

func ToNibble(b []byte, index int) byte

ToNibble returns a nibble data from []byte by index

Types

type Anvil

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

Anvil is a level format It often is used for minecraft java edition and server world

func NewAnvil

func NewAnvil(path string) (*Anvil, error)

func (*Anvil) Chunk

func (lvl *Anvil) Chunk(x, y int, create bool) level.Chunk

Chunk returns a chunk. If it's not loaded, loads the chunks. If create is true, generates a chunk.

func (*Anvil) Chunks

func (lvl *Anvil) Chunks() []level.Chunk

Chunks retuns loaded chunks.

func (*Anvil) IsLoadedChunk

func (lvl *Anvil) IsLoadedChunk(x, y int) bool

IsLoadedChunk returns weather a chunk is loaded.

func (*Anvil) LoadChunk

func (lvl *Anvil) LoadChunk(x, y int, create bool) bool

LoadChunk loads a chunk. If create is true, generates a chunk.

func (*Anvil) SaveChunk

func (lvl *Anvil) SaveChunk(x, y int) bool

SaveChunk saves a chunk.

func (*Anvil) SaveChunks

func (lvl *Anvil) SaveChunks()

SaveChunks saves all chunks.

func (*Anvil) UnloadChunk

func (lvl *Anvil) UnloadChunk(x, y int, safe bool) bool

UnloadChunk unloads a chunk. If safe is false, unloads even when players are there.

type BlockState

type BlockState struct {
	Name       string
	Properties map[string]string

	IsOld   bool
	OldID   byte
	OldMeta byte
}

func (*BlockState) Equal

func (bs *BlockState) Equal(sub *BlockState) bool

func (*BlockState) ToBlockData

func (bs *BlockState) ToBlockData() *block.Block

type Chunk

type Chunk struct {
	ChunkFormat ChunkFormat
	// contains filtered or unexported fields
}

Chunk is

func NewChunk

func NewChunk(x, y int, format ChunkFormat) *Chunk

NewChunk returns new Chunk

func ReadChunk

func ReadChunk(x, y int, b []byte) (*Chunk, error)

ReadChunk returns new Chunk with CompoundTag

func (*Chunk) AtSubChunk

func (chunk *Chunk) AtSubChunk(y int) (*SubChunk, bool)

AtSubChunk returns a sub chunk at the y (chunk coordinate)

func (*Chunk) GetBlock

func (chunk *Chunk) GetBlock(x, y, z int) (*block.Block, error)

GetBlock gets a block at the xyz (chunk coordinate)

func (*Chunk) GetSubChunk

func (chunk *Chunk) GetSubChunk(y int) (*SubChunk, bool)

GetSubChunk returns a sub chunk at the y index you can set 0-15 at y

func (*Chunk) Save

func (chunk *Chunk) Save() (*nbt.Compound, error)

Save saves the chunk, returns CompoundTag

func (*Chunk) SubChunks

func (chunk *Chunk) SubChunks() []*SubChunk

SubChunks returns sub chunks

func (*Chunk) X

func (chunk *Chunk) X() int

X returns x coordinate

func (*Chunk) Y

func (chunk *Chunk) Y() int

Y returns y coordinate

type ChunkFormat

type ChunkFormat interface {
	Read(tag *nbt.Compound) (*Chunk, error)
}

ChunkFormat is a chunk format for a version

type ChunkFormatV112

type ChunkFormatV112 struct {
}

ChunkFormatV112 is a chunk format for v1.12

func (*ChunkFormatV112) Read

func (format *ChunkFormatV112) Read(tag *nbt.Compound) (*Chunk, error)

type ChunkFormatV113

type ChunkFormatV113 struct {
}

ChunkFormatV113 is a chunk format for v1.13

func (*ChunkFormatV113) Read

func (format *ChunkFormatV113) Read(tag *nbt.Compound) (*Chunk, error)

type Location

type Location struct {
	Off   binary.Triad
	Count byte
}

Location is a location info for chunk data

type Region

type Region struct {
	X int
	Y int

	Data []byte

	Locations  []*Location
	Timestamps []int32
}

Region is a section had 32x32 chunks

func NewRegion

func NewRegion(x, y int) *Region

NewRegion returns new Region with xy

func (*Region) Load

func (reg *Region) Load(b []byte) error

Load loads a region from region file bytes

func (*Region) ReadChunk

func (reg *Region) ReadChunk(x, y int) ([]byte, error)

ReadChunk reads a chunk, returns chunk data as []byte If the chunk doesn't exist, returns nil both two values

func (*Region) Save

func (reg *Region) Save() ([]byte, error)

Save saves region data, returns bytes for a region file

type RegionLoader

type RegionLoader struct {
	ToRegionFile func(x, y int) string
	// contains filtered or unexported fields
}

RegionLoader controls a region file on dir and pass Region to load a region

func NewRegionLoader

func NewRegionLoader(path string, tofile func(x, y int) string) (*RegionLoader, error)

NewRegionLoader returns new RegionLoader You can set RegionFileMCRegion and RegionFileAnvil to tofile

func (*RegionLoader) LoadRegion

func (rl *RegionLoader) LoadRegion(x, y int, create bool) (*Region, error)

LoadRegion loads a region

func (*RegionLoader) SaveRegion

func (rl *RegionLoader) SaveRegion(reg *Region) error

SaveRegion saves a region as a file

type SubChunk

type SubChunk struct {
	Y byte

	Palette    []*BlockState
	Blocks     []uint16
	BlockLight []byte
	SkyLight   []byte
}

SubChunk is what is divided a chunk horizontally in sixteen

func NewSubChunk

func NewSubChunk(y byte) *SubChunk

NewSubChunk returns new subchunk

func (SubChunk) At

func (SubChunk) At(x, y, z int) int

At returns index from subchunk coordinates xyz need to be more 0 and less 15

func (*SubChunk) AtBlock

func (sub *SubChunk) AtBlock(x, y, z int) (*BlockState, error)

AtBlock returns block name at the subchunk coordinates

func (*SubChunk) AtBlockLight

func (sub *SubChunk) AtBlockLight(x, y, z int) (byte, error)

AtBlockLight returns a blocklight at the subchunk coordinates

func (*SubChunk) AtSkyLight

func (sub *SubChunk) AtSkyLight(x, y, z int) (byte, error)

AtSkyLight returns a skylight at the subchunk coordinates

func (*SubChunk) BlockIndex

func (sub *SubChunk) BlockIndex(x, y, z int) (uint16, error)

BlockIndex returns a index for block id

func (SubChunk) Vaild

func (SubChunk) Vaild(x, y, z int) error

Vaild vailds subchunk coordinates

type SubChunkFormat

type SubChunkFormat interface {
	Read(tag *nbt.Compound) (*SubChunk, error)
}

SubChunkFormat is a subchunk format for a version

type SubChunkFormatV112

type SubChunkFormatV112 struct {
}

SubChunkFormatV112 is a subchunk format for v1.12 and before

func (SubChunkFormatV112) Read

func (SubChunkFormatV112) Read(tag *nbt.Compound) (*SubChunk, error)

type SubChunkFormatV113

type SubChunkFormatV113 struct {
}

SubChunkFormatV113 is a subchunk format for v1.13 and after

func (SubChunkFormatV113) Read

func (SubChunkFormatV113) Read(tag *nbt.Compound) (*SubChunk, error)

func (SubChunkFormatV113) Write

func (SubChunkFormatV113) Write(sub *SubChunk) (*nbt.Compound, error)

Jump to

Keyboard shortcuts

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