v0.0.4 Latest Latest

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 31 Imported by: 0




This section is empty.


This section is empty.


func BlockRuntimeID

func BlockRuntimeID(b Block) (uint32, bool)

BlockRuntimeID attempts to return a runtime ID of a block state previously registered using RegisterBlock(). If the runtime ID is found, the bool returned is true. It is otherwise false.

func Distance

func Distance(a, b mgl64.Vec3) float64

Distance returns the distance between two vectors.

func RegisterBlock

func RegisterBlock(b Block, s BlockState) error

func RegisterBlockState

func RegisterBlockState(s BlockState) error

func RegisterItem

func RegisterItem(name string, item Item)

RegisterItem registers an item with the ID and meta passed. Once registered, items may be obtained from an ID and metadata value using itemByID(). If an item with the ID and meta passed already exists, RegisterItem panics.


type Axis

type Axis int

Axis represents the axis that a block may be directed in. Most blocks do not have an axis, but blocks such as logs or pillars do.

const (
	// Y represents the vertical Y axis.
	Y Axis = iota
	// Z represents the horizontal Z axis.
	// X represents the horizontal X axis.

func (Axis) FromString

func (a Axis) FromString(s string) (interface{}, error)

FromString returns an axis by a string.

func (Axis) String

func (a Axis) String() string

String converts an Axis into either x, y or z, depending on which axis it is.

type Block

type Block interface {
	// HasNBT specifies if this Block has additional NBT present in the world save, also known as a block
	// entity. If true is returned, Block must implemented the NBTer interface.
	HasNBT() bool
	// Model returns the BlockModel of the Block.
	Model() BlockModel

Block is a block that may be placed or found in a world. In addition, the block may also be added to an inventory: It is also an item. Every Block implementation must be able to be hashed as key in a map.

type BlockModel

type BlockModel interface {
	// AABB returns the bounding boxes that a block with this model can be collided with.
	AABB(pos BlockPos, w *World) []physics.AABB
	// FaceSolid checks if a specific face of a block at the position in a world passed is solid. Blocks may
	// be attached to these faces.
	FaceSolid(pos BlockPos, face Face, w *World) bool

BlockModel represents the model of a block. These models specify the ways a block can be collided with and whether or not specific faces are solid wrt. being able to, for example, place torches onto those sides.

type BlockPos

type BlockPos [3]int

BlockPos holds the position of a block. The position is represented of an array with an x, y and z value, where the y value is positive.

func BlockPosFromVec3

func BlockPosFromVec3(vec3 mgl64.Vec3) BlockPos

BlockPosFromVec3 returns a block position by a Vec3, rounding the values down adequately.

func (BlockPos) Add

func (p BlockPos) Add(pos BlockPos) BlockPos

Add adds two block positions together and returns a new one with the combined values.

func (BlockPos) Face

func (p BlockPos) Face(other BlockPos) Face

Face returns the face that the other BlockPos was on compared to the current BlockPos. The other BlockPos is assumed to be a direct neighbour of the current BlockPos.

func (BlockPos) Neighbours

func (p BlockPos) Neighbours(f func(neighbour BlockPos))

Neighbours calls the function passed for each of the block position's neighbours. If the Y value is below 0 or above 255, the function will not be called for that position.

func (BlockPos) OutOfBounds

func (p BlockPos) OutOfBounds() bool

OutOfBounds checks if the Y value is either bigger than 255 or smaller than 0.

func (BlockPos) Side

func (p BlockPos) Side(face Face) BlockPos

Side returns the position on the side of this block position, at a specific face.

func (BlockPos) Subtract

func (p BlockPos) Subtract(pos BlockPos) BlockPos

Subtract subtracts two block positions together and returns a new one with the combined values.

func (BlockPos) Vec3

func (p BlockPos) Vec3() mgl64.Vec3

Vec3 returns a vec3 holding the same coordinates as the block position.

func (BlockPos) Vec3Centre

func (p BlockPos) Vec3Centre() mgl64.Vec3

Vec3Centre returns a Vec3 holding the coordinates of the block position with 0.5 added on all axes.

func (BlockPos) Vec3Middle

func (p BlockPos) Vec3Middle() mgl64.Vec3

Vec3Middle returns a Vec3 holding the coordinates of the block position with 0.5 added on both horizontal axes.

func (BlockPos) X

func (p BlockPos) X() int

X returns the X coordinate of the block position.

func (BlockPos) Y

func (p BlockPos) Y() int

Y returns the Y coordinate of the block position.

func (BlockPos) Z

func (p BlockPos) Z() int

Z returns the Z coordinate of the block position.

type BlockState

type BlockState struct {
	Name       string                 `nbt:"name"`
	Properties map[string]interface{} `nbt:"states"`
	Version    int32                  `nbt:"version"`

func (BlockState) HashProperties

func (s BlockState) HashProperties() string

HashProperties produces a hash for the block properties held by the BlockState.

type ChunkPos

type ChunkPos [2]int32

ChunkPos holds the position of a chunk. The type is provided as a utility struct for keeping track of a chunk's position. Chunks do not themselves keep track of that. Chunk positions are different than block positions in the way that increasing the X/Z by one means increasing the absolute value on the X/Z axis in terms of blocks by 16.

func (ChunkPos) Hash

func (p ChunkPos) Hash() string

Hash returns the hash of the chunk position. It is essentially the bytes of the X and Z values of the position following each other.

func (ChunkPos) X

func (p ChunkPos) X() int32

X returns the X coordinate of the chunk position.

func (ChunkPos) Z

func (p ChunkPos) Z() int32

Z returns the Z coordinate of the chunk position.

type Direction

type Direction int

Direction represents a direction towards one of the horizontal axes of the world.

const (
	// North represents the north direction.
	North Direction = iota
	// South represents the south direction.
	// West represents the west direction.
	// East represents the east direction.

func AllDirections

func AllDirections() (d []Direction)

func (Direction) Face

func (d Direction) Face() Face

Face converts the direction to a block face.

func (Direction) Opposite

func (d Direction) Opposite() Direction

Opposite returns the opposite direction.

func (Direction) Rotate90

func (d Direction) Rotate90() Direction

Rotate90 rotates the direction 90 degrees horizontally and returns the new direction.

type Entity

type Entity interface {
	// AABB returns the AABB of the entity.
	AABB() physics.AABB
	// Position returns the current position of the entity in the world.
	Position() mgl64.Vec3
	// OnGround checks if the entity is currently on the ground.
	OnGround() bool
	// World returns the current world of the entity. This is always the world that the entity can actually be
	// found in.
	World() *World
	// Yaw returns the yaw of the entity. This is horizontal rotation (rotation around the vertical axis), and
	// is 0 when the entity faces forward.
	Yaw() float64
	// Pitch returns the pitch of the entity. This is vertical rotation (rotation around the horizontal axis),
	// and is 0 when the entity faces forward.
	Pitch() float64
	// State returns a list of entity states which the entity is currently subject to. Generally, these states
	// alter the way the entity looks.
	State() []state.State

	Velocity() mgl64.Vec3
	SetVelocity(v mgl64.Vec3)

	// Name returns a human readable name for the entity. This is not unique for an entity, but generally
	// unique for an entity type.
	Name() string

	// EncodeEntity converts the entity to its encoded representation: It returns the type of the Minecraft
	// entity, for example 'minecraft:falling_block'.
	EncodeEntity() string

Entity represents an entity in the world, typically an object that may be moved around and can be interacted with by other entities. Viewers of a world may view an entity when near it.

type Face

type Face int

Face represents the face of a block or entity.

const (
	// FaceDown represents the bottom face of a block.
	FaceDown Face = iota
	// FaceUp represents the top face of a block.
	// FaceNorth represents the north face of a block.
	// FaceSouth represents the south face of a block.
	// FaceWest represents the west face of the block.
	// FaceEast represents the east face of the block.

func AllFaces

func AllFaces() []Face

AllFaces returns a list of all of the current faces allowed inside of the world (up, down, north, east, south, west)

func (Face) Axis

func (f Face) Axis() Axis

Axis returns the axis the face is facing. FaceEast and west correspond to the x axis, north and south to the z axis and up and down to the y axis.

func (Face) Direction

func (f Face) Direction() Direction

Direction converts the Face to a Direction and returns it, assuming the Face is horizontal and not FaceUp or FaceDown.

func (Face) FromString

func (f Face) FromString(s string) (interface{}, error)

FromString returns a Face by a string.

func (Face) Opposite

func (f Face) Opposite() Face

Opposite returns the opposite face. FaceDown will return up, north will return south and west will return east, and vice versa.

type Generator

type Generator interface {
	// GenerateChunk generates a chunk at a chunk position passed. The generator sets blocks in the chunk that
	// is passed to the method.
	GenerateChunk(pos ChunkPos, chunk *chunk.Chunk)

Generator handles the generating of newly created chunks. Worlds have one generator which is used to generate chunks when the provider of the world cannot find a chunk at a given chunk position.

type Handler

type Handler interface {
	// HandleLiquidFlow handles the flowing of a liquid from one block position from into another block
	// position into. The liquid that will replace the block replaced is also passed.
	HandleLiquidFlow(ctx *event.Context, from, into BlockPos, liquid, replaced Block)
	// HandleLiquidHarden handles the hardening of a liquid at hardenedPos. The liquid that was hardened,
	// liquidHardened, and the liquid that caused it to harden, otherLiquid, are passed. The block created
	// as a result is also passed.
	HandleLiquidHarden(ctx *event.Context, hardenedPos BlockPos, liquidHardened, otherLiquid, newBlock Block)

Handler handles events that are called by a world. Implementations of Handler may be used to listen to specific events such as when an entity is added to the world.

type Item

type Item interface {
	// EncodeItem encodes the item to its Minecraft representation, which consists of a numerical ID and a
	// metadata value.
	EncodeItem() (id int32, meta int16)

Item represents an item that may be added to an inventory. It has a method to encode the item to an ID and a metadata value.

type ItemEntry

type ItemEntry struct {
	ID   int32
	Meta int16

ItemEntry holds the ID and Meta for an item translation.

type Liquid

type Liquid interface {
	// LiquidDepth returns the current depth of the liquid.
	LiquidDepth() int
	// SpreadDecay returns the amount of depth that is subtracted from the liquid's depth when it spreads to
	// a next block.
	SpreadDecay() int
	// WithDepth returns the liquid with the depth passed.
	WithDepth(depth int, falling bool) Liquid
	// LiquidFalling checks if the liquid is currently considered falling down.
	LiquidFalling() bool
	// LiquidType returns a string unique for the liquid, used to check if two liquids are considered to be
	// of the same type.
	LiquidType() string
	// Harden checks if the block should harden when looking at the surrounding blocks and sets the position
	// to the hardened block when adequate. If the block was hardened, the method returns true.
	Harden(pos BlockPos, w *World, flownIntoBy *BlockPos) bool

Liquid represents a block that can be moved through and which can flow in the world after placement. There are two liquids in vanilla, which are lava and water.

type LiquidDisplacer

type LiquidDisplacer interface {
	// CanDisplace specifies if the block is able to displace the liquid passed.
	CanDisplace(b Liquid) bool
	// SideClosed checks if a position on the side of the block placed in the world at a specific position is
	// closed. When this returns true (for example, when the side is below the position and the block is a
	// slab), liquid inside of the displacer won't flow from pos into side.
	SideClosed(pos, side BlockPos, w *World) bool

LiquidDisplacer represents a block that is able to displace a liquid to a different world layer, without fully removing the liquid.

type Loader

type Loader struct {
	// contains filtered or unexported fields

Loader implements the loading of the world. A loader can typically be moved around the world to load different parts of the world. An example usage is the player, which uses a loader to load chunks around it so that it can view them.

func NewLoader

func NewLoader(chunkRadius int, world *World, v Viewer) *Loader

NewLoader creates a new loader using the chunk radius passed. Chunks beyond this radius from the position of the loader will never be loaded. The Viewer passed will handle the loading of chunks, including the viewing of entities that were loaded in those chunks.

func (*Loader) ChangeRadius

func (l *Loader) ChangeRadius(new int)

ChangeRadius changes the maximum chunk radius of the Loader.

func (*Loader) ChangeWorld

func (l *Loader) ChangeWorld(new *World)

ChangeWorld changes the World of the Loader. The currently loaded chunks are reset and any future loading is done from the new World.

func (*Loader) Close

func (l *Loader) Close() error

Close closes the loader. It unloads all chunks currently loaded for the viewer, and hides all entities that are currently shown to it.

func (*Loader) Load

func (l *Loader) Load(n int) error

Load loads n chunks around the centre of the chunk, starting with the middle and working outwards. For every chunk loaded, the function f is called. The function f must not hold the chunk beyond the function scope. An error is returned if one of the chunks could not be loaded.

func (*Loader) Move

func (l *Loader) Move(pos mgl64.Vec3)

Move moves the loader to the position passed. The position is translated to a chunk position to load

func (*Loader) World

func (l *Loader) World() *World

World returns the World that the Loader is in.

type NBTer

type NBTer interface {
	// DecodeNBT returns the item or block, depending on which of those the NBTer was, with the NBT data
	// decoded into it.
	DecodeNBT(data map[string]interface{}) interface{}
	EncodeNBT() map[string]interface{}

NBTer represents either an item or a block which may decode NBT data and encode to NBT data. Typically this is done to store additional data.

type NeighbourUpdateTicker

type NeighbourUpdateTicker interface {
	// NeighbourUpdateTick handles a neighbouring block being updated. The position of that block and the
	// position of this block is passed.
	NeighbourUpdateTick(pos, changedNeighbour BlockPos, w *World)

NeighbourUpdateTicker represents a block that is updated when a block adjacent to it is updated, either through placement or being broken.

type NoIOProvider

type NoIOProvider struct{}

NoIOProvider implements a Provider while not performing any disk I/O. It generates values on the run and dynamically, instead of reading and writing data, and returns otherwise empty values.

func (NoIOProvider) Close

func (NoIOProvider) Close() error

Close ...

func (NoIOProvider) LoadBlockNBT

func (NoIOProvider) LoadBlockNBT(ChunkPos) ([]map[string]interface{}, error)

LoadBlockNBT ...

func (NoIOProvider) LoadChunk

func (NoIOProvider) LoadChunk(ChunkPos) (*chunk.Chunk, bool, error)

LoadChunk ...

func (NoIOProvider) LoadDefaultGameMode

func (NoIOProvider) LoadDefaultGameMode() gamemode.GameMode

LoadDefaultGameMode ...

func (NoIOProvider) LoadDifficulty

func (NoIOProvider) LoadDifficulty() difficulty.Difficulty

LoadDifficulty ...

func (NoIOProvider) LoadEntities

func (NoIOProvider) LoadEntities(ChunkPos) ([]Entity, error)

LoadEntities ...

func (NoIOProvider) LoadTime

func (NoIOProvider) LoadTime() int64

LoadTime ...

func (NoIOProvider) LoadTimeCycle

func (NoIOProvider) LoadTimeCycle() bool

LoadTimeCycle ...

func (NoIOProvider) SaveBlockNBT

func (NoIOProvider) SaveBlockNBT(ChunkPos, []map[string]interface{}) error

SaveBlockNBT ...

func (NoIOProvider) SaveChunk

func (NoIOProvider) SaveChunk(ChunkPos, *chunk.Chunk) error

SaveChunk ...

func (NoIOProvider) SaveDefaultGameMode

func (NoIOProvider) SaveDefaultGameMode(gamemode.GameMode)

SaveDefaultGameMode ...

func (NoIOProvider) SaveDifficulty

func (NoIOProvider) SaveDifficulty(difficulty.Difficulty)

SaveDifficulty ...

func (NoIOProvider) SaveEntities

func (NoIOProvider) SaveEntities(ChunkPos, []Entity) error

SaveEntities ...

func (NoIOProvider) SaveTime

func (NoIOProvider) SaveTime(int64)

SaveTime ...

func (NoIOProvider) SaveTimeCycle

func (NoIOProvider) SaveTimeCycle(bool)

SaveTimeCycle ...

func (NoIOProvider) SetWorldName

func (NoIOProvider) SetWorldName(string)

SetWorldName ...

func (NoIOProvider) SetWorldSpawn

func (NoIOProvider) SetWorldSpawn(BlockPos)

SetWorldSpawn ...

func (NoIOProvider) WorldName

func (NoIOProvider) WorldName() string

WorldName ...

func (NoIOProvider) WorldSpawn

func (NoIOProvider) WorldSpawn() BlockPos

WorldSpawn ...

type NopGenerator

type NopGenerator struct{}

NopGenerator is the default generator a world. It places no blocks in the world which results in a void world.

func (NopGenerator) GenerateChunk

func (NopGenerator) GenerateChunk(ChunkPos, *chunk.Chunk)

GenerateChunk ...

type NopHandler

type NopHandler struct{}

NopHandler implements the Handler interface but does not execute any code when an event is called. The default Handler of worlds is set to NopHandler. Users may embed NopHandler to avoid having to implement each method.

func (NopHandler) HandleLiquidFlow

func (NopHandler) HandleLiquidFlow(*event.Context, BlockPos, BlockPos, Block, Block)

HandleLiquidFlow ...

func (NopHandler) HandleLiquidHarden

func (NopHandler) HandleLiquidHarden(*event.Context, BlockPos, Block, Block, Block)

HandleLiquidHarden ...

type Particle

type Particle interface {
	// Spawn spawns the particle at the position passed. Particles may execute any additional actions here,
	// such as spawning different particles.
	Spawn(w *World, pos mgl64.Vec3)

Particle represents a particle that may be added to the world. These particles are then rendered client- side, with the server having no control over it after sending.

type Provider

type Provider interface {
	// WorldName returns the name of the world that the provider provides for. When setting the provider of a
	// World, the World will replace its current name with this one.
	WorldName() string
	// SetWorldName sets the name of the world to a new name.
	SetWorldName(name string)
	// WorldSpawn returns the spawn position of the world. Although players may spawn at different positions,
	// every new player spawns at this position.
	WorldSpawn() BlockPos
	// SetWorldSpawn sets the spawn of a world to a new position.
	SetWorldSpawn(pos BlockPos)
	// LoadChunk attempts to load a chunk from the chunk position passed. If successful, a non-nil chunk is
	// returned and exists is true and err nil. If no chunk was saved at the chunk position passed, the chunk
	// returned is nil, and so is the error. If the chunk did exist, but if the data was invalid, nil is
	// returned for the chunk and true, with a non-nil error.
	// If exists ends up false, the chunk at the position is instead newly generated by the world.
	LoadChunk(position ChunkPos) (c *chunk.Chunk, exists bool, err error)
	// SaveChunk saves a chunk at a specific position in the provider. If writing was not successful, an error
	// is returned.
	SaveChunk(position ChunkPos, c *chunk.Chunk) error
	// LoadEntities loads all entities stored at a particular chunk position. If the entities cannot be read,
	// LoadEntities returns a non-nil error.
	LoadEntities(position ChunkPos) ([]Entity, error)
	// SaveEntities saves a list of entities in a chunk position. If writing is not successful, an error is
	// returned.
	SaveEntities(position ChunkPos, entities []Entity) error
	// LoadBlockNBT loads the block NBT, also known as block entities, at a specific chunk position. If the
	// NBT cannot be read, LoadBlockNBT returns a non-nil error.
	LoadBlockNBT(position ChunkPos) ([]map[string]interface{}, error)
	// SaveBlockNBT saves block NBT, or block entities, to a specific chunk position. If the NBT cannot be
	// stored, SaveBlockNBT returns a non-nil error.
	SaveBlockNBT(position ChunkPos, data []map[string]interface{}) error
	// LoadTime loads the time of the world.
	LoadTime() int64
	// SaveTime saves the time of the world.
	SaveTime(time int64)
	// SaveTimeCycle saves the state of the time cycle: Either stopped or started. If true is passed, the time
	// is running. If false, the time is stopped.
	SaveTimeCycle(running bool)
	// LoadTimeCycle loads the state of the time cycle: If time is running, true is returned. If the time
	// cycle is stopped, false is returned.
	LoadTimeCycle() bool
	// LoadDefaultGameMode loads the default game mode of the world.
	LoadDefaultGameMode() gamemode.GameMode
	// SaveDefaultGameMode sets the default game mode of the world.
	SaveDefaultGameMode(mode gamemode.GameMode)
	// LoadDifficulty loads the difficulty of a world.
	LoadDifficulty() difficulty.Difficulty
	// SaveDifficulty saves the difficulty of a world.
	SaveDifficulty(d difficulty.Difficulty)

Provider represents a value that may provide world data to a World value. It usually does the reading and writing of the world data so that the World may use it.

type RandomTicker

type RandomTicker interface {
	// RandomTick handles a random tick of the block at the position passed. Additionally, a rand.Rand
	// instance is passed which may be used to generate values randomly without locking.
	RandomTick(pos BlockPos, w *World, r *rand.Rand)

RandomTicker represents a block that executes an action when it is ticked randomly. Every 20th of a second, one random block in each sub chunk are picked to receive a random tick.

type ScheduledTicker

type ScheduledTicker interface {
	// ScheduledTick handles a scheduled tick initiated by an event in one of the neighbouring blocks, such as
	// when a block is placed or broken.
	ScheduledTick(pos BlockPos, w *World)

ScheduledTicker represents a block that executes an action when it has a block update scheduled, such as when a block adjacent to it is broken.

type Sound

type Sound interface {
	// Play plays the sound. This function may play other sounds too. It is always called when World.PlaySound
	// is called with the sound.
	Play(w *World, pos mgl64.Vec3)

Sound represents a sound that may be added to the world. When done, viewers of the world may be able to hear the sound.

type Structure

type Structure interface {
	// Dimensions returns the dimensions of the structure. It returns an int array with the width, height and
	// length respectively.
	Dimensions() [3]int
	// At returns the block at a specific location in the structure. When the structure is placed in the
	// world, this method is called for every location within the dimensions of the structure.
	// At may return nil to not place any block at the position. Returning Air will set any block at that
	// position to air, but returning nil will not do anything.
	// In addition to the coordinates, At will have a function passed that may be used to get a block at a
	// specific position. In scope of At(), structures should use this over World.Block(), due to the way
	// chunks are locked.
	At(x, y, z int, blockAt func(x, y, z int) Block) Block
	// AdditionalLiquidAt returns additional liquid blocks at a specific location in the structure. Most
	// structures will not need to properly implement this method, but structures may implement it to provide
	// waterlogged blocks when needed.
	// Structures that do not need this should return nil.
	AdditionalLiquidAt(x, y, z int) Liquid

Structure represents a structure which may be placed in the world. It has fixed dimensions.

type TickerBlock

type TickerBlock interface {
	Tick(currentTick int64, pos BlockPos, w *World)

TickerBlock is an implementation of NBTer with an additional Tick method that is called on every world tick for loaded blocks that implement this interface.

type TickerEntity

type TickerEntity interface {
	// Tick ticks the entity with the current tick passed.
	Tick(current int64)

TickerEntity represents an entity that has a Tick method which should be called every time the entity is ticked every 20th of a second.

type Viewer

type Viewer interface {
	// Position returns the position of the viewer.
	Position() mgl64.Vec3
	// ViewEntity views the entity passed. It is called for every entity that the viewer may encounter in the
	// world, either by moving entities or by moving the viewer using a world.Loader.
	ViewEntity(e Entity)
	// HideEntity stops viewing the entity passed. It is called for every entity that leaves the viewing range
	// of the viewer, either by its movement or the movement of the viewer using a world.Loader.
	HideEntity(e Entity)
	// ViewEntityMovement views the movement of an entity. The entity is moved with a delta position, yaw and
	// pitch, which, when applied to values of the entity, will result in the final values.
	ViewEntityMovement(e Entity, deltaPos mgl64.Vec3, deltaYaw, deltaPitch float64)
	// ViewEntityVelocity views the velocity of an entity. It is called right before a call to
	// ViewEntityMovement so that the Viewer may interpolate the movement itself.
	ViewEntityVelocity(e Entity, velocity mgl64.Vec3)
	// ViewEntityTeleport views the teleportation of an entity. The entity is immediately moved to a different
	// target position.
	ViewEntityTeleport(e Entity, position mgl64.Vec3)
	// ViewChunk views the chunk passed at a particular position. It is called for every chunk loaded using
	// the world.Loader.
	ViewChunk(pos ChunkPos, c *chunk.Chunk, blockNBT map[BlockPos]Block)
	// ViewTime views the time of the world. It is called every time the time is changed or otherwise every
	// second.
	ViewTime(time int)
	// ViewEntityItems views the items currently held by an entity that is able to equip items.
	ViewEntityItems(e Entity)
	// ViewEntityArmour views the items currently equipped as armour by the entity.
	ViewEntityArmour(e Entity)
	// ViewEntityAction views an action performed by an entity. Available actions may be found in the `action`
	// package, and include things such as swinging an arm.
	ViewEntityAction(e Entity, a action.Action)
	// ViewEntityState views the current state of an entity. It is called whenever an entity changes its
	// physical appearance, for example when sprinting.
	ViewEntityState(e Entity, s []state.State)
	// ViewParticle views a particle spawned at a given position in the world. It is called when a particle,
	// for example a block breaking particle, is spawned near the player.
	ViewParticle(pos mgl64.Vec3, p Particle)
	// ViewSound is called when a sound is played in the world.
	ViewSound(pos mgl64.Vec3, s Sound)
	// ViewBlockUpdate views the updating of a block. It is called when a block is set at the position passed
	// to the method.
	ViewBlockUpdate(pos BlockPos, b Block, layer int)
	// ViewBlockAction views an action performed by a block. Available actions may be found in the `action`
	// package, and include things such as a chest opening.
	ViewBlockAction(pos BlockPos, a blockAction.Action)
	// ViewEmote views an emote being performed by another entity.
	ViewEmote(player Entity, emote uuid.UUID)

Viewer is a viewer in the world. It can view changes that are made in the world, such as the addition of entities and the changes of blocks.

type World

type World struct {
	// contains filtered or unexported fields

World implements a Minecraft world. It manages all aspects of what players can see, such as blocks, entities and particles. World generally provides a synchronised state: All entities, blocks and players usually operate in this world, so World ensures that all its methods will always be safe for simultaneous calls. A nil *World is safe to use but not functional.

func New

func New(log *logrus.Logger, simulationDistance int) *World

New creates a new initialised world. The world may be used right away, but it will not be saved or loaded from files until it has been given a different provider than the default. (NoIOProvider) By default, the name of the world will be 'World'.

func OfEntity

func OfEntity(e Entity) (*World, bool)

OfEntity attempts to return a world that an entity is currently in. If the entity was not currently added to a world, the world returned is nil and the bool returned is false.

func (*World) AddEntity

func (w *World) AddEntity(e Entity)

AddEntity adds an entity to the world at the position that the entity has. The entity will be visible to all viewers of the world that have the chunk of the entity loaded. If the chunk that the entity is in is not yet loaded, it will first be loaded. If the entity passed to AddEntity is currently in a world, it is first removed from that world.

func (*World) AddParticle

func (w *World) AddParticle(pos mgl64.Vec3, p Particle)

AddParticle spawns a particle at a given position in the world. Viewers that are viewing the chunk will be shown the particle.

func (*World) Block

func (w *World) Block(pos BlockPos) Block

Block reads a block from the position passed. If a chunk is not yet loaded at that position, the chunk is loaded, or generated if it could not be found in the world save, and the block returned. Chunks will be loaded synchronously.

func (*World) BreakBlock

func (w *World) BreakBlock(pos BlockPos)

BreakBlock breaks a block at the position passed. Unlike when setting the block at that position to air, BreakBlock will also show particles and update blocks around the position.

func (*World) BreakBlockWithoutParticles

func (w *World) BreakBlockWithoutParticles(pos BlockPos)

BreakBlockWithoutParticles breaks a block at the position passed. Unlike when setting the block at that position to air, BreakBlockWithoutParticles will also update blocks around the position.

func (*World) BuildStructure

func (w *World) BuildStructure(pos BlockPos, s Structure)

BuildStructure builds a Structure passed at a specific position in the world. Unlike SetBlock, it takes a Structure implementation, which provides blocks to be placed at a specific location. BuildStructure is specifically tinkered to be able to process a large batch of chunks simultaneously and will do so within much less time than separate SetBlock calls would. The method operates on a per-chunk basis, setting all blocks within a single chunk part of the structure before moving on to the next chunk.

func (*World) Close

func (w *World) Close() error

Close closes the world and saves all chunks currently loaded.

func (*World) CloseChunkCacheJanitor

func (w *World) CloseChunkCacheJanitor()

CloseChunkCacheJanitor closes the chunk cache janitor of the world. Calling this method will prevent chunks from unloading until the World is closed, preventing entities from despawning. As a result, this could lead to a memory leak if the size of the world can grow. This method should therefore only be used in places where the movement of players is limited to a confined space such as a hub.

func (*World) DefaultGameMode

func (w *World) DefaultGameMode() gamemode.GameMode

DefaultGameMode returns the default game mode of the world. When players join, they are given this game mode. The default game mode may be changed using SetDefaultGameMode().

func (*World) Difficulty

func (w *World) Difficulty() difficulty.Difficulty

Difficulty returns the difficulty of the world. Properties of mobs in the world and the player's hunger will depend on this difficulty.

func (*World) Entities

func (w *World) Entities() []Entity

Entities returns a list of all entities currently added to the World.

func (*World) EntitiesWithin

func (w *World) EntitiesWithin(aabb physics.AABB) []Entity

EntitiesWithin does a lookup through the entities in the chunks touched by the AABB passed, returning all those which are contained within the AABB when it comes to their position.

func (*World) Generator

func (w *World) Generator(g Generator)

Generator changes the generator of the world to the one passed. If nil is passed, the generator is set to the default, NopGenerator.

func (*World) Handle

func (w *World) Handle(h Handler)

Handle changes the current Handler of the world. As a result, events called by the world will call handlers of the Handler passed. Handle sets the world's Handler to NopHandler if nil is passed.

func (*World) Handler

func (w *World) Handler() Handler

Handler returns the Handler of the world. It should always be used, rather than direct field access, in order to provide synchronisation safety.

func (*World) HighestBlock

func (w *World) HighestBlock(x, z int) int

HighestBlock looks up the highest non-air block in the world at a specific x and z in the world. The y value of the highest block is returned, or 0 if no blocks were present in the column.

func (*World) Light

func (w *World) Light(pos BlockPos) uint8

Light returns the light level at the position passed. This is the highest of the sky and block light. The light value returned is a value in the range 0-15, where 0 means there is no light present, whereas 15 means the block is fully lit.

func (*World) Liquid

func (w *World) Liquid(pos BlockPos) (Liquid, bool)

Liquid attempts to return any liquid block at the position passed. This liquid may be in the foreground or in any other layer. If found, the liquid is returned. If not, the bool returned is false and the liquid is nil.

func (*World) Name

func (w *World) Name() string

Name returns the display name of the world. Generally, this name is displayed at the top of the player list in the pause screen in-game. If a provider is set, the name will be updated according to the name that it provides.

func (*World) PlaceBlock

func (w *World) PlaceBlock(pos BlockPos, b Block)

PlaceBlock places a block at the position passed. Unlike when using SetBlock, PlaceBlock also schedules block updates around the position. If the block can displace liquids at the position placed, it will do so, and liquid source blocks will be put into the same block as the one passed.

func (*World) PlaySound

func (w *World) PlaySound(pos mgl64.Vec3, s Sound)

PlaySound plays a sound at a specific position in the world. Viewers of that position will be able to hear the sound if they're close enough.

func (*World) Provider

func (w *World) Provider(p Provider)

Provider changes the provider of the world to the provider passed. If nil is passed, the NoIOProvider will be set, which does not read or write any data.

func (*World) ReadOnly

func (w *World) ReadOnly()

ReadOnly makes the world read only. Chunks will no longer be saved to disk, just like entities and data in the level.dat.

func (*World) RemoveEntity

func (w *World) RemoveEntity(e Entity)

RemoveEntity removes an entity from the world that is currently present in it. Any viewers of the entity will no longer be able to see it. RemoveEntity operates assuming the position of the entity is the same as where it is currently in the world. If it can not find it there, it will loop through all entities and try to find it. RemoveEntity assumes the entity is currently loaded and in a loaded chunk. If not, the function will not do anything.

func (*World) ScheduleBlockUpdate

func (w *World) ScheduleBlockUpdate(pos BlockPos, delay time.Duration)

ScheduleBlockUpdate schedules a block update at the position passed after a specific delay. If the block at that position does not handle block updates, nothing will happen.

func (*World) SetBlock

func (w *World) SetBlock(pos BlockPos, b Block)

SetBlock writes a block to the position passed. If a chunk is not yet loaded at that position, the chunk is first loaded or generated if it could not be found in the world save. SetBlock panics if the block passed has not yet been registered using RegisterBlock(). Nil may be passed as the block to set the block to air. SetBlock should be avoided in situations where performance is critical when needing to set a lot of blocks to the world. BuildStructure may be used instead.

func (*World) SetDefaultGameMode

func (w *World) SetDefaultGameMode(mode gamemode.GameMode)

SetDefaultGameMode changes the default game mode of the world. When players join, they are then given that game mode.

func (*World) SetDifficulty

func (w *World) SetDifficulty(d difficulty.Difficulty)

SetDifficulty changes the difficulty of a world.

func (*World) SetLiquid

func (w *World) SetLiquid(pos BlockPos, b Liquid)

SetLiquid sets the liquid at a specific position in the world. Unlike SetBlock, SetLiquid will not overwrite any existing blocks. It will instead be in the same position as a block currently there, unless there already is a liquid at that position, in which case it will be overwritten. If nil is passed for the liquid, any liquid currently present will be removed.

func (*World) SetRandomTickSpeed

func (w *World) SetRandomTickSpeed(v int)

SetRandomTickSpeed sets the random tick speed of blocks. By default, each sub chunk has 3 blocks randomly ticked per sub chunk, so the default value is 3. Setting this value to 0 will stop random ticking altogether, while setting it higher results in faster ticking.

func (*World) SetSpawn

func (w *World) SetSpawn(pos BlockPos)

SetSpawn sets the spawn of the world to a different position. The player will be spawned in the center of this position when newly joining.

func (*World) SetTime

func (w *World) SetTime(new int)

SetTime sets the new time of the world. SetTime will always work, regardless of whether the time is stopped or not.

func (*World) SkyLight

func (w *World) SkyLight(pos BlockPos) uint8

SkyLight returns the sky light level at the position passed. This light level is not influenced by blocks that emit light, such as torches or glowstone. The light value, similarly to Light, is a value in the range 0-15, where 0 means no light is present.

func (*World) Spawn

func (w *World) Spawn() BlockPos

Spawn returns the spawn of the world. Every new player will by default spawn on this position in the world when joining.

func (*World) StartTime

func (w *World) StartTime()

StartTime restarts the time in the world. When called, the time will start cycling again and the day/night cycle will continue. The time may be stopped again by calling World.StopTime(). StartTime will not do anything if the time is already started.

func (*World) StopTime

func (w *World) StopTime()

StopTime stops the time in the world. When called, the time will no longer cycle and the world will remain at the time when StopTime is called. The time may be restarted by calling World.StartTime(). StopTime will not do anything if the time is already stopped.

func (*World) Time

func (w *World) Time() int

Time returns the current time of the world. The time is incremented every 1/20th of a second, unless World.StopTime() is called.

func (*World) Viewers

func (w *World) Viewers(pos mgl64.Vec3) []Viewer

Viewers returns a list of all viewers viewing the position passed. A viewer will be assumed to be watching if the position is within one of the chunks that the viewer is watching.


Path Synopsis

Jump to

Keyboard shortcuts

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