world

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeSleep         = 12542
	TimeWake          = 23459
	TimeSleepWithRain = 12010
	TimeWakeWithRain  = 23991
	TimeFull          = 24000
)

Variables

View Source
var (
	DifficultyPeaceful difficultyPeaceful

	DifficultyEasy difficultyEasy

	DifficultyNormal difficultyNormal

	DifficultyHard difficultyHard
)
View Source
var (
	Overworld overworld

	Nether nether

	End end
)
View Source
var (
	GameModeSurvival survival

	GameModeCreative creative

	GameModeAdventure adventure

	GameModeSpectator spectator
)
View Source
var (
	ErrWorldClosed = errors.New("world: world closed")

	ErrEntityClosed = errors.New("world: entity closed")

	ErrEntityNotInWorld = errors.New("world: entity not in this world")

	ErrTaskCancelled = errors.New("world: scheduled task cancelled")

	ErrTaskPanicked = errors.New("world: scheduled task panicked")

	ErrEntityType = errors.New("world: unexpected entity type")
)
View Source
var DefaultBlockRegistry = &BasicBlockRegistry{
	blockProperties: make(map[string]map[string]any),
	stateRuntimeIDs: make(map[stateHash]uint32),
	customBlocks:    make(map[string]CustomBlock),
}

Functions

func BiomeDefinitions

func BiomeDefinitions() ([]protocol.BiomeDefinition, []string)

func BlockHash

func BlockHash(b Block) uint64

func BlockRuntimeID

func BlockRuntimeID(b Block) uint32

func Call

func Call[T any](ctx context.Context, w *World, f func(tx *Tx) (T, error)) (T, error)

func CallEntity

func CallEntity[T any](ctx context.Context, h *EntityHandle, f func(tx *Tx, e Entity) (T, error)) (T, error)

func CallRef

func CallRef[T any, E Entity](ctx context.Context, ref EntityRef[E], f func(tx *Tx, e E) (T, error)) (T, error)

func ClampRedstonePower

func ClampRedstonePower(power int) int

func CustomBlocks

func CustomBlocks() map[string]CustomBlock

func DifficultyID

func DifficultyID(diff Difficulty) (int, bool)

func DimensionID

func DimensionID(dim Dimension) (int, bool)

func GameModeID

func GameModeID(mode GameMode) (int, bool)

func ItemRuntimeID

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

func RedstoneFullPowerConductor

func RedstoneFullPowerConductor(pos cube.Pos, b Block, tx *Tx) bool

func RegisterBiome

func RegisterBiome(b Biome)

func RegisterBlock

func RegisterBlock(b Block)

func RegisterItem

func RegisterItem(item Item)

func RegisterSpawnEggHandler

func RegisterSpawnEggHandler(name string, handler SpawnEggHandler)

Types

type ArrowSpawnConfig

type ArrowSpawnConfig struct {
	Damage float64

	Owner Entity

	Critical bool

	DisablePickup bool

	ObtainArrowOnPickup bool

	PunchLevel int

	PiercingLevel int

	Tip any
}

type BasicBlockRegistry

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

func (*BasicBlockRegistry) Air

func (br *BasicBlockRegistry) Air() Block

func (*BasicBlockRegistry) AirRuntimeID

func (br *BasicBlockRegistry) AirRuntimeID() uint32

func (*BasicBlockRegistry) BitSize

func (br *BasicBlockRegistry) BitSize() int

func (*BasicBlockRegistry) BlockByName

func (br *BasicBlockRegistry) BlockByName(name string, properties map[string]any) (Block, bool)

func (*BasicBlockRegistry) BlockByRuntimeID

func (br *BasicBlockRegistry) BlockByRuntimeID(rid uint32) (Block, bool)

func (*BasicBlockRegistry) BlockByRuntimeIDOrAir

func (br *BasicBlockRegistry) BlockByRuntimeIDOrAir(rid uint32) Block

func (*BasicBlockRegistry) BlockCount

func (br *BasicBlockRegistry) BlockCount() int

func (*BasicBlockRegistry) BlockHash

func (br *BasicBlockRegistry) BlockHash(b Block) uint64

func (*BasicBlockRegistry) BlockRuntimeID

func (br *BasicBlockRegistry) BlockRuntimeID(b Block) uint32

func (*BasicBlockRegistry) Blocks

func (br *BasicBlockRegistry) Blocks() []Block

func (*BasicBlockRegistry) Clone

func (*BasicBlockRegistry) CustomBlocks

func (br *BasicBlockRegistry) CustomBlocks() map[string]CustomBlock

func (*BasicBlockRegistry) FilteringBlock

func (br *BasicBlockRegistry) FilteringBlock(rid uint32) uint8

func (*BasicBlockRegistry) Finalize

func (br *BasicBlockRegistry) Finalize()

func (*BasicBlockRegistry) HashToRuntimeID

func (br *BasicBlockRegistry) HashToRuntimeID(hash uint32) (rid uint32, ok bool)

func (*BasicBlockRegistry) LightBlock

func (br *BasicBlockRegistry) LightBlock(rid uint32) uint8

func (*BasicBlockRegistry) LiquidBlock

func (br *BasicBlockRegistry) LiquidBlock(rid uint32) bool

func (*BasicBlockRegistry) LiquidDisplacingBlock

func (br *BasicBlockRegistry) LiquidDisplacingBlock(rid uint32) bool

func (*BasicBlockRegistry) NBTBlock

func (br *BasicBlockRegistry) NBTBlock(rid uint32) bool

