minecraft

package module
v0.0.0-...-51d5029 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: ISC Imports: 15 Imported by: 1

README

minecraft

-- import "vimagination.zapto.org/minecraft"

Package minecraft is a level viewer/editor for the popular creative game minecraft.

Usage

const (
	DefaultGenerator    = "default"
	FlatGenerator       = "flat"
	LargeBiomeGenerator = "largeBiomes"
	AmplifiedGenerator  = "amplified"
	CustomGenerator     = "customized"
	DebugGenerator      = "debug_all_block_states"
)

Default minecraft generators

const (
	Survival int32 = iota
	Creative
	Adventure
	Spectator
)

Game Modes Settings.

const (
	Peaceful int8 = iota
	Easy
	Normal
	Hard
)

Difficulty Settings.

const (
	SunRise  = 0
	Noon     = 6000
	SunSet   = 12000
	MidNight = 18000
	Day      = 24000
)

Time-of-day convenience constants.

const (
	GZip byte = 1
	Zlib byte = 2
)

Compression convenience constants.

var (
	// ErrOOB is an error returned when sanity checking section data.
	ErrOOB = errors.New("received out-of-bounds error")
	// ErrNoLock is an error returns by path types to indicate that the lock on the
	// minecraft level has been locked and needs reinstating to continue.
	ErrNoLock = errors.New("lost lock on files")
)
var (
	// TransparentBlocks is a slice of the block ids that are transparent.
	// This is used in lighting calculations and is user overridable for custom
	// blocks.
	TransparentBlocks = TransparentBlockList{0, 6, 18, 20, 26, 27, 28, 29, 30, 31, 33, 34, 37, 38, 39, 40, 50, 51, 52, 54, 55, 59, 63, 64, 65, 66, 69, 70, 71, 75, 76, 77, 78, 79, 81, 83, 85, 90, 92, 93, 94, 96, 102, 106, 107, 117, 118, 119, 120, 750}
	// LightBlocks is a map of block ids to the amount of light they give off.
	LightBlocks = LightBlockList{
		10:  15,
		11:  15,
		39:  1,
		50:  14,
		51:  15,
		62:  13,
		74:  13,
		76:  7,
		89:  15,
		90:  11,
		91:  15,
		94:  9,
		117: 1,
		119: 15,
		120: 1,
		122: 1,
		124: 15,
		130: 7,
		138: 15,
	}
)
type Biome
type Biome uint8

Biome is a convenience type for biomes.

const (
	Ocean                Biome = 0
	Plains               Biome = 1
	Desert               Biome = 2
	ExtremeHills         Biome = 3
	Forest               Biome = 4
	Taiga                Biome = 5
	Swampland            Biome = 6
	River                Biome = 7
	Hell                 Biome = 8
	Sky                  Biome = 9
	FrozenOcean          Biome = 10
	FrozenRiver          Biome = 11
	IcePlains            Biome = 12
	IceMountains         Biome = 13
	MushroomIsland       Biome = 14
	MushroomIslandShore  Biome = 15
	Beach                Biome = 16
	DesertHills          Biome = 17
	ForestHills          Biome = 18
	TaigaHills           Biome = 19
	ExtremeHillsEdge     Biome = 20
	Jungle               Biome = 21
	JungleHills          Biome = 22
	JungleEdge           Biome = 23
	DeepOcean            Biome = 24
	StoneBeach           Biome = 25
	ColdBeach            Biome = 26
	BirchForest          Biome = 27
	BirchForestHills     Biome = 28
	RoofedForest         Biome = 29
	ColdTaiga            Biome = 30
	ColdTaigaHills       Biome = 31
	MegaTaiga            Biome = 32
	MegaTaigaHills       Biome = 33
	ExtremeHillsPlus     Biome = 34
	Savanna              Biome = 35
	SavannaPlateau       Biome = 36
	Mesa                 Biome = 37
	MesaPlateauF         Biome = 38
	MesaPlateau          Biome = 39
	SunflowerPlains      Biome = 129
	DeserM               Biome = 130
	ExtremeHillsM        Biome = 131
	FlowerForest         Biome = 132
	TaigaM               Biome = 133
	SwamplandM           Biome = 134
	IcePlainsSpikes      Biome = 140
	JungleM              Biome = 149
	JungleEdgeM          Biome = 151
	BirchForestM         Biome = 155
	BirchForestHillsM    Biome = 156
	RoofedForestM        Biome = 157
	ColdTaigaM           Biome = 158
	MegaSpruceTaiga      Biome = 160
	MegaSpruceTaigaHills Biome = 161
	ExtremeHillsPlusM    Biome = 162
	SavannaM             Biome = 163
	SavannaPlateauM      Biome = 164
	MesaBryce            Biome = 165
	MesaPlateauFM        Biome = 166
	MesaPlateauM         Biome = 167
	AutoBiome            Biome = 255
)

