world

package
v0.0.0-...-50e9496 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2013 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGenerator

func AddGenerator(name string, f func() Generator)

Add a generator to be used for gemerating worlds. Should only be called at init.

func AddSystem

func AddSystem(name string, f func() System)

Add a system to be used for loading/saving worlds. Should only be called at init.

Types

type Chunk

type Chunk struct {
	X, Z int

	Sections  [16]*ChunkSection
	Biome     [16 * 16]byte
	HeightMap [16 * 16]byte

	Entities map[string]Entity
	// contains filtered or unexported fields
}

A chunk loaded locally in a flat byte arrays

func (*Chunk) Block

func (c *Chunk) Block(x, y, z int) byte

Gets the block at the coordinates

func (*Chunk) BlockLight

func (c *Chunk) BlockLight(x, y, z int) byte

func (*Chunk) Close

func (c *Chunk) Close() bool

func (*Chunk) Data

func (c *Chunk) Data(x, y, z int) byte

func (*Chunk) Init

func (c *Chunk) Init(world *World, gen Generator, system System)

Inits the chunk. Should only be called by the world

func (*Chunk) Join

func (c *Chunk) Join(watcher Watcher)

Adds the watcher to the chunk

func (*Chunk) Leave

func (c *Chunk) Leave(watcher Watcher)

Removes the watcher to the chunk

func (*Chunk) Location

func (c *Chunk) Location() (x, z int)

Returns the chunk's location

func (*Chunk) SetBlock

func (c *Chunk) SetBlock(x, y, z int, b byte)

Sets the block at the coordinates

func (*Chunk) SetBlockLight

func (c *Chunk) SetBlockLight(x, y, z int, l byte)

func (*Chunk) SetData

func (c *Chunk) SetData(x, y, z int, d byte)

func (*Chunk) SetSkyLight

func (c *Chunk) SetSkyLight(x, y, z int, l byte)

func (*Chunk) SkyLight

func (c *Chunk) SkyLight(x, y, z int) byte

type ChunkSection

type ChunkSection struct {
	Blocks     [16 * 16 * 16]byte
	Data       [(16 * 16 * 16) / 2]byte
	BlockLight [(16 * 16 * 16) / 2]byte
	SkyLight   [(16 * 16 * 16) / 2]byte
	//Counter of things that keep the section active
	//(blocks, lights)
	Count uint
}

type Dimension

type Dimension int8

Dimensions normally control the lighting and skycolour

const (
	Overworld Dimension = 0
	Nether    Dimension = -1
	End       Dimension = 1
)

type Entity

type Entity interface {
	//Returns the entity's UUID
	UUID() string
	//Returns wether the entity is saveable to the chunk
	Saveable() bool
}

type Generator

type Generator interface {
	//Generates the terrain in the passed chunk
	Generate(chunk *Chunk)
	//Returns the generator's name
	Name() string
	//Loads the generator's settings from the world
	Load(world *World)
	//Saves the generator's settings to the world
	Save(world *World)
}

type MsgpackSystem

type MsgpackSystem struct {
	Name string
	// contains filtered or unexported fields
}

func (*MsgpackSystem) Chunk

func (mw *MsgpackSystem) Chunk(x, z int) (*Chunk, bool)

Returns the chunk at the coordinates, also returns if the chunk existed before this

func (*MsgpackSystem) Close

func (mw *MsgpackSystem) Close()

func (*MsgpackSystem) CloseChunk

func (mw *MsgpackSystem) CloseChunk(x, z int, chunk *Chunk)

Closes the chunk in the system

func (*MsgpackSystem) Init

func (mw *MsgpackSystem) Init(path string)

Loads or creates the system

func (*MsgpackSystem) Read

func (mw *MsgpackSystem) Read(key string, v interface{}) error

Reads key into the passed struct pointer

func (*MsgpackSystem) SaveChunk

func (mw *MsgpackSystem) SaveChunk(x, z int, chunk *Chunk)

Saves the chunk back to storage.