func (*BasicBlockRegistry) RandomTickBlock

func (br *BasicBlockRegistry) RandomTickBlock(rid uint32) bool

func (*BasicBlockRegistry) RegisterBlock

func (br *BasicBlockRegistry) RegisterBlock(b Block)

func (*BasicBlockRegistry) RegisterBlockState

func (br *BasicBlockRegistry) RegisterBlockState(s BlockState)

func (*BasicBlockRegistry) RuntimeIDToHash

func (br *BasicBlockRegistry) RuntimeIDToHash(runtimeID uint32) (hash uint32, ok bool)

func (*BasicBlockRegistry) RuntimeIDToState

func (br *BasicBlockRegistry) RuntimeIDToState(runtimeID uint32) (name string, properties map[string]any, found bool)

func (*BasicBlockRegistry) StateToRuntimeID

func (br *BasicBlockRegistry) StateToRuntimeID(name string, properties map[string]any) (runtimeID uint32, found bool)

type Biome

type Biome interface {
	Temperature() float64

	Rainfall() float64

	Depth() float64

	Scale() float64

	WaterColour() color.RGBA

	Tags() []string

	String() string

	EncodeBiome() int
}

func BiomeByID

func BiomeByID(id int) (Biome, bool)

func BiomeByName

func BiomeByName(name string) (Biome, bool)

func Biomes

func Biomes() []Biome

type Block

type Block interface {
	EncodeBlock() (string, map[string]any)

	Hash() (uint64, uint64)

	Model() BlockModel
}

func BlockByName

func BlockByName(name string, properties map[string]any) (Block, bool)

func BlockByRuntimeID

func BlockByRuntimeID(rid uint32) (Block, bool)

func Blocks

func Blocks() []Block

type BlockAction

type BlockAction interface {
	BlockAction()
}

type BlockModel

type BlockModel interface {
	BBox(pos cube.Pos, s BlockSource) []cube.BBox

	FaceSolid(pos cube.Pos, face cube.Face, s BlockSource) bool
}

type BlockRegistry

type BlockRegistry interface {
	chunk.BlockRegistry

	BlockByRuntimeID(rid uint32) (Block, bool)

	BlockByRuntimeIDOrAir(rid uint32) Block

	BlockRuntimeID(block Block) (rid uint32)

	RegisterBlock(block Block)

	RegisterBlockState(blockState BlockState)

	CustomBlocks() map[string]CustomBlock

	BlockByName(name string, properties map[string]any) (Block, bool)

	Blocks() []Block

	Air() Block

	Finalize()

	BitSize() int

	BlockHash(b Block) uint64

	RuntimeIDToHash(runtimeID uint32) (hash uint32, ok bool)
}

func NewBlockRegistry

func NewBlockRegistry() BlockRegistry

type BlockSource

type BlockSource interface {
	Block(cube.Pos) Block
}

type BlockState

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

type ChunkPos

type ChunkPos [2]int32

func (ChunkPos) String

func (p ChunkPos) String() string

func (ChunkPos) X

func (p ChunkPos) X() int32

func (ChunkPos) Z

func (p ChunkPos) Z() int32

type Column

type Column struct {
	*chunk.Chunk
	Entities      []*EntityHandle
	BlockEntities map[cube.Pos]Block
	// contains filtered or unexported fields
}

type Config

type Config struct {
	Log *slog.Logger

	Dim Dimension

	PortalDestination func(dim Dimension) *World

	Provider Provider

	Generator Generator

	ReadOnly bool

	SaveInterval time.Duration

	ChunkUnloadInterval time.Duration

	ChunkLoadWorkers int

	RandomTickSpeed int

	RandSource rand.Source

	Entities EntityRegistry

	Blocks BlockRegistry

	Synchronous bool
}

func (Config) New

func (conf Config) New() *World

type Context

type Context struct {
	*Tx
	// contains filtered or unexported fields
}

func (*Context) Cancel

func (ctx *Context) Cancel()

func (*Context) Cancelled

func (ctx *Context) Cancelled() bool

type CustomBlock

type CustomBlock interface {
	Block
	Properties() customblock.Properties
}

type CustomBlockBuildable

type CustomBlockBuildable interface {
	CustomBlock

	Name() string

	Geometry() []byte

	Textures() map[string]image.Image
}

type CustomItem

type CustomItem interface {
	Item

	Name() string

	Texture() image.Image

	Category() category.Category
}

func CustomItems

func CustomItems() []CustomItem

type DamageSource

type DamageSource interface {
	ReducedByArmour() bool

	ReducedByResistance() bool

	Fire() bool

	IgnoreTotem() bool
}

type Difficulty

type Difficulty interface {
	FoodRegenerates() bool

	StarvationHealthLimit() float64

	FireSpreadIncrease() int
}

func DifficultyByID

func DifficultyByID(id int) (Difficulty, bool)

type Dimension

type Dimension interface {
	Range() cube.Range
	WaterEvaporates() bool
	LavaSpreadDuration() time.Duration
	WeatherCycle() bool
	TimeCycle() bool
}

func DimensionByID

func DimensionByID(id int) (Dimension, bool)

type Entity

type Entity interface {
	io.Closer

	H() *EntityHandle

	Position() mgl64.Vec3

	Rotation() cube.Rotation
}

type EntityAction

type EntityAction interface {
	EntityAction()
}

type EntityAnimation

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

func NewEntityAnimation

func NewEntityAnimation(name string) EntityAnimation