Biome constants.

func (Biome) Equal
func (b Biome) Equal(e interface{}) bool

Equal is an implementation of the equaler.Equaler interface.

func (Biome) String
func (b Biome) String() string
type Block
type Block struct {
	ID   uint16
	Data uint8
}

Block is a type that represents the full information for a block, id, data, metadata and scheduled tick data.

func (*Block) AddTicks
func (b *Block) AddTicks(t ...Tick)

AddTicks adds one or more scheduled ticks to the block.

func (Block) Equal
func (b Block) Equal(e interface{}) bool

Equal is an implementation of the equaler.Equaler interface.

func (Block) EqualBlock
func (b Block) EqualBlock(c Block) bool

EqualBlock checks for equality between the two blocks.

func (Block) GetMetadata
func (b Block) GetMetadata() nbt.Compound

GetMetadata returns a copy of the metadata for this block, or nil is it has none.

func (Block) GetTicks
func (b Block) GetTicks() []Tick

GetTicks returns all of the scheduled ticks for a block.

func (Block) HasMetadata
func (b Block) HasMetadata() bool

HasMetadata returns true if the block contains extended metadata.

func (Block) HasTicks
func (b Block) HasTicks() bool

HasTicks returns true if the block has any scheduled ticks.

func (Block) IsLiquid
func (b Block) IsLiquid() bool

IsLiquid returns true if the block id matches a liquid.

func (Block) Light
func (b Block) Light() uint8

Light returns how much light is generated by this block.

func (Block) Opacity
func (b Block) Opacity() uint8

Opacity returns how much light is blocked by this block..

func (*Block) SetMetadata
func (b *Block) SetMetadata(data nbt.Compound)

SetMetadata sets the blocks metadata to a copy of the given metadata.

func (*Block) SetTicks
func (b *Block) SetTicks(t []Tick)

SetTicks sets the scheduled ticks for the block, replacing any existing ones.

func (Block) String
func (b Block) String() string
type ConflictError
type ConflictError struct {
	X, Z int32
}

ConflictError is an error return by SetChunk when trying to save a single chunk multiple times during the same save operation.

func (ConflictError) Error
func (c ConflictError) Error() string
type FilePath
type FilePath struct {
}

FilePath implements the Path interface and provides a standard minecraft save format.

func NewFilePath
func NewFilePath(dirname string) (*FilePath, error)

NewFilePath constructs a new directory based path to read from.

func NewFilePathDimension
func NewFilePathDimension(dirname string, dimension int) (*FilePath, error)

NewFilePathDimension create a new FilePath, but with the option to set the dimension that chunks are loaded from.

Example. Dimension -1 == The Nether

Dimension  1 == The End
func (*FilePath) Defrag
func (p *FilePath) Defrag(x, z int32) error

Defrag rewrites a region file to reduce wasted space.

func (*FilePath) GetChunk
func (p *FilePath) GetChunk(x, z int32) (nbt.Tag, error)

GetChunk returns the chunk at chunk coords x, z.

func (*FilePath) GetChunks
func (p *FilePath) GetChunks(x, z int32) ([][2]int32, error)

GetChunks returns a list of all chunks within a region with coords x,z.

func (*FilePath) GetRegions
func (p *FilePath) GetRegions() [][2]int32

GetRegions returns a list of region x,z coords of all generated regions.

func (*FilePath) HasLock
func (p *FilePath) HasLock() bool

HasLock returns whether or not another program has taken the lock.

func (*FilePath) Lock
func (p *FilePath) Lock() error

Lock will retake the lock file if it has been lost. May cause corruption.

func (*FilePath) ReadLevelDat
func (p *FilePath) ReadLevelDat() (nbt.Tag, error)

ReadLevelDat returns the level data.

func (*FilePath) RemoveChunk
func (p *FilePath) RemoveChunk(x, z int32) error

RemoveChunk deletes the chunk at chunk coords x, z.

func (*FilePath) SetChunk
func (p *FilePath) SetChunk(data ...nbt.Tag) error

SetChunk saves multiple chunks at once, possibly returning a MultiError if multiple errors were encountered.

func (*FilePath) WriteLevelDat
func (p *FilePath) WriteLevelDat(data nbt.Tag) error

WriteLevelDat Writes the level data.

type FilePathSetError
type FilePathSetError struct {
	X, Z int32
	Err  error
}

FilePathSetError is an error returned from SetChunk when some error is returned either from converting the nbt or saving it.

func (FilePathSetError) Error
func (f FilePathSetError) Error() string
type Level
type Level struct {
}

Level is the base type for minecraft data, all data for a minecraft level is either store in, or accessed from, this type.

