world

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 25 Imported by: 238

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockRuntimeID

func BlockRuntimeID(b Block) (uint32, bool)

BlockRuntimeID attempts to return a runtime ID of a block 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 ItemRuntimeID

func ItemRuntimeID(i Item) (rid int32, meta int16, ok bool)

ItemRuntimeID attempts to return the runtime ID of the Item passed. False is returned if the Item is not registered.

func RegisterBlock

func RegisterBlock(b Block)

RegisterBlock registers the Block passed. The EncodeBlock method will be used to encode and decode the block passed. RegisterBlock panics if the block properties returned were not valid, existing properties.

func RegisterItem

func RegisterItem(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.

Types

type Block

type Block interface {
	// EncodeBlock encodes the block to a string ID such as 'minecraft:grass' and properties associated
	// with the block.
	EncodeBlock() (string, map[string]interface{})
	// Hash returns a unique identifier of the block including the block states. This function is used internally to
	// convert a block to a single integer which can be used in map lookups. The hash produced therefore does not need
	// to match anything in the game, but it must be unique among all registered blocks.
	// The tool in `/cmd/blockhash` may be used to automatically generate block hashes of blocks in a package.
	Hash() uint64
	// 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.

func BlockByName

func BlockByName(name string, properties map[string]interface{}) (Block, bool)

BlockByName attempts to return a Block by its name and properties. If not found, the bool returned is false.

func BlockByRuntimeID

func BlockByRuntimeID(rid uint32) (Block, bool)

BlockByRuntimeID attempts to return a Block by its runtime ID. If not found, the bool returned is false. If found, the block is non-nil and the bool true.

type BlockModel

type BlockModel interface {
	// AABB returns the bounding boxes that a block with this model can be collided with.
	AABB(pos cube.Pos, 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 cube.Pos, face cube.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 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) 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 Difficulty

type Difficulty interface {
	// FoodRegenerates specifies if players' food levels should automatically regenerate with this difficulty.
	FoodRegenerates() bool
	// StarvationHealthLimit specifies the amount of health at which a player will no longer receive damage from
	// starvation.
	StarvationHealthLimit() float64
	// FireSpreadIncrease returns a number that increases the rate at which fire spreads.
	FireSpreadIncrease() int
}

Difficulty represents the difficulty of a Minecraft world. The difficulty of a world influences all kinds of aspects of the world, such as the damage enemies deal to players, the way hunger depletes, whether hostile monsters spawn or not and more.

type DifficultyEasy

type DifficultyEasy struct{}

DifficultyEasy difficulty has mobs deal less damage to players than normal and starvation won't occur if a player has less than 5 hearts of health.

func (DifficultyEasy) FireSpreadIncrease

func (DifficultyEasy) FireSpreadIncrease() int

FireSpreadIncrease ...

func (DifficultyEasy) FoodRegenerates

func (DifficultyEasy) FoodRegenerates() bool

FoodRegenerates ...

func (DifficultyEasy) StarvationHealthLimit

func (DifficultyEasy) StarvationHealthLimit() float64

StarvationHealthLimit ...

type DifficultyHard

type DifficultyHard struct{}

DifficultyHard difficulty has mobs that deal above average damage to players. Starvation will kill players with too little food and monsters will get additional effects.

func (DifficultyHard) FireSpreadIncrease

func (DifficultyHard) FireSpreadIncrease() int

FireSpreadIncrease ...

func (DifficultyHard) FoodRegenerates

func (DifficultyHard) FoodRegenerates() bool

FoodRegenerates ...

func (DifficultyHard) StarvationHealthLimit

func (DifficultyHard) StarvationHealthLimit() float64

StarvationHealthLimit ...

type DifficultyNormal

type DifficultyNormal struct{}

DifficultyNormal difficulty has mobs that deal normal damage to players. Starvation will occur until the player is down to a single heart.

func (DifficultyNormal) FireSpreadIncrease

func (DifficultyNormal) FireSpreadIncrease() int

FireSpreadIncrease ...

func (DifficultyNormal) FoodRegenerates

func (DifficultyNormal) FoodRegenerates() bool

FoodRegenerates ...

func (DifficultyNormal) StarvationHealthLimit

func (DifficultyNormal) StarvationHealthLimit() float64

StarvationHealthLimit ...

type DifficultyPeaceful

type DifficultyPeaceful struct{}

DifficultyPeaceful difficulty prevents most hostile mobs from spawning and makes players rapidly regenerate health and food.

func (DifficultyPeaceful) FireSpreadIncrease

func (DifficultyPeaceful) FireSpreadIncrease() int

FireSpreadIncrease ...

func (DifficultyPeaceful) FoodRegenerates

func (DifficultyPeaceful) FoodRegenerates() bool

FoodRegenerates ...

func (DifficultyPeaceful) StarvationHealthLimit

func (DifficultyPeaceful) StarvationHealthLimit() float64

StarvationHealthLimit ...

type Entity

type Entity interface {
	io.Closer
	// 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
	// Rotation returns the yaw and pitch of the entity in degrees. Yaw is horizontal rotation (rotation around the
	// vertical axis, 0 when facing forward), pitch is vertical rotation (rotation around the horizontal axis, also 0
	// when facing forward).
	Rotation() (yaw, 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 GameMode

type GameMode interface {
	// AllowsEditing specifies if a player with this GameMode can edit the World it's in.
	AllowsEditing() bool
	// AllowsTakingDamage specifies if a player with this GameMode can take damage from other entities.
	AllowsTakingDamage() bool
	// CreativeInventory specifies if a player with this GameMode has access to the creative inventory.
	CreativeInventory() bool
}

GameMode represents a game mode that may be assigned to a player. Upon joining the world, players will be given the default game mode that the world holds. Game modes specify the way that a player interacts with and plays in the world.

type GameModeAdventure

type GameModeAdventure struct{}

GameModeAdventure represents the adventure game mode: Players with this game mode cannot edit the world (placing or breaking blocks).

func (GameModeAdventure) AllowsEditing

func (GameModeAdventure) AllowsEditing() bool

AllowsEditing ...

func (GameModeAdventure) AllowsTakingDamage

func (GameModeAdventure) AllowsTakingDamage() bool

AllowsTakingDamage ...

func (GameModeAdventure) CreativeInventory

func (GameModeAdventure) CreativeInventory() bool

CreativeInventory ...

type GameModeCreative

type GameModeCreative struct{}

GameModeCreative represents the creative game mode: Players with this game mode have infinite blocks and items and can break blocks instantly. Players with creative mode can also fly.

func (GameModeCreative) AllowsEditing

func (GameModeCreative) AllowsEditing() bool

AllowsEditing ...

func (GameModeCreative) AllowsTakingDamage

func (GameModeCreative) AllowsTakingDamage() bool

AllowsTakingDamage ...

func (GameModeCreative) CreativeInventory

func (GameModeCreative) CreativeInventory() bool

CreativeInventory ...

type GameModeSpectator

type GameModeSpectator struct{}

GameModeSpectator represents the spectator game mode: Players with this game mode cannot interact with the world and cannot be seen by other players. GameModeSpectator players can fly, like creative mode, and can move through blocks.

func (GameModeSpectator) AllowsEditing

func (GameModeSpectator) AllowsEditing() bool

AllowsEditing ...

func (GameModeSpectator) AllowsTakingDamage

func (GameModeSpectator) AllowsTakingDamage() bool

AllowsTakingDamage ...

func (GameModeSpectator) CreativeInventory

func (GameModeSpectator) CreativeInventory() bool

CreativeInventory ...

type GameModeSurvival

type GameModeSurvival struct{}

GameModeSurvival represents the survival game mode: Players with this game mode have limited supplies and can break blocks using only the right tools.

func (GameModeSurvival) AllowsEditing

func (GameModeSurvival) AllowsEditing() bool

AllowsEditing ...

func (GameModeSurvival) AllowsTakingDamage

func (GameModeSurvival) AllowsTakingDamage() bool

AllowsTakingDamage ...

func (GameModeSurvival) CreativeInventory

func (GameModeSurvival) CreativeInventory() bool

CreativeInventory ...

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 cube.Pos, 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 cube.Pos, 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() (name string, 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.

func ItemByName

func ItemByName(name string, meta int16) (Item, bool)

ItemByName attempts to return an item by a name and a metadata value.

func ItemByRuntimeID

func ItemByRuntimeID(rid int32, meta int16) (Item, bool)

ItemByRuntimeID attempts to return an Item by the runtime ID passed. If no item with that runtime ID exists, false is returned. ItemByRuntimeID also tries to find the item with a metadata value of 0.

func Items

func Items() []Item

Items returns a slice of all registered items.

type Liquid

type Liquid interface {
	Block
	// 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 an int 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 cube.Pos, w *World, flownIntoBy *cube.Pos) 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 cube.Pos, 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 cube.Pos, 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) LoadEntities

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

LoadEntities ...

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) SaveEntities

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

SaveEntities ...

func (NoIOProvider) SaveSettings added in v0.1.0

func (NoIOProvider) SaveSettings(Settings)

SaveSettings ...

func (NoIOProvider) Settings added in v0.1.0

func (NoIOProvider) Settings() Settings

Settings ...

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, cube.Pos, cube.Pos, Block, Block)

HandleLiquidFlow ...

func (NopHandler) HandleLiquidHarden

func (NopHandler) HandleLiquidHarden(*event.Context, cube.Pos, 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 {
	io.Closer
	// Settings returns the settings for a World.
	Settings() Settings
	// SaveSettings saves the settings of a World.
	SaveSettings(Settings)

	// 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
}

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 cube.Pos, 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. Additionally, a rand.Rand instance is passed which may be used to
	// generate values randomly without locking.
	ScheduledTick(pos cube.Pos, w *World, r *rand.Rand)
}

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 Settings added in v0.1.0

type Settings struct {
	// Name is the display name of the World.
	Name string
	// Spawn is the spawn position of the World. New players that join the world will be spawned here.
	Spawn cube.Pos
	// Time is the current time of the World. It advances every tick if TimeCycle is set to true.
	Time int64
	// TimeCycle specifies if the time should advance every tick. If set to false, time won't change.
	TimeCycle bool
	// CurrentTick is the current tick of the world. This is similar to the Time, except that it has no visible effect
	// to the client. It can also not be changed through commands and will only ever go up.
	CurrentTick int64
	// DefaultGameMode is the GameMode assigned to players that join the World for the first time.
	DefaultGameMode GameMode
	// Difficulty is the difficulty of the World. Behaviour of hunger, regeneration and monsters differs based on the
	// difficulty of the world.
	Difficulty Difficulty
}

Settings holds the settings of a World. These are typically saved to a level.dat file.

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. Additionally,
	// At may return a Liquid to be placed in the same place as the block.
	// 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, Liquid)
}

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

type TickerBlock

type TickerBlock interface {
	NBTer
	Tick(currentTick int64, pos cube.Pos, 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[cube.Pos]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 cube.Pos, 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 cube.Pos, a blockAction.Action)
	// ViewEmote views an emote being performed by another entity.
	ViewEmote(player Entity, emote uuid.UUID)
	// ViewSkin views the current skin of a player.
	ViewSkin(e Entity)
	// ViewWorldSpawn views the current spawn location of the world.
	ViewWorldSpawn(pos cube.Pos)
}

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 internal.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 cube.Pos) 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 cube.Pos)

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 cube.Pos)

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 cube.Pos, 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

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 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) HighestLightBlocker

func (w *World) HighestLightBlocker(x, z int) int16

HighestLightBlocker gets the Y value of the highest fully light blocking block at the x and z values passed in the world.

func (*World) Light

func (w *World) Light(pos cube.Pos) 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 cube.Pos) (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 cube.Pos, 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 cube.Pos, 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 cube.Pos, 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)

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)

SetDifficulty changes the difficulty of a world.

func (*World) SetLiquid

func (w *World) SetLiquid(pos cube.Pos, 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 cube.Pos)

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 cube.Pos) 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() cube.Pos

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) (viewers []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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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