func (EntityAnimation) Controller

func (a EntityAnimation) Controller() string

func (EntityAnimation) Name

func (a EntityAnimation) Name() string

func (EntityAnimation) NextState

func (a EntityAnimation) NextState() string

func (EntityAnimation) StopCondition

func (a EntityAnimation) StopCondition() string

func (EntityAnimation) WithController

func (a EntityAnimation) WithController(controller string) EntityAnimation

func (EntityAnimation) WithNextState

func (a EntityAnimation) WithNextState(state string) EntityAnimation

func (EntityAnimation) WithStopCondition

func (a EntityAnimation) WithStopCondition(condition string) EntityAnimation

type EntityConfig

type EntityConfig interface {
	Apply(data *EntityData)
}

type EntityData

type EntityData struct {
	Pos, Vel          mgl64.Vec3
	Rot               cube.Rotation
	Name              string
	AlwaysShowNameTag bool
	FireDuration      time.Duration
	Age               time.Duration

	Data any
}

type EntityHandle

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

func NewEntity

func NewEntity(t EntityType, conf EntityConfig) *EntityHandle

func (*EntityHandle) Close

func (e *EntityHandle) Close() error

func (*EntityHandle) Closed

func (e *EntityHandle) Closed() bool

func (*EntityHandle) Do

func (e *EntityHandle) Do(f func(tx *Tx, e Entity)) *Task

func (*EntityHandle) DoAfter

func (e *EntityHandle) DoAfter(delay time.Duration, f func(tx *Tx, e Entity)) *Task

func (*EntityHandle) Entity

func (e *EntityHandle) Entity(tx *Tx) (Entity, bool)

func (*EntityHandle) Type

func (e *EntityHandle) Type() EntityType

func (*EntityHandle) UUID

func (e *EntityHandle) UUID() uuid.UUID

type EntityRef

type EntityRef[T Entity] struct {
	// contains filtered or unexported fields
}

func NewEntityRef

func NewEntityRef[T Entity](h *EntityHandle) EntityRef[T]

func (EntityRef[T]) Do

func (r EntityRef[T]) Do(f func(tx *Tx, e T)) *Task

func (EntityRef[T]) DoAfter

func (r EntityRef[T]) DoAfter(delay time.Duration, f func(tx *Tx, e T)) *Task

func (EntityRef[T]) Handle

func (r EntityRef[T]) Handle() *EntityHandle

type EntityRegistry

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

func (EntityRegistry) Config

func (reg EntityRegistry) Config() EntityRegistryConfig

func (EntityRegistry) Lookup

func (reg EntityRegistry) Lookup(name string) (EntityType, bool)

func (EntityRegistry) Types

func (reg EntityRegistry) Types() []EntityType

type EntityRegistryConfig

type EntityRegistryConfig struct {
	Item               func(opts EntitySpawnOpts, it any) *EntityHandle
	FallingBlock       func(opts EntitySpawnOpts, bl Block) *EntityHandle
	TNT                func(opts EntitySpawnOpts, fuse time.Duration) *EntityHandle
	BottleOfEnchanting func(opts EntitySpawnOpts, owner Entity) *EntityHandle
	Arrow              func(opts EntitySpawnOpts, conf ArrowSpawnConfig) *EntityHandle
	Egg                func(opts EntitySpawnOpts, owner Entity) *EntityHandle
	EnderPearl         func(opts EntitySpawnOpts, owner Entity) *EntityHandle
	Firework           func(opts EntitySpawnOpts, firework Item, owner Entity, sidewaysVelocityMultiplier, upwardsAcceleration float64, attached bool) *EntityHandle
	LingeringPotion    func(opts EntitySpawnOpts, t any, owner Entity) *EntityHandle
	Snowball           func(opts EntitySpawnOpts, owner Entity) *EntityHandle
	SplashPotion       func(opts EntitySpawnOpts, t any, owner Entity) *EntityHandle
	Lightning          func(opts EntitySpawnOpts) *EntityHandle
}

func (EntityRegistryConfig) New

type EntitySpawnOpts

type EntitySpawnOpts struct {
	Position mgl64.Vec3

	Rotation cube.Rotation

	Velocity mgl64.Vec3

	ID uuid.UUID

	NameTag string
}

func (EntitySpawnOpts) New

type EntityType

type EntityType interface {
	Open(tx *Tx, handle *EntityHandle, data *EntityData) Entity

	EncodeEntity() string

	BBox(e Entity) cube.BBox

	DecodeNBT(m map[string]any, data *EntityData)

	EncodeNBT(data *EntityData) map[string]any
}

type GameMode

type GameMode interface {
	AllowsEditing() bool

	AllowsTakingDamage() bool

	CreativeInventory() bool

	HasCollision() bool

	AllowsFlying() bool

	AllowsInteraction() bool

	Visible() bool

	InstantPortalTravel() bool
}

func GameModeByID

func GameModeByID(id int) (GameMode, bool)

type Generator

type Generator interface {
	GenerateChunk(pos ChunkPos, chunk *chunk.Chunk)

	DefaultSpawn(dim Dimension) cube.Pos
}

type Handler