func NewLevel
func NewLevel(location Path) (*Level, error)

NewLevel creates/Loads a minecraft level from the given path.

func (*Level) AllowCommands
func (l *Level) AllowCommands(a bool)

AllowCommands enables/disables the cheat commands.

func (*Level) BorderCenter
func (l *Level) BorderCenter(x, z float64)

BorderCenter sets the position of the center of the World Border.

func (*Level) BorderSize
func (l *Level) BorderSize(w float64)

BorderSize sets the width of the border.

func (*Level) Close
func (l *Level) Close()

Close closes all open chunks, but does not save them.

func (*Level) CommandBlockOutput
func (l *Level) CommandBlockOutput(d bool)

CommandBlockOutput enables/disables chat echo for command blocks.

func (*Level) CommandFeedback
func (l *Level) CommandFeedback(d bool)

CommandFeedback enables/disables the echo for player commands in the chat.

func (*Level) DayLightCycle
func (l *Level) DayLightCycle(d bool)

DayLightCycle enables/disables the day/night cycle.

func (*Level) DeathMessages
func (l *Level) DeathMessages(d bool)

DeathMessages enables/disables the logging of player deaths to the chat.

func (*Level) Difficulty
func (l *Level) Difficulty(d int8)

Difficulty sets the level difficulty.

func (*Level) DifficultyLocked
func (l *Level) DifficultyLocked(dl bool)

DifficultyLocked locks the difficulty in game.

func (*Level) FireTick
func (l *Level) FireTick(d bool)

FireTick enables/disables fire updates, such as spreading and extinguishing.

func (*Level) GameMode
func (l *Level) GameMode(gm int32)

GameMode sets the game mode type.

func (*Level) Generator
func (l *Level) Generator(generator string)

Generator sets the generator type.

func (*Level) GeneratorOptions
func (l *Level) GeneratorOptions(options string)

GeneratorOptions sets the generator options for a flat or custom generator. The syntax is not checked.

func (*Level) GetBiome
func (l *Level) GetBiome(x, z int32) (Biome, error)

GetBiome returns the biome for the column x, z.

func (*Level) GetBlock
func (l *Level) GetBlock(x, y, z int32) (Block, error)

GetBlock gets the block at coordinates x, y, z.

func (*Level) GetHeight
func (l *Level) GetHeight(x, z int32) (int32, error)

GetHeight returns the y coordinate for the highest non-transparent block at column x, z.

func (*Level) GetLevelName
func (l *Level) GetLevelName() string

GetLevelName sets the given string to the name of the minecraft level.

func (*Level) GetSpawn
func (l *Level) GetSpawn() (x int32, y int32, z int32)

GetSpawn sets the given x, y, z coordinates to the current spawn point.

func (*Level) Hardcore
func (l *Level) Hardcore(h bool)

Hardcore enables/disables hardcore mode.

func (*Level) HealthRegeneration
func (l *Level) HealthRegeneration(d bool)

HealthRegeneration enables/disables the regeneration of the players health when their hunger is high enough.

func (*Level) KeepInventory
func (l *Level) KeepInventory(d bool)

KeepInventory enables/disables the keeping of a players inventory upon death.

func (*Level) LevelName
func (l *Level) LevelName(name string)

LevelName sets the name of the minecraft level.

func (*Level) LogAdminCommands
func (l *Level) LogAdminCommands(d bool)

LogAdminCommands enables/disables the logging of admin commands to the log.

func (*Level) MapFeatures
func (l *Level) MapFeatures(mf bool)

MapFeatures enables/disables map feature generation (villages, strongholds, mineshafts, etc.).

func (*Level) MobGriefing
func (l *Level) MobGriefing(d bool)

MobGriefing enables/disables the ability of mobs to destroy blocks.

func (*Level) MobLoot
func (l *Level) MobLoot(d bool)

MobLoot enables/disable mob loot drops.

func (*Level) MobSpawning
func (l *Level) MobSpawning(d bool)

MobSpawning enables/disables mob spawning.

func (*Level) RainTime
func (l *Level) RainTime(time int32)

RainTime sets the time until the rain state changes.

func (*Level) Raining
func (l *Level) Raining(raining bool)

Raining sets the rain on or off.

func (*Level) Save
func (l *Level) Save() error

Save saves all open chunks, but does not close them.

func (*Level) Seed
func (l *Level) Seed(seed int64)

Seed sets the random seed for the level.

func (*Level) SetBiome
func (l *Level) SetBiome(x, z int32, biome Biome) error

SetBiome sets the biome for the column x, z.

func (*Level) SetBlock
func (l *Level) SetBlock(x, y, z int32, block Block) error

SetBlock sets the block at coordinates x, y, z. Also processes any lighting updates if applicable.