func (*MsgpackSystem) SystemName

func (mw *MsgpackSystem) SystemName() string

Gets the name of the system

func (*MsgpackSystem) Write

func (mw *MsgpackSystem) Write(key string, v interface{}) error

Writes the passed struct/struct pointer to the data folder with the name key.nether.

type System

type System interface {
	//Loads or creates the system
	Init(path string)
	//Gets the name of the system
	SystemName() string
	//Writes the passed struct/struct pointer to the system's storage
	//with the key 'name'.
	Write(name string, v interface{}) error
	//Reads 'name' into the passed struct pointer
	Read(name string, v interface{}) error
	//Returns the chunk at the coordinates, also returns if the chunk existed
	//before this
	Chunk(x, z int) (*Chunk, bool)
	//Saves the chunk back to storage.
	SaveChunk(x, z int, storage *Chunk)
	//Closes the chunk in the system
	CloseChunk(x, z int, storage *Chunk)
	//Closes the system
	Close()
}

Systems are the underlying storage system for worlds. The Write/Read and Chunk methods write/read structs into the system. The methods should ignore fields tagged `ignore:"true"`

type TryClose

type TryClose struct {
	Ret   chan struct{}
	Done  chan bool
	World *World
}

type Watcher

type Watcher interface {
	//Queues a packet to be sent to the watcher
	QueuePacket(packet protocol.Packet)
	//Returns the watcher's UUID
	UUID() string
}

type World

type World struct {
	Name string

	//The limiters were added because trying to send/save all the chunks
	//at once caused large amounts of memory usage
	SendLimiter  chan cachedCompressor
	SaveLimiter  chan struct{}
	RequestClose chan *Chunk
	// contains filtered or unexported fields
}

func GetWorld

func GetWorld(name string, tryClose chan TryClose) *World

Loads the world by name

func LoadWorld

func LoadWorld(name string, system System, gen Generator, dimension Dimension, tryClose chan TryClose) *World

Loads the world by name using the passed system if the world doesn't exists.

func (*World) AddEntity

func (world *World) AddEntity(x, z int, entity Entity, spawn []protocol.Packet, despawn []protocol.Packet)

func (*World) Block

func (world *World) Block(x, y, z int) (block, data byte)

Gets the block and data at the location

func (*World) Dimension

func (world *World) Dimension() Dimension

Returns the worlds dimension

func (*World) JoinChunk

func (world *World) JoinChunk(x, z int, watcher Watcher)

Adds the watcher to the chunk at the coordinates. If the chunk isn't loaded then it will be loaded.

func (*World) LeaveChunk

func (world *World) LeaveChunk(x, z int, watcher Watcher)

Removes the watcher to the chunk at the coordinates.

func (*World) Light

func (world *World) Light(x, y, z int, sky bool) (level byte)

Gets the block and data at the location

func (*World) QueuePacket

func (world *World) QueuePacket(x, z int, uuid string, packet protocol.Packet)

Sends the packet to all watchers of the chunk apart from the watcher with the passed uuid (leave blank to send to all)

func (*World) Read

func (world *World) Read(key string, value interface{}) error

Reads the value into the world's system's storage. This method is safe to call from different goroutines when the key is different.

func (*World) RemoveEntity

func (world *World) RemoveEntity(x, z int, entity Entity)

func (*World) SetBlock

func (world *World) SetBlock(x, y, z int, block, data byte)

Sets the block and data at the location

func (*World) TimeOfDay

func (world *World) TimeOfDay() int64

func (*World) UpdateSpawnData

func (world *World) UpdateSpawnData(x, z int, entity Entity, spawn bool, packets []protocol.Packet)

func (*World) Write

func (world *World) Write(key string, value interface{}) error

Writes the value into the world's system's storage. This method is safe to call from different goroutines when the key is different.

Directories

Path Synopsis
Package flat is designed to replicate vanilla's superflat worlds.
Package flat is designed to replicate vanilla's superflat worlds.

Jump to

Keyboard shortcuts

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