type Handler interface {
	HandleLiquidFlow(ctx *Context, from, into cube.Pos, liquid Liquid, replaced Block)

	HandleLiquidDecay(ctx *Context, pos cube.Pos, before, after Liquid)

	HandleLiquidHarden(ctx *Context, hardenedPos cube.Pos, liquidHardened, otherLiquid, newBlock Block)

	HandleSound(ctx *Context, s Sound, pos mgl64.Vec3)

	HandleFireSpread(ctx *Context, from, to cube.Pos)

	HandleBlockBurn(ctx *Context, pos cube.Pos)

	HandleCropTrample(ctx *Context, pos cube.Pos)

	HandleLeavesDecay(ctx *Context, pos cube.Pos)

	HandleEntitySpawn(tx *Tx, e Entity)

	HandleEntityDespawn(tx *Tx, e Entity)

	HandleExplosion(ctx *Context, position mgl64.Vec3, entities *[]Entity, blocks *[]cube.Pos, itemDropChance *float64, spawnFire *bool)

	HandleRedstoneUpdate(ctx *Context, update RedstoneUpdate)

	HandleClose(tx *Tx)
}

type HealingSource

type HealingSource interface {
	HealingSource()
}

type Item

type Item interface {
	EncodeItem() (name string, meta int16)
}

func ItemByName

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

func ItemByRuntimeID

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

func Items

func Items() []Item

type Liquid

type Liquid interface {
	Block

	LiquidDepth() int

	SpreadDecay() int

	WithDepth(depth int, falling bool) Liquid

	LiquidFalling() bool

	BlastResistance() float64

	LiquidType() string

	Harden(pos cube.Pos, tx *Tx, flownIntoBy *cube.Pos) bool

	LiquidRemoveBlock(pos cube.Pos, tx *Tx, removed Block)
}

type LiquidDisplacer

type LiquidDisplacer interface {
	CanDisplace(b Liquid) bool

	SideClosed(pos, side cube.Pos, tx *Tx) bool
}

type Loader

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

func NewLoader

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

func (*Loader) ChangeRadius

func (l *Loader) ChangeRadius(tx *Tx, new int)

func (*Loader) ChangeWorld

func (l *Loader) ChangeWorld(tx *Tx, new *World)

func (*Loader) Chunk

func (l *Loader) Chunk(pos ChunkPos) (*Column, bool)

func (*Loader) Close

func (l *Loader) Close(tx *Tx)

func (*Loader) Load

func (l *Loader) Load(tx *Tx, n int)

func (*Loader) Move

func (l *Loader) Move(tx *Tx, pos mgl64.Vec3)

func (*Loader) World

func (l *Loader) World() *World

type NBTer

type NBTer interface {
	DecodeNBT(data map[string]any) any

	EncodeNBT() map[string]any
}

type NeighbourUpdateTicker

type NeighbourUpdateTicker interface {
	NeighbourUpdateTick(pos, changedNeighbour cube.Pos, tx *Tx)
}

type NopGenerator

type NopGenerator struct{}

func (NopGenerator) DefaultSpawn

func (NopGenerator) DefaultSpawn(Dimension) cube.Pos

func (NopGenerator) GenerateChunk

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

type NopHandler

type NopHandler struct{}

func (NopHandler) HandleBlockBurn

func (NopHandler) HandleBlockBurn(*Context, cube.Pos)

func (NopHandler) HandleClose

func (NopHandler) HandleClose(*Tx)

func (NopHandler) HandleCropTrample

func (NopHandler) HandleCropTrample(*Context, cube.Pos)

func (NopHandler) HandleEntityDespawn

func (NopHandler) HandleEntityDespawn(*Tx, Entity)

func (NopHandler) HandleEntitySpawn

func (NopHandler) HandleEntitySpawn(*Tx, Entity)

func (NopHandler) HandleExplosion

func (NopHandler) HandleExplosion(*Context, mgl64.Vec3, *[]Entity, *[]cube.Pos, *float64, *bool)

func (NopHandler) HandleFireSpread

func (NopHandler) HandleFireSpread(*Context, cube.Pos, cube.Pos)

func (NopHandler) HandleLeavesDecay

func (NopHandler) HandleLeavesDecay(*Context, cube.Pos)

func (NopHandler) HandleLiquidDecay

func (NopHandler) HandleLiquidDecay(*Context, cube.Pos, Liquid, Liquid)

func (NopHandler) HandleLiquidFlow

func (NopHandler) HandleLiquidFlow(*Context, cube.Pos, cube.Pos, Liquid, Block)

func (NopHandler) HandleLiquidHarden

func (NopHandler) HandleLiquidHarden(*Context, cube.Pos, Block, Block, Block)

func (NopHandler) HandleRedstoneUpdate

func (NopHandler) HandleRedstoneUpdate(*Context, RedstoneUpdate)

func (NopHandler) HandleSound

func (NopHandler) HandleSound(*Context, Sound, mgl64.Vec3)

type NopProvider

type NopProvider struct {
	Set *Settings
}

func (NopProvider) Close

func (NopProvider) Close() error

func (NopProvider) LoadColumn

func (NopProvider) LoadColumn(ChunkPos, Dimension) (*chunk.Column, error)

func (NopProvider) LoadPlayerSpawnPosition

func (NopProvider) LoadPlayerSpawnPosition(uuid.UUID) (cube.Pos, bool, error)

func (NopProvider) SavePlayerSpawnPosition

func (NopProvider) SavePlayerSpawnPosition(uuid.UUID, cube.Pos) error

func (NopProvider) SaveSettings

func (NopProvider) SaveSettings(*Settings)

func (NopProvider) Settings

func (n NopProvider) Settings() *Settings

func (NopProvider) StoreColumn

func (NopProvider) StoreColumn(ChunkPos, Dimension, *chunk.Column) error

type NopViewer

