Documentation ¶
Overview ¶
Package game contains the logic for game features such as worlds and entities.
The entire game state is managed by a Game instance. This type has a Run function that is responsible for updating ('ticking') the world and entities. All game related logic should execute on the same goroutine that called Run. If a different goroutine needs to execute a game-related job, it can use the Game.Schedule function to schedule a job to run on the correct goroutine.
Index ¶
Constants ¶
const PlayerEyeHeight = 1.62
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk struct {
// contains filtered or unexported fields
}
Chunk represents a 16x16x256 area in a World.
func (*Chunk) Broadcast ¶
func (c *Chunk) Broadcast(msg interface{})
Broadcast broadcasts a message to all subscribers of this Chunk.
func (*Chunk) SetBlock ¶
SetBlock changes a block in the chunk. Note that the coordinates are relative to the chunk, not world coordinates. Coordinates must all be within the range [0,15] or the function will panic.
func (*Chunk) Subscribe ¶
Subscribe registers the specified channel to receive updates for this Chunk. The specified ID must be unique to the subscriber.
func (*Chunk) Unsubscribe ¶
Unsubscribe cancels the subscription associated with the specified ID.
type ChunkPos ¶
type ChunkPos struct {
X, Z int32
}
ChunkPos contains a pair of chunk coordinates.
func ChunkPosFromWorldCoords ¶
ChunkPosFromWorldCoords returns the ChunkPos for the given world coordinates.
type Config ¶
type Config struct { // MaxJobs specifies how many jobs can be queued at the same time. MaxJobs int // TickInterval specifies how often the game state should be updated. TickInterval time.Duration }
Config is used to configure a Game instance.
type Entity ¶
type Entity interface { // EntityID returns the ID for this entity. This function may be called concurrently. EntityID() ID // contains filtered or unexported methods }
Entity represents a Minecraft entity, such as a player or a dropped item.
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game manages the state for game related things, such as worlds and entities.
func (*Game) Close ¶
Close releases resources associated with the Game. Any ongoing Run calls will exit. This function may only be called once and always returns nil.
func (*Game) DefaultWorld ¶
DefaultWorld returns the default World.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player represents a player entity.
func NewPlayer ¶
func NewPlayer(name string, uid uuid.UUID, conn PlayerConn) *Player
NewPlayer constructs a new Player. The created Player will not be associated with any World yet.
func (*Player) HandlePacket ¶
HandlePacket processes a packet sent by the player. This function should only be used by the server itself.
type PlayerConn ¶
type PlayerConn interface { // WritePacket sends a packet to the player. WritePacket(pk packet.Outbound) // Disconnect kicks the player from the server. Disconnect(reason *chat.Msg) }
PlayerConn represents a player's network connection.
type World ¶
type World struct {
// contains filtered or unexported fields
}
World represents a world within the server.
func (*World) GetChunk ¶
GetChunk gets the Chunk at the specified position, or nil if it does not exist.
func (*World) RemoveEntity ¶
RemoveEntity removes the entity associated with the specified id. If no such entity exists, this function does nothing.