Documentation ¶
Index ¶
- Variables
- func BlockRuntimeID(b Block) (uint32, bool)
- func Distance(a, b mgl64.Vec3) float64
- func ItemRuntimeID(i Item) (rid int32, meta int16, ok bool)
- func RegisterBiome(b Biome)
- func RegisterBlock(b Block)
- func RegisterEntity(e SaveableEntity)
- func RegisterItem(item Item)
- type Biome
- type Block
- type BlockAction
- type BlockModel
- type ChunkPos
- type Difficulty
- type Dimension
- type Entity
- type EntityAction
- type GameMode
- type Generator
- type Handler
- type Item
- type Liquid
- type LiquidDisplacer
- type Loader
- type NBTer
- type NeighbourUpdateTicker
- type NoIOProvider
- func (NoIOProvider) Close() error
- func (NoIOProvider) LoadBlockNBT(ChunkPos) ([]map[string]interface{}, error)
- func (NoIOProvider) LoadChunk(ChunkPos) (*chunk.Chunk, bool, error)
- func (NoIOProvider) LoadEntities(ChunkPos) ([]SaveableEntity, error)
- func (NoIOProvider) SaveBlockNBT(ChunkPos, []map[string]interface{}) error
- func (NoIOProvider) SaveChunk(ChunkPos, *chunk.Chunk) error
- func (NoIOProvider) SaveEntities(ChunkPos, []SaveableEntity) error
- func (NoIOProvider) SaveSettings(*Settings)
- func (NoIOProvider) Settings(*Settings)
- type NopGenerator
- type NopHandler
- type NopViewer
- func (NopViewer) HideEntity(Entity)
- func (NopViewer) Position() mgl64.Vec3
- func (NopViewer) ViewBlockAction(cube.Pos, BlockAction)
- func (NopViewer) ViewBlockUpdate(cube.Pos, Block, int)
- func (NopViewer) ViewChunk(ChunkPos, *chunk.Chunk, map[cube.Pos]Block)
- func (NopViewer) ViewEmote(Entity, uuid.UUID)
- func (NopViewer) ViewEntity(Entity)
- func (NopViewer) ViewEntityAction(Entity, EntityAction)
- func (NopViewer) ViewEntityArmour(Entity)
- func (NopViewer) ViewEntityItems(Entity)
- func (NopViewer) ViewEntityMovement(Entity, mgl64.Vec3, float64, float64, bool)
- func (NopViewer) ViewEntityState(Entity)
- func (NopViewer) ViewEntityTeleport(Entity, mgl64.Vec3)
- func (NopViewer) ViewEntityVelocity(Entity, mgl64.Vec3)
- func (NopViewer) ViewParticle(mgl64.Vec3, Particle)
- func (NopViewer) ViewSkin(Entity)
- func (NopViewer) ViewSound(mgl64.Vec3, Sound)
- func (NopViewer) ViewTime(int)
- func (NopViewer) ViewWeather(bool, bool)
- func (NopViewer) ViewWorldSpawn(cube.Pos)
- type Particle
- type Provider
- type RandomTicker
- type SaveableEntity
- type ScheduledTicker
- type Settings
- type Sound
- type Structure
- type TickerBlock
- type TickerEntity
- type Viewer
- type World
- func (w *World) AddEntity(e Entity)
- func (w *World) AddParticle(pos mgl64.Vec3, p Particle)
- func (w *World) Biome(pos cube.Pos) Biome
- func (w *World) Block(pos cube.Pos) Block
- func (w *World) BreakBlock(pos cube.Pos)
- func (w *World) BreakBlockWithoutParticles(pos cube.Pos)
- func (w *World) BuildStructure(pos cube.Pos, s Structure)
- func (w *World) Close() error
- func (w *World) DefaultGameMode() GameMode
- func (w *World) Difficulty() Difficulty
- func (w *World) Dimension() Dimension
- func (w *World) Entities() []Entity
- func (w *World) EntitiesWithin(aabb physics.AABB, ignored func(Entity) bool) []Entity
- func (w *World) Generator(g Generator)
- func (w *World) Handle(h Handler)
- func (w *World) Handler() Handler
- func (w *World) HighestBlock(x, z int) int
- func (w *World) HighestLightBlocker(x, z int) int
- func (w *World) Light(pos cube.Pos) uint8
- func (w *World) Liquid(pos cube.Pos) (Liquid, bool)
- func (w *World) Name() string
- func (w *World) PlaceBlock(pos cube.Pos, b Block)
- func (w *World) PlaySound(pos mgl64.Vec3, s Sound)
- func (w *World) PortalDestinations() (nether, end *World)
- func (w *World) Provider(p Provider)
- func (w *World) RainingAt(pos cube.Pos) bool
- func (w *World) Range() cube.Range
- func (w *World) ReadOnly()
- func (w *World) RemoveEntity(e Entity)
- func (w *World) ScheduleBlockUpdate(pos cube.Pos, delay time.Duration)
- func (w *World) SetBiome(pos cube.Pos, b Biome)
- func (w *World) SetBlock(pos cube.Pos, b Block)
- func (w *World) SetDefaultGameMode(mode GameMode)
- func (w *World) SetDifficulty(d Difficulty)
- func (w *World) SetLiquid(pos cube.Pos, b Liquid)
- func (w *World) SetPortalDestinations(nether, end *World)
- func (w *World) SetRandomTickSpeed(v int)
- func (w *World) SetSpawn(pos cube.Pos)
- func (w *World) SetTickRange(v int)
- func (w *World) SetTime(new int)
- func (w *World) SkyLight(pos cube.Pos) uint8
- func (w *World) SnowingAt(pos cube.Pos) bool
- func (w *World) Spawn() cube.Pos
- func (w *World) StartRaining(dur time.Duration)
- func (w *World) StartThundering(dur time.Duration)
- func (w *World) StartTime()
- func (w *World) StartWeatherCycle()
- func (w *World) StopRaining()
- func (w *World) StopThundering()
- func (w *World) StopTime()
- func (w *World) StopWeatherCycle()
- func (w *World) Temperature(pos cube.Pos) float64
- func (w *World) ThunderingAt(pos cube.Pos) bool
- func (w *World) Time() int
- func (w *World) Viewers(pos mgl64.Vec3) (viewers []Viewer)
Constants ¶
This section is empty.
Variables ¶
var ( // DifficultyPeaceful prevents most hostile mobs from spawning and makes players rapidly regenerate health and food. DifficultyPeaceful difficultyPeaceful // DifficultyEasy has mobs that deal less damage to players than normal and starvation won't occur if a player has // less than 5 hearts of health. DifficultyEasy difficultyEasy // DifficultyNormal has mobs that deal normal damage to players. Starvation will occur until the player is down to // a single heart. DifficultyNormal difficultyNormal // DifficultyHard has mobs that deal above average damage to players. Starvation will kill players with too little // food and monsters will get additional effects. DifficultyHard difficultyHard )
var ( // Overworld is the Dimension implementation of a normal overworld. It has a blue sky under normal circumstances and // has a sun, clouds, stars and a moon. Overworld has a building range of [-64, 320]. Overworld overworld // Nether is a Dimension implementation with a lower base light level and a darker sky without sun/moon. It has a // building range of [0, 256]. Nether nether // End is a Dimension implementation with a dark sky. It has a building range of [0, 256]. End end )
var ( // GameModeSurvival is the survival game mode: Players with this game mode have limited supplies and can break blocks // after taking some time. GameModeSurvival survival // 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. GameModeCreative creative // GameModeAdventure represents the adventure game mode: Players with this game mode cannot edit the world // (placing or breaking blocks). GameModeAdventure adventure // GameModeSpectator represents the spectator game mode: Players with this game mode cannot interact with the // world and cannot be seen by other players. spectator players can fly, like creative mode, and can // move through blocks. GameModeSpectator spectator )
Functions ¶
func BlockRuntimeID ¶
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 ItemRuntimeID ¶
ItemRuntimeID attempts to return the runtime ID of the Item passed. False is returned if the Item is not registered.
func RegisterBiome ¶
func RegisterBiome(b Biome)
RegisterBiome registers a biome to the map so that it can be saved and loaded with the world.
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 RegisterEntity ¶
func RegisterEntity(e SaveableEntity)
RegisterEntity registers a SaveableEntity to the map so that it can be saved and loaded with the world.
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 Biome ¶
type Biome interface { // Temperature returns the temperature of the biome. Temperature() float64 // Rainfall returns the rainfall of the biome. Rainfall() float64 // String returns the biome name as a string. String() string // EncodeBiome encodes the biome into an int value that is used to identify the biome over the network. EncodeBiome() int }
Biome is a region in a world with distinct geographical features, flora, temperatures, humidity ratings, and sky, water, grass and foliage colors.
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 ¶
BlockByName attempts to return a Block by its name and properties. If not found, the bool returned is false.
func BlockByRuntimeID ¶
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 BlockAction ¶
type BlockAction interface {
BlockAction()
}
BlockAction represents an action that may be performed by a block. Typically, these actions are sent to viewers in a world so that they can see these actions.
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 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 from 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.
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 Dimension ¶
type Dimension interface { Range() cube.Range EncodeDimension() int WaterEvaporates() bool LavaSpreadDuration() time.Duration WeatherCycle() bool TimeCycle() bool }
Dimension is a dimension of a World. It influences a variety of properties of a World such as the building range, the sky colour and the behaviour of liquid blocks.
type Entity ¶
type Entity interface { io.Closer // 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 // AABB returns the AABB of the entity. AABB() physics.AABB // Position returns the current position of the entity in the world. Position() mgl64.Vec3 // 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) // World returns the current world of the entity. This is always the world that the entity can actually be // found in. World() *World }
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 EntityAction ¶
type EntityAction interface {
EntityAction()
}
EntityAction represents an action that may be performed by an entity. Typically, these actions are sent to viewers in a world so that they can see these actions.
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 // HasCollision specifies if a player with this GameMode can collide with blocks or entities in the world. HasCollision() bool // AllowsFlying specifies if a player with this GameMode can fly freely. AllowsFlying() bool // AllowsInteraction specifies if a player with this GameMode can interact with the world through entities or if it // can use items in the world. AllowsInteraction() bool // Visible specifies if a player with this GameMode can be visible to other players. If false, the player will be // invisible under any circumstance. Visible() 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 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) // HandleSound handles a Sound being played in the World at a specific position. ctx.Cancel() may be called // to stop the Sound from playing to viewers of the position. HandleSound(ctx *event.Context, s Sound, pos mgl64.Vec3) }
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 ¶
ItemByName attempts to return an item by a name and a metadata value.
func ItemByRuntimeID ¶
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.
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 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 ¶
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 ¶
ChangeRadius changes the maximum chunk radius of the Loader.
func (*Loader) ChangeWorld ¶
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 ¶
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 ¶
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.
type NBTer ¶
type NBTer interface { // DecodeNBT returns the (new) item, block or entity, depending on which of those the NBTer was, with the NBT data // decoded into it. DecodeNBT(data map[string]interface{}) interface{} // EncodeNBT encodes the entity into a map which can then be encoded as NBT to be written. 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) LoadBlockNBT ¶
func (NoIOProvider) LoadBlockNBT(ChunkPos) ([]map[string]interface{}, error)
LoadBlockNBT ...
func (NoIOProvider) LoadEntities ¶
func (NoIOProvider) LoadEntities(ChunkPos) ([]SaveableEntity, 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, []SaveableEntity) error
SaveEntities ...
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 ¶
HandleLiquidFlow ...
func (NopHandler) HandleLiquidHarden ¶
HandleLiquidHarden ...
func (NopHandler) HandleSound ¶
HandleSound ...
type NopViewer ¶
type NopViewer struct{}
NopViewer is a Viewer implementation that does not implement any behaviour. It may be embedded by other structs to prevent having to implement all of Viewer's methods.
func (NopViewer) HideEntity ¶
func (NopViewer) Position ¶
Position returns an empty mgl64.Vec3. We can do this because this position is only used for checking if a chunk should have random block ticking, which is generally not desirable with a NopViewer anyway.
func (NopViewer) ViewBlockAction ¶
func (NopViewer) ViewBlockAction(cube.Pos, BlockAction)
func (NopViewer) ViewEntity ¶
func (NopViewer) ViewEntityAction ¶
func (NopViewer) ViewEntityAction(Entity, EntityAction)
func (NopViewer) ViewEntityArmour ¶
func (NopViewer) ViewEntityItems ¶
func (NopViewer) ViewEntityMovement ¶
func (NopViewer) ViewEntityState ¶
func (NopViewer) ViewWeather ¶
func (NopViewer) ViewWorldSpawn ¶
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 loads the settings for a World and writes them to s. Settings(s *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) ([]SaveableEntity, error) // SaveEntities saves a list of entities in a chunk position. If writing is not successful, an error is // returned. SaveEntities(position ChunkPos, entities []SaveableEntity) 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 SaveableEntity ¶
SaveableEntity is an Entity that can be saved and loaded with the World it was added to. These entities can be registered on startup using RegisterEntity to allow loading them in a World.
func EntityByName ¶
func EntityByName(name string) (SaveableEntity, bool)
EntityByName looks up a SaveableEntity by the name (for example, 'minecraft:slime') and returns it if found. EntityByName can only return entities previously registered using RegisterEntity. If not found, the bool returned is false.
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 ¶
type Settings struct { sync.Mutex // 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 // RainTime is the current rain time of the World. It advances every tick if WeatherCycle is set to true. RainTime int64 // Raining is the current rain level of the World. Raining bool // ThunderTime is the current thunder time of the World. It advances every tick if WeatherCycle is set to true. ThunderTime int64 // Thunder is the current thunder level of the World. Thundering bool // WeatherCycle specifies if weather should be enabled in this world. If set to false, weather will be disabled. WeatherCycle 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 // TickRange is the radius in chunks around a Viewer that has its blocks and entities ticked when the world is // ticked. If set to 0, blocks and entities will never be ticked. TickRange int32 // contains filtered or unexported fields }
Settings holds the settings of a World. These are typically saved to a level.dat file. It is safe to pass the same Settings to multiple worlds created using New, in which case the Settings are synchronised between the worlds.
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 can return a Liquid to be placed in the same place as the block. // At can 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 ¶
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 World and tick passed. Tick(w *World, 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 the respective values of the entity, will result in the final values. ViewEntityMovement(e Entity, pos mgl64.Vec3, yaw, pitch float64, onGround bool) // 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 EntityAction) // 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) // 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) // 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) // ViewWeather views the weather of the world, including rain and thunder. ViewWeather(raining, thunder bool) }
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 ¶
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'. The Settings passed specify the initial settings of the World created. These Settings are changed as soon as Provider is called, at which point they will be replaced with the Settings as created by the Provider passed. If nil is passed as Settings, default settings are used.
func OfEntity ¶
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 ¶
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 ¶
AddParticle spawns a particle at a given position in the world. Viewers that are viewing the chunk will be shown the particle.
func (*World) Biome ¶
Biome reads the biome at 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 biome returned. Chunks will be loaded synchronously.
func (*World) 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 ¶
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 ¶
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 ¶
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) DefaultGameMode ¶
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) Dimension ¶
Dimension returns the Dimension assigned to the World in world.New. The sky colour and behaviour of a variety of world features differ based on the Dimension assigned to a World.
func (*World) EntitiesWithin ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) PortalDestinations ¶
PortalDestinations returns the destination worlds for nether and end portals respectively. Upon entering portals in this World, entities are moved to the respective destination worlds.
func (*World) 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) RainingAt ¶
RainingAt returns a bool that indicates whether it is raining at a position in the world. RainingAt returns false if it is snowing at a position, rather than raining.
func (*World) Range ¶
Range returns the range in blocks of the World (min and max). It is equivalent to calling World.Dimension().Range().
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 ¶
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 ¶
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) SetBiome ¶
SetBiome sets the biome at 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.
func (*World) SetBlock ¶
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 ¶
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 ¶
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) SetPortalDestinations ¶
SetPortalDestinations sets the destination worlds for any nether and end portals in the World respectively. In order for either portals to work, SetPortalDestinations must first be called. Nil may be passed as destination to prevent the respective portal from transporting entities in it.
func (*World) SetRandomTickSpeed ¶
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 ¶
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) SetTickRange ¶
SetTickRange sets the range in chunks around each Viewer that will have the chunks (their blocks and entities) ticked when the World is ticked.
func (*World) SetTime ¶
SetTime sets the new time of the world. SetTime will always work, regardless of whether the time is stopped or not.
func (*World) SkyLight ¶
SkyLight returns the skylight 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) SnowingAt ¶
SnowingAt returns a bool that indicates whether it is snowing at a position in the world.
func (*World) Spawn ¶
Spawn returns the spawn of the world. Every new player will by default spawn on this position in the world when joining.
func (*World) StartRaining ¶
StartRaining makes it rain in the current world where the time.Duration passed will determine how long it will rain.
func (*World) StartThundering ¶
StartThundering makes it thunder in the current world where the time.Duration passed will determine how long it will thunder. StartThundering will also make it rain.
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) StartWeatherCycle ¶
func (w *World) StartWeatherCycle()
StartWeatherCycle enables weather of the World.
func (*World) StopRaining ¶
func (w *World) StopRaining()
StopRaining makes it stop raining in the current world.
func (*World) StopThundering ¶
func (w *World) StopThundering()
StopThundering makes it stop thundering in the current world.
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) StopWeatherCycle ¶
func (w *World) StopWeatherCycle()
StopWeatherCycle disables weather of the World.
func (*World) Temperature ¶
Temperature returns the temperature in the World at a specific position. Higher altitudes and different biomes influence the temperature returned.
func (*World) ThunderingAt ¶
ThunderingAt returns a bool indicating whether it is currently thundering or not. True is returned only if it is both raining and thundering at the same time and if the position passed is exposed to rain.