type NopViewer struct{}

func (NopViewer) HideEntity

func (NopViewer) HideEntity(Entity)

func (NopViewer) ViewBlockAction

func (NopViewer) ViewBlockAction(cube.Pos, BlockAction)

func (NopViewer) ViewBlockUpdate

func (NopViewer) ViewBlockUpdate(cube.Pos, Block, int)

func (NopViewer) ViewBrewingUpdate

func (NopViewer) ViewBrewingUpdate(time.Duration, time.Duration, int32, int32, int32, int32)

func (NopViewer) ViewChunk

func (NopViewer) ViewChunk(ChunkPos, Dimension, map[cube.Pos]Block, *chunk.Chunk)

func (NopViewer) ViewEmote

func (NopViewer) ViewEmote(Entity, uuid.UUID)

func (NopViewer) ViewEntity

func (NopViewer) ViewEntity(Entity)

func (NopViewer) ViewEntityAction

func (NopViewer) ViewEntityAction(Entity, EntityAction)

func (NopViewer) ViewEntityAnimation

func (NopViewer) ViewEntityAnimation(Entity, EntityAnimation)

func (NopViewer) ViewEntityArmour

func (NopViewer) ViewEntityArmour(Entity)

func (NopViewer) ViewEntityDisplacement

func (NopViewer) ViewEntityDisplacement(Entity, mgl64.Vec3, cube.Rotation, bool)

func (NopViewer) ViewEntityGameMode

func (NopViewer) ViewEntityGameMode(Entity)

func (NopViewer) ViewEntityItems

func (NopViewer) ViewEntityItems(Entity)

func (NopViewer) ViewEntityMovement

func (NopViewer) ViewEntityMovement(Entity, mgl64.Vec3, cube.Rotation, bool)

func (NopViewer) ViewEntityState

func (NopViewer) ViewEntityState(Entity)

func (NopViewer) ViewEntityTeleport

func (NopViewer) ViewEntityTeleport(Entity, mgl64.Vec3)

func (NopViewer) ViewEntityVelocity

func (NopViewer) ViewEntityVelocity(Entity, mgl64.Vec3)

func (NopViewer) ViewEntityWake

func (NopViewer) ViewEntityWake(Entity)

func (NopViewer) ViewParticle

func (NopViewer) ViewParticle(mgl64.Vec3, Particle)

func (NopViewer) ViewSkin

func (NopViewer) ViewSkin(Entity)

func (NopViewer) ViewSound

func (NopViewer) ViewSound(mgl64.Vec3, Sound)

func (NopViewer) ViewTime

func (NopViewer) ViewTime(int)

func (NopViewer) ViewTimeCycle

func (NopViewer) ViewTimeCycle(bool)

func (NopViewer) ViewWeather

func (NopViewer) ViewWeather(bool, bool)

func (NopViewer) ViewWorldSpawn

func (NopViewer) ViewWorldSpawn(cube.Pos)

type PanicError

type PanicError struct {
	Value any

	Stack []byte
}

func (*PanicError) Error

func (e *PanicError) Error() string

func (*PanicError) Unwrap

func (e *PanicError) Unwrap() error

type Particle

type Particle interface {
	Spawn(w *World, pos mgl64.Vec3)
}

type Provider

type Provider interface {
	io.Closer

	Settings() *Settings

	SaveSettings(*Settings)

	LoadPlayerSpawnPosition(uuid uuid.UUID) (pos cube.Pos, exists bool, err error)

	SavePlayerSpawnPosition(uuid uuid.UUID, pos cube.Pos) error

	LoadColumn(pos ChunkPos, dim Dimension) (*chunk.Column, error)

	StoreColumn(pos ChunkPos, dim Dimension, col *chunk.Column) error
}

type RandomTicker

type RandomTicker interface {
	RandomTick(pos cube.Pos, tx *Tx, r *rand.Rand)
}

type RedstoneNonConductive

type RedstoneNonConductive interface {
	RedstoneNonConductive()
}

type RedstonePowerAction

type RedstonePowerAction interface {
	RedstonePowerAction(pos cube.Pos, tx *Tx, oldPower, newPower int)
}

type RedstonePowerConsumer

type RedstonePowerConsumer interface {
	RedstonePowerUpdate(pos cube.Pos, tx *Tx, power int) (after Block, changed bool)
}

type RedstonePowerContextAction

type RedstonePowerContextAction interface {
	RedstonePowerActionUpdate(pos cube.Pos, tx *Tx, update RedstoneUpdate)
}

type RedstonePowerPostUpdater

type RedstonePowerPostUpdater interface {
	RedstonePowerPostUpdate(pos cube.Pos, tx *Tx, before, after Block, oldPower, newPower int)
}

type RedstonePowerRelayer

type RedstonePowerRelayer interface {
	RedstoneSignalLoss(pos cube.Pos, tx *Tx) int
}

type RedstonePowerRelayerNeighbourer

type RedstonePowerRelayerNeighbourer interface {
	RedstoneRelayerNeighbours(pos cube.Pos, tx *Tx) []cube.Pos
}

type RedstonePowerSource

type RedstonePowerSource interface {
	RedstonePower(pos cube.Pos, tx *Tx, face cube.Face) int
}

type RedstoneStrongPowerSource

type RedstoneStrongPowerSource interface {
	RedstoneStrongPower(pos cube.Pos, tx *Tx, face cube.Face) int
}

type RedstoneTorchTransaction

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

func (RedstoneTorchTransaction) BurnoutStatus