func (*Level) Spawn
func (l *Level) Spawn(x, y, z int32)

Spawn sets the spawn point to the given coordinates..

func (*Level) ThunderTime
func (l *Level) ThunderTime(time int32)

ThunderTime sets the tune until the thunder state changes.

func (*Level) Thundering
func (l *Level) Thundering(thundering bool)

Thundering sets the lightning/thunder on or off.

func (*Level) TicksExisted
func (l *Level) TicksExisted(t int64)

TicksExisted sets how many ticks have passed in game.

func (*Level) TileDrops
func (l *Level) TileDrops(d bool)

TileDrops enables/disables the dropping of items upon block breakage.

func (*Level) Time
func (l *Level) Time(t int64)

Time sets the in world time.

type LightBlockList
type LightBlockList map[uint16]uint8

LightBlockList is a map of block ids to the amount of light they give off.

func (LightBlockList) Add
func (l LightBlockList) Add(blockID uint16, light uint8) bool

Add is a convenience method for the light block list. It adds a new block id to the list with its corresponding light level.

func (LightBlockList) Remove
func (l LightBlockList) Remove(blockID uint16) bool

Remove is a convenience method to remove a block id from the light block list.

type MemPath
type MemPath struct {
}

MemPath is an in memory minecraft level format that implements the Path interface.

func NewMemPath
func NewMemPath() *MemPath

NewMemPath creates a new MemPath implementation.

func (*MemPath) GetChunk
func (m *MemPath) GetChunk(x, z int32) (nbt.Tag, error)

GetChunk returns the chunk at chunk coords x, z.

func (*MemPath) ReadLevelDat
func (m *MemPath) ReadLevelDat() (nbt.Tag, error)

ReadLevelDat Returns the level data.

func (*MemPath) RemoveChunk
func (m *MemPath) RemoveChunk(x, z int32) error

RemoveChunk deletes the chunk at chunk coords x, z.

func (*MemPath) SetChunk
func (m *MemPath) SetChunk(data ...nbt.Tag) error

SetChunk saves multiple chunks at once.

func (*MemPath) WriteLevelDat
func (m *MemPath) WriteLevelDat(data nbt.Tag) error

WriteLevelDat Writes the level data.

type MissingTagError
type MissingTagError struct {
	TagName string
}

MissingTagError is an error type returned when an expected tag is not found.

func (MissingTagError) Error
func (m MissingTagError) Error() string
type MultiError
type MultiError struct {
	Errors []error
}

MultiError is an error type that contains multiple errors.

func (MultiError) Error
func (m MultiError) Error() string
type Option
type Option func(*Level)

Option is a function used to set an option for a minecraft level struct.

type Path
type Path interface {
	// Returns an empty nbt.Tag (TagEnd) when chunk does not exists.
	GetChunk(int32, int32) (nbt.Tag, error)
	SetChunk(...nbt.Tag) error
	RemoveChunk(int32, int32) error
	ReadLevelDat() (nbt.Tag, error)
	WriteLevelDat(nbt.Tag) error
}

The Path interface allows the minecraft level to be created from/saved to different formats.

type Tick
type Tick struct {
	I, T, P int32
}

Tick is a type that represents a scheduled tick.

type TransparentBlockList
type TransparentBlockList []uint16

TransparentBlockList is a slice of the block ids that are transparent.

func (*TransparentBlockList) Add
func (t *TransparentBlockList) Add(blockID uint16) bool

Add is a convenience method for the transparent block list. It adds a new block id to the list, making sure to not add duplicates.

func (*TransparentBlockList) Remove
func (t *TransparentBlockList) Remove(blockID uint16) bool

Remove is a convenience method to remove a block id from the transparent block list.

type UnexpectedValue
type UnexpectedValue struct {
	TagName, Expecting, Got string
}

UnexpectedValue is an error returned from chunk loading during sanity checking.

func (UnexpectedValue) Error
func (u UnexpectedValue) Error() string
type UnknownCompression
type UnknownCompression struct {
	Code byte
}

UnknownCompression is an error returned by path types when it encounters a compression scheme it is not prepared to handle or an unknown compression scheme.

func (UnknownCompression) Error
func (u UnknownCompression) Error() string
type WrongTypeError
type WrongTypeError struct {
	TagName        string
	Expecting, Got nbt.TagID
}

WrongTypeError is an error returned when an nbt tag has an unexpected type.

func (WrongTypeError) Error
func (w WrongTypeError) Error() string

Documentation

Overview

Package minecraft is a level viewer/editor for the popular creative game minecraft.

Example
package main

import (
	"fmt"

	"vimagination.zapto.org/minecraft"
)

func main() {
	path := minecraft.NewMemPath()
	level, _ := minecraft.NewLevel(path)
	level.LevelName("TestMine")
	name := level.GetLevelName()
	fmt.Println(name)
}
Output:

