level

package module
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: 1 Imported by: 0

README

level

[WIP] I may throw away :P

Installation

You can get the package with go get command.

go get -u github.com/beito123/level

-u is a option updating the package

License

This is licensed by MIT License. See LICENSE file.

Examples

Read
func main() {
	// Load leveldb level for mcbe
	lvl, err := leveldb.Load("./db")
	if err != nil {
		panic(err)
	}

	// Chunk coordinates
	x := 0
	y := 0

	ok, err := lvl.HasGeneratedChunk(x, y)
	if err != nil {
		panic(err)
	}

	if !ok {
		panic("a chunk isn't generated")
	}

	// Get chunk
	chunk, err := lvl.Chunk(x, y)
	if err != nil {
		panic(err)
	}

	for y := 0; y < 256; y++ {
		for z := 0; z < 16; z++ {
			for x := 0; x < 16; x++ {
				b, err := chunk.GetBlock(x, y, z)
				if err != nil {
					panic(err)
				}

				if b.Name() == "minecraft:air" { // ignore air
					continue
				}

				fmt.Printf("%s (at %d, %d, %d)\n", b.Name(), x, y, z)
			}
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockState

type BlockState interface {

	// Name returns block name
	Name() string

	// ToBlockNameProperties returns block name and properties
	// If it's not supported, returns false for ok
	ToBlockNameProperties() (name string, properties map[string]string, ok bool)

	// ToBlockNameMeta returns block name and meta
	// If it's not supported, returns false for ok
	ToBlockNameMeta() (name string, meta int, ok bool)

	// ToBlockIDMeta returns block id and meta
	// If it's not supported, returns false for ok
	ToBlockIDMeta() (id int, meta int, ok bool)
}

BlockState is a block information

type Chunk

type Chunk interface {

	// X returns x coordinate
	X() int

	// Y returns y coordinate
	Y() int

	// SetX set x coordinate
	SetX(x int)

	// SetY set y coordinate
	SetY(y int)

	// Height returns the height of the highest block at chunk coordinate
	Height(x, y int) (height uint16)

	// Biome returns biome
	Biome(x, y int) byte

	// SetBiome set biome
	SetBiome(x, y int, biome byte)

	// Entities returns entities of nbt data
	Entities() []*nbt.Compound

	// SetEntities set entities of nbt data
	SetEntities(entities []*nbt.Compound)

	// BlockEntities returns block entities of nbt data
	BlockEntities() []*nbt.Compound

	// SetBlockEntities set block entities of nbt data
	SetBlockEntities(entities []*nbt.Compound)

	// GetBlock gets a BlockState at chunk coordinate
	GetBlock(x, y, z int) (BlockState, error)

	// SetBlock set a BlockState at chunk coordinate
	SetBlock(x, y, z int, state BlockState) error
}

Chunk is a simple interface for chunk

type Dimension

type Dimension int

Dimension is a kind of world type

const (
	// OverWorld is a first dimension at new game
	OverWorld Dimension = iota

	// Nether is a hell world
	Nether

	// TheEnd is a dimension with floating islands
	TheEnd

	// Unknown is for unknown dimension
	// It' not use generally
	Unknown
)

type Format

type Format interface {

	// Name returns name of level
	Name() string

	// SetName sets the name of level
	SetName(name string)

	// GameType returns the default game mode of level
	GameType() GameType

	// SetGameType sets the game mode of level
	SetGameType(typ GameType)

	// Spawn returns the default spawn of level
	Spawn() (x, y, z int)

	// SetSpawn sets the default spawn of level
	SetSpawn(x, y, z int)

	// Property returns a property of level.dat
	Property(name string) (tag nbt.Tag, ok bool)

	// SetProperty sets a property
	SetProperty(tag nbt.Tag)

	// AllProperties returns all properties
	AllProperties() *nbt.Compound

	// SetAllProperties sets all properties
	SetAllProperties(com *nbt.Compound)

	// Close closes the level format
	// You must close after you use the format
	// It's should not run other functions after format is closed
	Close() error

	// Dimension return dimension of the level
	Dimension() Dimension

	// SetDimension set dimension of the level
	SetDimension(Dimension)

	// LoadChunk loads a chunk.
	// If create is enabled, generates a chunk if it doesn't exist
	LoadChunk(x, y int, create bool) error

	// UnloadChunk unloads a chunk.
	UnloadChunk(x, y int) error

	// GenerateChunk generates a chunk
	GenerateChunk(x, y int) error

	// HasGeneratedChunk returns whether the chunk is generaged
	HasGeneratedChunk(x, y int) (bool, error)

	// IsLoadedChunk returns weather a chunk is loaded.
	IsLoadedChunk(x, y int) bool

	// SaveChunk saves a chunk.
	SaveChunk(x, y int) error

	// SaveChunks saves all chunks.
	SaveChunks() error

	// Chunk returns a chunk.
	// If a chunk is not loaded, it will be loaded
	Chunk(x, y int) (Chunk, error)

	// LoadedChunks returns loaded chunks.
	LoadedChunks() []Chunk
}

Format is a simple interface for level formats This needs to be supported concurrency

type GameType

type GameType int

GameType is a gamemode of players

const (
	Survival GameType = iota
	Creative
	Adventure
	Spectator
)

func (GameType) Name

func (typ GameType) Name() string

Name returns the name of game type

type Level

type Level struct {
}

Level is a simple level loader

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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