func (t RedstoneTorchTransaction) BurnoutStatus() (burnedOut, recoverable bool)

func (RedstoneTorchTransaction) ClearBurnout

func (t RedstoneTorchTransaction) ClearBurnout()

func (RedstoneTorchTransaction) ConsumeSelfTriggered

func (t RedstoneTorchTransaction) ConsumeSelfTriggered() bool

func (RedstoneTorchTransaction) MarkSelfTriggered

func (t RedstoneTorchTransaction) MarkSelfTriggered()

func (RedstoneTorchTransaction) RecordTurnOff

func (t RedstoneTorchTransaction) RecordTurnOff() (burnsOut bool)

type RedstoneTransaction

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

func (RedstoneTransaction) ScheduleUpdate

func (r RedstoneTransaction) ScheduleUpdate(pos cube.Pos)

func (RedstoneTransaction) Torch

type RedstoneUpdate

type RedstoneUpdate struct {
	Pos cube.Pos

	ChangedNeighbour cube.Pos

	HasChangedNeighbour bool

	ChangedRedstoneRelevant bool

	Source cube.Pos

	HasSource bool

	Before Block

	After Block

	OldPower int

	NewPower int

	CurrentTick int64

	Cause RedstoneUpdateCause
}

type RedstoneUpdateCause

type RedstoneUpdateCause uint8
const (
	RedstoneUpdateCauseBlockUpdate RedstoneUpdateCause = iota

	RedstoneUpdateCauseScheduledTick

	RedstoneUpdateCauseCompilerRebuild
)

type RedstoneWeakBlockPowerer

type RedstoneWeakBlockPowerer interface {
	RedstoneWeaklyPowersBlocks() bool
}

type ScheduledTicker

type ScheduledTicker interface {
	ScheduledTick(pos cube.Pos, tx *Tx, r *rand.Rand)
}

type SetOpts

type SetOpts struct {
	DisableBlockUpdates bool

	DisableLiquidDisplacement bool

	DisableRedstoneUpdates bool
}

type Settings

type Settings struct {
	sync.Mutex

	Name string

	Spawn cube.Pos

	Time int64

	TimeCycle bool

	RainTime int64

	Raining bool

	ThunderTime int64

	Thundering bool

	WeatherCycle bool

	RequiredSleepTicks int64

	CurrentTick int64

	DefaultGameMode GameMode

	Difficulty Difficulty

	TickRange int32
	// contains filtered or unexported fields
}

type Sleeper

type Sleeper interface {
	Entity

	Name() string
	UUID() uuid.UUID

	Messaget(t chat.Translation, a ...any)
	SendSleepingIndicator(sleeping, max int)

	Sleep(pos cube.Pos)
	Sleeping() (cube.Pos, bool)
	Wake()
}

type Sound

type Sound interface {
	Play(w *World, pos mgl64.Vec3)
}

type SpawnEggHandler

type SpawnEggHandler func(tx *Tx, pos cube.Pos) bool

func SpawnEggHandlerByName

func SpawnEggHandlerByName(name string) (SpawnEggHandler, bool)

type Structure

type Structure interface {
	Dimensions() [3]int

	At(x, y, z int, blockAt func(x, y, z int) Block) (Block, Liquid)
}

type SubChunkPos

type SubChunkPos [3]int32

func (SubChunkPos) String

func (p SubChunkPos) String() string

func (SubChunkPos) X

func (p SubChunkPos) X() int32

func (SubChunkPos) Y

func (p SubChunkPos) Y() int32

func (SubChunkPos) Z

func (p SubChunkPos) Z() int32

type Task

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

func NewFinishedTask

func NewFinishedTask(err error) *Task

func (*Task) Cancel

func (t *Task) Cancel() bool

func (*Task) Done

func (t *Task) Done() <-chan struct{}

func (*Task) Err

func (t *Task) Err() error

func (*Task) OnDone

func (t *Task) OnDone(f func(err error))

func (*Task) Wait

func (t *Task) Wait(ctx context.Context) error

type TickerBlock

type TickerBlock interface {
	NBTer
	Tick(currentTick int64, pos cube.Pos, tx *Tx)
}

type TickerEntity

type TickerEntity interface {
	Entity

	Tick(tx *Tx, current int64)
}

type Tx

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

func (*Tx) AddEntity

func (tx *Tx) AddEntity(e *EntityHandle) Entity

func (*Tx) AddEntityAt

func (tx *Tx) AddEntityAt(e *EntityHandle, pos mgl64.Vec3) Entity

func (*Tx) AddParticle

func (tx *Tx) AddParticle(pos mgl64.Vec3, p Particle)

func (*Tx) Biome

func (tx *Tx) Biome(pos cube.Pos) Biome

func (*Tx) Block

func (tx *Tx) Block(pos cube.Pos) Block

func (*Tx) BlockLoaded

func (tx *Tx) BlockLoaded(pos cube.Pos) (Block, bool)

func (*Tx) BlocksWithin

func (tx *Tx) BlocksWithin(pos cube.Pos, radius int, blocks ...Block) iter.Seq[cube.Pos]

func (*Tx) BroadcastSleepingIndicator

func (tx *Tx) BroadcastSleepingIndicator()

func (*Tx) BroadcastSleepingReminder

func (tx *Tx) BroadcastSleepingReminder(sleeper Sleeper)

func (*Tx) BuildStructure

func (tx *Tx) BuildStructure(pos cube.Pos, s Structure)

func (*Tx) CurrentTick

