world

package
v0.0.0-...-6ef5be2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("could not load world")
	ErrOverwrite     = errors.New("chunk already generated. not overwriting.")
	ErrNotLoaded     = errors.New("chunk not loaded")
	ErrAlreadyLoaded = errors.New("chunk already loaded")
)
View Source
var (
	ErrOrphanChunk = errors.New("No world associated with chunk")
)

Functions

This section is empty.

Types

type Block

type Block struct {
}

type BlockEntity

type BlockEntity struct {
	ID       string
	Position Position
}

type Chunk

type Chunk struct {
	X             int
	Z             int
	Sections      [16]ChunkSection
	Entities      []Entity
	BlockEntities []BlockEntity
	// contains filtered or unexported fields
}

A minecraft chunk

func (*Chunk) Packet

func (c *Chunk) Packet() protocol.ChunkData

Generates a protocol.ChunkData packet from the chunk XXX this is a stub

func (*Chunk) Save

func (c *Chunk) Save() error

Saves a chunk to worlds/c.world.Name/c.x-y.gob Returns ErrOrphanChunk if c.world == nil

type ChunkSection

type ChunkSection struct {
	// Y Index of the Section (0 - 15)
	Y       int
	Palette []Block
}

type DefaultGenerator

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

func (DefaultGenerator) Generate

func (g DefaultGenerator) Generate(x, z int) (Chunk, error)

func (DefaultGenerator) Seed

func (g DefaultGenerator) Seed() int64

func (DefaultGenerator) SetSeed

func (g DefaultGenerator) SetSeed(seed int64)

type Entity

type Entity struct {
	ID       string
	Position Position
	Motion   struct {
		DX float64
		DY float64
		DZ float64
	}
	Rotation struct {
		Yaw   float32
		Pitch float32
	}
}

type Generator

type Generator interface {
	// Return the seed used by the generator
	Seed() int64

	// Set the seed used by the generator
	SetSeed(seed int64)

	Generate(x int, z int) (Chunk, error)
}

A generator is used to create an unknown chunk

type Position

type Position struct {
	X float64
	Y float64
	Z float64
}

type SuperflatGenerator

type SuperflatGenerator struct {
	BlockType int32
	Height    int16
	// contains filtered or unexported fields
}

func (SuperflatGenerator) Generate

func (s SuperflatGenerator) Generate(x, z int) (Chunk, error)

func (SuperflatGenerator) Seed

func (g SuperflatGenerator) Seed() int64

func (SuperflatGenerator) SetSeed

func (g SuperflatGenerator) SetSeed(seed int64)

type Type

type Type int
const (
	Overworld Type = iota
	Nether
	End
)

type World

type World struct {
	Name      string
	Type      Type
	Generator Generator
	// contains filtered or unexported fields
}

An x-z grid of chunks and associated information. Minecrafts "Overworld" (or "Nether") are one world

func Load

func Load(name string) (*World, error)

Load a new world from worlds/name/world.gob Returns ErrNotFound if the world has not been generated yet

func New

func New(name string, worldType Type, gen Generator) (*World, error)

Creates a new world and saves it

func (*World) Chunk

func (w *World) Chunk(x int, z int) (*Chunk, error)

Returns a pointer to the chunk Returns ErrNotLoaded if the chunk is not loaded

func (*World) GenerateChunk

func (w *World) GenerateChunk(x int, z int) error

Generates a chunk and saves it into worlds/w.Name/x-y.gob

func (*World) GetChunk

func (w *World) GetChunk(x int, z int) (*Chunk, error)

Like w.Chunk() but generates or loads the chunk if neccessary

func (*World) LoadChunk

func (w *World) LoadChunk(x int, z int) error

Loads a chunk from worlds/w.Name/x-y.gob registers it in w and returns it Returns ErrNotFound if the chunk has not been generated yet Returns ErrAlreadyLoaded if the chunk is already loaded

func (*World) Save

func (w *World) Save() error

Saves the world into worlds/w.Name/world.gob

func (*World) UnloadChunk

func (w *World) UnloadChunk(x int, z int) error

Unloads and saves a chunk from memory Return ErrNotLoaded if the cunk is not loaded

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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