TestMine

Index

Examples

Constants

View Source
const (
	DefaultGenerator    = "default"
	FlatGenerator       = "flat"
	LargeBiomeGenerator = "largeBiomes"
	AmplifiedGenerator  = "amplified"
	CustomGenerator     = "customized"
	DebugGenerator      = "debug_all_block_states"
)

Default minecraft generators

View Source
const (
	Survival int32 = iota
	Creative
	Adventure
	Spectator
)

Game Modes Settings.

View Source
const (
	Peaceful int8 = iota
	Easy
	Normal
	Hard
)

Difficulty Settings.

View Source
const (
	SunRise  = 0
	Noon     = 6000
	SunSet   = 12000
	MidNight = 18000
	Day      = 24000
)

Time-of-day convenience constants.

View Source
const (
	GZip byte = 1
	Zlib byte = 2
)

Compression convenience constants.

Variables

View Source
var (
	// ErrOOB is an error returned when sanity checking section data.
	ErrOOB = errors.New("received out-of-bounds error")
	// ErrNoLock is an error returns by path types to indicate that the lock on the
	// minecraft level has been locked and needs reinstating to continue.
	ErrNoLock = errors.New("lost lock on files")
)
View Source
var (
	// TransparentBlocks is a slice of the block ids that are transparent.
	// This is used in lighting calculations and is user overridable for custom
	// blocks.
	TransparentBlocks = TransparentBlockList{0, 6, 18, 20, 26, 27, 28, 29, 30, 31, 33, 34, 37, 38, 39, 40, 50, 51, 52, 54, 55, 59, 63, 64, 65, 66, 69, 70, 71, 75, 76, 77, 78, 79, 81, 83, 85, 90, 92, 93, 94, 96, 102, 106, 107, 117, 118, 119, 120, 750}
	// LightBlocks is a map of block ids to the amount of light they give off.
	LightBlocks = LightBlockList{
		10:  15,
		11:  15,
		39:  1,
		50:  14,
		51:  15,
		62:  13,
		74:  13,
		76:  7,
		89:  15,
		90:  11,
		91:  15,
		94:  9,
		117: 1,
		119: 15,
		120: 1,
		122: 1,
		124: 15,
		130: 7,
		138: 15,
	}
)

Functions

This section is empty.

Types

type Biome

type Biome uint8

Biome is a convenience type for biomes.

const (
	Ocean                Biome = 0
	Plains               Biome = 1
	Desert               Biome = 2
	ExtremeHills         Biome = 3
	Forest               Biome = 4
	Taiga                Biome = 5
	Swampland            Biome = 6
	River                Biome = 7
	Hell                 Biome = 8
	Sky                  Biome = 9
	FrozenOcean          Biome = 10
	FrozenRiver          Biome = 11
	IcePlains            Biome = 12
	IceMountains         Biome = 13
	MushroomIsland       Biome = 14
	MushroomIslandShore  Biome = 15
	Beach                Biome = 16
	DesertHills          Biome = 17
	ForestHills          Biome = 18
	TaigaHills           Biome = 19
	ExtremeHillsEdge     Biome = 20
	Jungle               Biome = 21
	JungleHills          Biome = 22
	JungleEdge           Biome = 23
	DeepOcean            Biome = 24
	StoneBeach           Biome = 25
	ColdBeach            Biome = 26
	BirchForest          Biome = 27
	BirchForestHills     Biome = 28
	RoofedForest         Biome = 29
	ColdTaiga            Biome = 30
	ColdTaigaHills       Biome = 31
	MegaTaiga            Biome = 32
	MegaTaigaHills       Biome = 33
	ExtremeHillsPlus     Biome = 34
	Savanna              Biome = 35
	SavannaPlateau       Biome = 36
	Mesa                 Biome = 37
	MesaPlateauF         Biome = 38
	MesaPlateau          Biome = 39
	SunflowerPlains      Biome = 129
	DeserM               Biome = 130
	ExtremeHillsM        Biome = 131
	FlowerForest         Biome = 132
	TaigaM               Biome = 133
	SwamplandM           Biome = 134
	IcePlainsSpikes      Biome = 140
	JungleM              Biome = 149
	JungleEdgeM          Biome = 151
	BirchForestM         Biome = 155
	BirchForestHillsM    Biome = 156
	RoofedForestM        Biome = 157
	ColdTaigaM           Biome = 158
	MegaSpruceTaiga      Biome = 160
	MegaSpruceTaigaHills Biome = 161
	ExtremeHillsPlusM    Biome = 162
	SavannaM             Biome = 163
	SavannaPlateauM      Biome = 164
	MesaBryce            Biome = 165
	MesaPlateauFM        Biome = 166
	MesaPlateauM         Biome = 167
	AutoBiome            Biome = 255
)