func (tx *Tx) CurrentTick() int64

func (*Tx) Defer

func (tx *Tx) Defer(f func(tx *Tx)) *Task

func (*Tx) DeferErr

func (tx *Tx) DeferErr(f func(tx *Tx) error) *Task

func (*Tx) Entities

func (tx *Tx) Entities() iter.Seq[Entity]

func (*Tx) EntitiesWithin

func (tx *Tx) EntitiesWithin(box cube.BBox) iter.Seq[Entity]

func (*Tx) Event

func (tx *Tx) Event() *Context

func (*Tx) HighestBlock

func (tx *Tx) HighestBlock(x, z int) int

func (*Tx) HighestLightBlocker

func (tx *Tx) HighestLightBlocker(x, z int) int

func (*Tx) Light

func (tx *Tx) Light(pos cube.Pos) uint8

func (*Tx) Liquid

func (tx *Tx) Liquid(pos cube.Pos) (Liquid, bool)

func (*Tx) PlayEntityAnimation

func (tx *Tx) PlayEntityAnimation(e Entity, a EntityAnimation)

func (*Tx) PlaySound

func (tx *Tx) PlaySound(pos mgl64.Vec3, s Sound)

func (*Tx) Players

func (tx *Tx) Players() iter.Seq[Entity]

func (*Tx) Raining

func (tx *Tx) Raining() bool

func (*Tx) RainingAt

func (tx *Tx) RainingAt(pos cube.Pos) bool

func (*Tx) Range

func (tx *Tx) Range() cube.Range

func (*Tx) Redstone

func (tx *Tx) Redstone() RedstoneTransaction

func (*Tx) RedstoneConductivePower

func (tx *Tx) RedstoneConductivePower(pos cube.Pos) int

func (*Tx) RedstoneDirectPower

func (tx *Tx) RedstoneDirectPower(pos cube.Pos) int

func (*Tx) RedstoneDirectPowerFrom

func (tx *Tx) RedstoneDirectPowerFrom(pos cube.Pos, face cube.Face) int

func (*Tx) RedstonePower

func (tx *Tx) RedstonePower(pos cube.Pos) int

func (*Tx) RedstonePowerFrom

func (tx *Tx) RedstonePowerFrom(pos cube.Pos, face cube.Face) int

func (*Tx) RedstoneStrongPower

func (tx *Tx) RedstoneStrongPower(pos cube.Pos) int

func (*Tx) RedstoneStrongPowerFrom

func (tx *Tx) RedstoneStrongPowerFrom(pos cube.Pos, face cube.Face) int

func (*Tx) RemoveEntity

func (tx *Tx) RemoveEntity(e Entity) *EntityHandle

func (*Tx) ScheduleBlockUpdate

func (tx *Tx) ScheduleBlockUpdate(pos cube.Pos, b Block, delay time.Duration)

func (*Tx) SetBiome

func (tx *Tx) SetBiome(pos cube.Pos, b Biome)

func (*Tx) SetBlock

func (tx *Tx) SetBlock(pos cube.Pos, b Block, opts *SetOpts)

func (*Tx) SetBlockEntity

func (tx *Tx) SetBlockEntity(pos cube.Pos, b Block)

func (*Tx) SetLiquid

func (tx *Tx) SetLiquid(pos cube.Pos, b Liquid)

func (*Tx) SkyLight

func (tx *Tx) SkyLight(pos cube.Pos) uint8

func (*Tx) Sleepers

func (tx *Tx) Sleepers() iter.Seq[Sleeper]

func (*Tx) SnowingAt

func (tx *Tx) SnowingAt(pos cube.Pos) bool

func (*Tx) Temperature

func (tx *Tx) Temperature(pos cube.Pos) float64

func (*Tx) Thundering

func (tx *Tx) Thundering() bool

func (*Tx) ThunderingAt

func (tx *Tx) ThunderingAt(pos cube.Pos) bool

func (*Tx) Viewers

func (tx *Tx) Viewers(pos mgl64.Vec3) []Viewer

func (*Tx) World

func (tx *Tx) World() *World

type ViewLayer

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

func NewViewLayer

func NewViewLayer(updater ViewLayerUpdater) *ViewLayer

func (*ViewLayer) AlwaysShowNameTag

func (v *ViewLayer) AlwaysShowNameTag(entity Entity) (bool, bool)

func (*ViewLayer) Close

func (v *ViewLayer) Close() error

func (*ViewLayer) Entities

func (v *ViewLayer) Entities() []*EntityHandle

func (*ViewLayer) NameTag

func (v *ViewLayer) NameTag(entity Entity) (string, bool)

func (*ViewLayer) Remove

func (v *ViewLayer) Remove(entity Entity)

func (*ViewLayer) ScoreTag

func (v *ViewLayer) ScoreTag(entity Entity) (string, bool)

func (*ViewLayer) ViewAlwaysShowNameTag

func (v *ViewLayer) ViewAlwaysShowNameTag(entity Entity, alwaysShow bool)

func (*ViewLayer) ViewNameTag

func (v *ViewLayer) ViewNameTag(entity Entity, nameTag string)

func (*ViewLayer) ViewPublicAlwaysShowNameTag

func (v *ViewLayer) ViewPublicAlwaysShowNameTag(entity Entity)

func (*ViewLayer) ViewPublicNameTag

func (v *ViewLayer) ViewPublicNameTag(entity Entity)

func (*ViewLayer) ViewPublicScoreTag

func (v *ViewLayer) ViewPublicScoreTag(entity Entity)