Biome constants.

func (Biome) Equal

func (b Biome) Equal(e interface{}) bool

Equal is an implementation of the equaler.Equaler interface.

func (Biome) String

func (b Biome) String() string

type Block

type Block struct {
	ID   uint16
	Data uint8
	// contains filtered or unexported fields
}

Block is a type that represents the full information for a block, id, data, metadata and scheduled tick data.

func (*Block) AddTicks

func (b *Block) AddTicks(t ...Tick)

AddTicks adds one or more scheduled ticks to the block.

func (Block) Equal

func (b Block) Equal(e interface{}) bool

Equal is an implementation of the equaler.Equaler interface.

func (Block) EqualBlock

func (b Block) EqualBlock(c Block) bool

EqualBlock checks for equality between the two blocks.

func (Block) GetMetadata

func (b Block) GetMetadata() nbt.Compound

GetMetadata returns a copy of the metadata for this block, or nil is it has none.

func (Block) GetTicks

func (b Block) GetTicks() []Tick

GetTicks returns all of the scheduled ticks for a block.

func (Block) HasMetadata

func (b Block) HasMetadata() bool

HasMetadata returns true if the block contains extended metadata.

func (Block) HasTicks

func (b Block) HasTicks() bool

HasTicks returns true if the block has any scheduled ticks.

func (Block) IsLiquid

func (b Block) IsLiquid() bool

IsLiquid returns true if the block id matches a liquid.

func (Block) Light

func (b Block) Light() uint8

Light returns how much light is generated by this block.

func (Block) Opacity

func (b Block) Opacity() uint8

Opacity returns how much light is blocked by this block..

func (*Block) SetMetadata

func (b *Block) SetMetadata(data nbt.Compound)

SetMetadata sets the blocks metadata to a copy of the given metadata.

func (*Block) SetTicks

func (b *Block) SetTicks(t []Tick)

SetTicks sets the scheduled ticks for the block, replacing any existing ones.

func (Block) String

func (b Block) String() string

type ConflictError

type ConflictError struct {
	X, Z int32
}

ConflictError is an error return by SetChunk when trying to save a single chunk multiple times during the same save operation.

func (ConflictError) Error

func (c ConflictError) Error() string

type FilePath

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

FilePath implements the Path interface and provides a standard minecraft save format.

func NewFilePath

func NewFilePath(dirname string) (*FilePath, error)

NewFilePath constructs a new directory based path to read from.

func NewFilePathDimension

func NewFilePathDimension(dirname string, dimension int) (*FilePath, error)

NewFilePathDimension create a new FilePath, but with the option to set the dimension that chunks are loaded from.

Example. Dimension -1 == The Nether

Dimension  1 == The End

func (*FilePath) Defrag

func (p *FilePath) Defrag(x, z int32) error

Defrag rewrites a region file to reduce wasted space.

func (*FilePath) GetChunk

func (p *FilePath) GetChunk(x, z int32) (nbt.Tag, error)

GetChunk returns the chunk at chunk coords x, z.

func (*FilePath) GetChunks

func (p *FilePath) GetChunks(x, z int32) ([][2]int32, error)

GetChunks returns a list of all chunks within a region with coords x,z.

func (*FilePath) GetRegions

func (p *FilePath) GetRegions() [][2]int32

GetRegions returns a list of region x,z coords of all generated regions.

func (*FilePath) HasLock

func (p *FilePath) HasLock() bool

HasLock returns whether or not another program has taken the lock.

func (*FilePath) Lock

func (p *FilePath) Lock() error

Lock will retake the lock file if it has been lost. May cause corruption.

func (*FilePath) ReadLevelDat

func (p *FilePath) ReadLevelDat() (nbt.Tag, error)

ReadLevelDat returns the level data.

func (*FilePath) RemoveChunk

func (p *FilePath) RemoveChunk(x, z int32) error

RemoveChunk deletes the chunk at chunk coords x, z.

func (*FilePath) SetChunk

func (p *FilePath) SetChunk(data ...nbt.Tag) error

SetChunk saves multiple chunks at once, possibly returning a MultiError if multiple errors were encountered.

func (*FilePath) WriteLevelDat

func (p *FilePath) WriteLevelDat(data nbt.Tag) error

WriteLevelDat Writes the level data.

type FilePathSetError

type FilePathSetError struct {
	X, Z int32
	Err  error
}

FilePathSetError is an error returned from SetChunk when some error is returned either from converting the nbt or saving it.

func (FilePathSetError) Error

func (f FilePathSetError) Error() string

type Level

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

Level is the base type for minecraft data, all data for a minecraft level is either store in, or accessed from, this type.

func NewLevel

func NewLevel(location Path) (*Level, error)

NewLevel creates/Loads a minecraft level from the given path.

func (*Level) AllowCommands

func (l *Level) AllowCommands(a bool)

AllowCommands enables/disables the cheat commands.

func (*Level) BorderCenter

func (l *Level) BorderCenter(x, z float64)

BorderCenter sets the position of the center of the World Border.

func (*Level) BorderSize

func (l *Level) BorderSize(w float64)

BorderSize sets the width of the border.

func (*Level) Close

func (l *Level) Close()

Close closes all open chunks, but does not save them.

func (*Level) CommandBlockOutput

func (l *Level) CommandBlockOutput(d bool)

CommandBlockOutput enables/disables chat echo for command blocks.

func (*Level) CommandFeedback

func (l *Level) CommandFeedback(d bool)

CommandFeedback enables/disables the echo for player commands in the chat.

func (*Level) DayLightCycle

func (l *Level) DayLightCycle(d bool)

DayLightCycle enables/disables the day/night cycle.

func (*Level) DeathMessages

func (l *Level) DeathMessages(d bool)

DeathMessages enables/disables the logging of player deaths to the chat.

func (*Level) Difficulty

func (l *Level) Difficulty(d int8)

Difficulty sets the level difficulty.

func (*Level) DifficultyLocked

func (l *Level) DifficultyLocked(dl bool)

DifficultyLocked locks the difficulty in game.

func (*Level) FireTick

func (l *Level) FireTick(d bool)

FireTick enables/disables fire updates, such as spreading and extinguishing.

func (*Level) GameMode

func (l *Level) GameMode(gm int32)

GameMode sets the game mode type.

func (*Level) Generator

func (l *Level) Generator(generator string)

Generator sets the generator type.

func (*Level) GeneratorOptions

func (l *Level) GeneratorOptions(options string)

GeneratorOptions sets the generator options for a flat or custom generator. The syntax is not checked.

func (*Level) GetBiome

func (l *Level) GetBiome(x, z int32) (Biome, error)

GetBiome returns the biome for the column x, z.

func (*Level) GetBlock

func (l *Level) GetBlock(x, y, z int32) (Block, error)

GetBlock gets the block at coordinates x, y, z.

func (*Level) GetHeight

func (l *Level) GetHeight(x, z int32) (int32, error)

GetHeight returns the y coordinate for the highest non-transparent block at column x, z.

func (*Level) GetLevelName

func (l *Level) GetLevelName() string

GetLevelName sets the given string to the name of the minecraft level.

func (*Level) GetSpawn

func (l *Level) GetSpawn() (x int32, y int32, z int32)

GetSpawn sets the given x, y, z coordinates to the current spawn point.

func (*Level) Hardcore

func (l *Level) Hardcore(h bool)

Hardcore enables/disables hardcore mode.

func (*Level) HealthRegeneration

func (l *Level) HealthRegeneration(d bool)

HealthRegeneration enables/disables the regeneration of the players health when their hunger is high enough.

func (*Level) KeepInventory

func (l *Level) KeepInventory(d bool)

KeepInventory enables/disables the keeping of a players inventory upon death.

func (*Level) LevelName

func (l *Level) LevelName(name string)

LevelName sets the name of the minecraft level.

func (*Level) LogAdminCommands

func (l *Level) LogAdminCommands(d bool)

LogAdminCommands enables/disables the logging of admin commands to the log.

func (*Level) MapFeatures

func (l *Level) MapFeatures(mf bool)

MapFeatures enables/disables map feature generation (villages, strongholds, mineshafts, etc.).

func (*Level) MobGriefing

func (l *Level) MobGriefing(d bool)

MobGriefing enables/disables the ability of mobs to destroy blocks.

func (*Level) MobLoot

func (l *Level) MobLoot(d bool)

MobLoot enables/disable mob loot drops.

func (*Level) MobSpawning

func (l *Level) MobSpawning(d bool)

MobSpawning enables/disables mob spawning.

func (*Level) RainTime

func (l *Level) RainTime(time int32)

RainTime sets the time until the rain state changes.

func (*Level) Raining

func (l *Level) Raining(raining bool)

Raining sets the rain on or off.

func (*Level) Save

func (l *Level) Save() error

Save saves all open chunks, but does not close them.

func (*Level) Seed

func (l *Level) Seed(seed int64)

Seed sets the random seed for the level.

func (*Level) SetBiome

func (l *Level) SetBiome(x, z int32, biome Biome) error

SetBiome sets the biome for the column x, z.

func (*Level) SetBlock

func (l *Level) SetBlock(x, y, z int32, block Block) error

SetBlock sets the block at coordinates x, y, z. Also processes any lighting updates if applicable.

func (*Level) Spawn

func (l *Level) Spawn(x, y, z int32)