func (*ViewLayer) ViewScoreTag

func (v *ViewLayer) ViewScoreTag(entity Entity, scoreTag string)

func (*ViewLayer) ViewVisibility

func (v *ViewLayer) ViewVisibility(entity Entity, level VisibilityLevel)

func (*ViewLayer) Visibility

func (v *ViewLayer) Visibility(entity Entity) VisibilityLevel

type ViewLayerUpdater

type ViewLayerUpdater interface {
	ViewLayerEntityChanged(entity Entity)
}

type Viewer

type Viewer interface {
	ViewEntity(e Entity)

	HideEntity(e Entity)

	ViewEntityGameMode(e Entity)

	ViewEntityMovement(e Entity, pos mgl64.Vec3, rot cube.Rotation, onGround bool)

	ViewEntityDisplacement(e Entity, pos mgl64.Vec3, rot cube.Rotation, onGround bool)

	ViewEntityVelocity(e Entity, vel mgl64.Vec3)

	ViewEntityTeleport(e Entity, pos mgl64.Vec3)

	ViewFurnaceUpdate(prevCookTime, cookTime, prevRemainingFuelTime, remainingFuelTime, prevMaxFuelTime, maxFuelTime time.Duration)

	ViewBrewingUpdate(prevBrewTime, brewTime time.Duration, prevFuelAmount, fuelAmount, prevFuelTotal, fuelTotal int32)

	ViewChunk(pos ChunkPos, dim Dimension, blockEntities map[cube.Pos]Block, c *chunk.Chunk)

	ViewTime(t int)

	ViewTimeCycle(doDayLightCycle bool)

	ViewEntityItems(e Entity)

	ViewEntityArmour(e Entity)

	ViewEntityAction(e Entity, a EntityAction)

	ViewEntityState(e Entity)

	ViewEntityAnimation(e Entity, a EntityAnimation)

	ViewParticle(pos mgl64.Vec3, p Particle)

	ViewSound(pos mgl64.Vec3, s Sound)

	ViewBlockUpdate(pos cube.Pos, b Block, layer int)

	ViewBlockAction(pos cube.Pos, a BlockAction)

	ViewEmote(e Entity, emote uuid.UUID)

	ViewSkin(e Entity)

	ViewWorldSpawn(pos cube.Pos)

	ViewWeather(raining, thunder bool)

	ViewEntityWake(e Entity)
}

type VisibilityLevel

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

func EnforceInvisible

func EnforceInvisible() VisibilityLevel

func EnforceVisible

func EnforceVisible() VisibilityLevel

func PublicVisibility

func PublicVisibility() VisibilityLevel

func (VisibilityLevel) EnforceVisibility

func (v VisibilityLevel) EnforceVisibility() bool

type World

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

func New

func New() *World

func (*World) AdvanceTick

func (w *World) AdvanceTick()

func (*World) BlockRegistry

func (w *World) BlockRegistry() BlockRegistry

func (*World) Close

func (w *World) Close() error

func (*World) DefaultGameMode

func (w *World) DefaultGameMode() GameMode

func (*World) Difficulty

func (w *World) Difficulty() Difficulty

func (*World) Dimension

func (w *World) Dimension() Dimension

func (*World) Do

func (w *World) Do(f func(tx *Tx)) *Task

func (*World) DoAfter

func (w *World) DoAfter(delay time.Duration, f func(tx *Tx)) *Task

func (*World) EntityRegistry

func (w *World) EntityRegistry() EntityRegistry

func (*World) Handle

func (w *World) Handle(h Handler)

func (*World) Handler

func (w *World) Handler() Handler

func (*World) HighestLightBlocker

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

func (*World) Name

func (w *World) Name() string

func (*World) PlayerSpawn

func (w *World) PlayerSpawn(id uuid.UUID) cube.Pos

func (*World) PortalDestination

func (w *World) PortalDestination(dim Dimension) *World

func (*World) Raining

func (w *World) Raining() bool

func (*World) Range

func (w *World) Range() cube.Range

func (*World) Save

func (w *World) Save()

func (*World) SetDefaultGameMode

func (w *World) SetDefaultGameMode(mode GameMode)

func (*World) SetDifficulty

func (w *World) SetDifficulty(d Difficulty)

func (*World) SetPlayerSpawn

func (w *World) SetPlayerSpawn(id uuid.UUID, pos cube.Pos)

func (*World) SetRequiredSleepDuration

func (w *World) SetRequiredSleepDuration(duration time.Duration)

func (*World) SetSpawn

func (w *World) SetSpawn(pos cube.Pos)

func (*World) SetTickRange

func (w *World) SetTickRange(v int)

func (*World) SetTime

func (w *World) SetTime(new int)

func (*World) Spawn

func (w *World) Spawn() cube.Pos

func (World) StartRaining

func (w World) StartRaining(dur time.Duration)

func (World) StartThundering

func (w World) StartThundering(dur time.Duration)

func (*World) StartTime

func (w *World) StartTime()

func (World) StartWeatherCycle

func (w World) StartWeatherCycle()

func (World) StopRaining

func (w World) StopRaining()

func (World) StopThundering

func (w World) StopThundering()

func (*World) StopTime

func (w *World) StopTime()

func (World) StopWeatherCycle

func (w World) StopWeatherCycle()

func (*World) Thundering

func (w *World) Thundering() bool

func (*World) Time

func (w *World) Time() int

func (*World) TimeCycle

func (w *World) TimeCycle() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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