Spawn sets the spawn point to the given coordinates..

func (*Level) ThunderTime

func (l *Level) ThunderTime(time int32)

ThunderTime sets the tune until the thunder state changes.

func (*Level) Thundering

func (l *Level) Thundering(thundering bool)

Thundering sets the lightning/thunder on or off.

func (*Level) TicksExisted

func (l *Level) TicksExisted(t int64)

TicksExisted sets how many ticks have passed in game.

func (*Level) TileDrops

func (l *Level) TileDrops(d bool)

TileDrops enables/disables the dropping of items upon block breakage.

func (*Level) Time

func (l *Level) Time(t int64)

Time sets the in world time.

type LightBlockList

type LightBlockList map[uint16]uint8

LightBlockList is a map of block ids to the amount of light they give off.

func (LightBlockList) Add

func (l LightBlockList) Add(blockID uint16, light uint8) bool

Add is a convenience method for the light block list. It adds a new block id to the list with its corresponding light level.

func (LightBlockList) Remove

func (l LightBlockList) Remove(blockID uint16) bool

Remove is a convenience method to remove a block id from the light block list.

type MemPath

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

MemPath is an in memory minecraft level format that implements the Path interface.

func NewMemPath

func NewMemPath() *MemPath

NewMemPath creates a new MemPath implementation.

func (*MemPath) GetChunk

func (m *MemPath) GetChunk(x, z int32) (nbt.Tag, error)

GetChunk returns the chunk at chunk coords x, z.

func (*MemPath) ReadLevelDat

func (m *MemPath) ReadLevelDat() (nbt.Tag, error)

ReadLevelDat Returns the level data.

func (*MemPath) RemoveChunk

func (m *MemPath) RemoveChunk(x, z int32) error

RemoveChunk deletes the chunk at chunk coords x, z.

func (*MemPath) SetChunk

func (m *MemPath) SetChunk(data ...nbt.Tag) error

SetChunk saves multiple chunks at once.

func (*MemPath) WriteLevelDat

func (m *MemPath) WriteLevelDat(data nbt.Tag) error

WriteLevelDat Writes the level data.

type MissingTagError

type MissingTagError struct {
	TagName string
}

MissingTagError is an error type returned when an expected tag is not found.

func (MissingTagError) Error

func (m MissingTagError) Error() string

type MultiError

type MultiError struct {
	Errors []error
}

MultiError is an error type that contains multiple errors.

func (MultiError) Error

func (m MultiError) Error() string

type Option

type Option func(*Level)

Option is a function used to set an option for a minecraft level struct.

type Path

type Path interface {
	// Returns an empty nbt.Tag (TagEnd) when chunk does not exists.
	GetChunk(int32, int32) (nbt.Tag, error)
	SetChunk(...nbt.Tag) error
	RemoveChunk(int32, int32) error
	ReadLevelDat() (nbt.Tag, error)
	WriteLevelDat(nbt.Tag) error
}

The Path interface allows the minecraft level to be created from/saved to different formats.

type Tick

type Tick struct {
	I, T, P int32
}

Tick is a type that represents a scheduled tick.

type TransparentBlockList

type TransparentBlockList []uint16

TransparentBlockList is a slice of the block ids that are transparent.

func (*TransparentBlockList) Add

func (t *TransparentBlockList) Add(blockID uint16) bool

Add is a convenience method for the transparent block list. It adds a new block id to the list, making sure to not add duplicates.

func (*TransparentBlockList) Remove

func (t *TransparentBlockList) Remove(blockID uint16) bool

Remove is a convenience method to remove a block id from the transparent block list.

type UnexpectedValue

type UnexpectedValue struct {
	TagName, Expecting, Got string
}

UnexpectedValue is an error returned from chunk loading during sanity checking.

func (UnexpectedValue) Error

func (u UnexpectedValue) Error() string

type UnknownCompression

type UnknownCompression struct {
	Code byte
}

UnknownCompression is an error returned by path types when it encounters a compression scheme it is not prepared to handle or an unknown compression scheme.

func (UnknownCompression) Error

func (u UnknownCompression) Error() string

type WrongTypeError

type WrongTypeError struct {
	TagName        string
	Expecting, Got nbt.TagID
}

WrongTypeError is an error returned when an nbt tag has an unexpected type.

func (WrongTypeError) Error

func (w WrongTypeError) Error() string

Directories

Path Synopsis
Package nbt implements a full Named Binary Tag reader/writer, based on the specs at http://web.archive.org/web/20110723210920/http://www.minecraft.net/docs/NBT.txt
Package nbt implements a full Named Binary Tag reader/writer, based on the specs at http://web.archive.org/web/20110723210920/http://www.minecraft.net/docs/NBT.txt

Jump to

Keyboard shortcuts

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