world

package
v0.0.0-...-2a33acd Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePlayerInfoPacket

func GeneratePlayerInfoPacket(players []*player.Player, action int32) *packet.OutgoingPacket

Types

type Hitbox

type Hitbox interface {
	// feet position (bottom center of hitbox)
	X() float64
	Y() float64
	Z() float64

	// New position the entity is trying to move to
	NewX() float64
	NewY() float64
	NewZ() float64

	// radius on X and Z in blocks
	Width() float64
	// height of the hitbox in blocks
	Height() float64
}

type World

type World struct {
	Scheduler *schedule.Scheduler

	// User space code to setup the world.
	Settings settings
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld(manager *WorldManager, name string) *World

This creates a new world, given a world manager and a name. Things like default chunk and world seed can be set using world.Settings.

func (*World) AddPlayer

func (w *World) AddPlayer(p *player.Player)

This adds a player to the given world. It should not be called, as that player will not be removed from it's previous world. Instead, you should call WorldManager.MovePlayerToWorld(name string). This will send all neccessary packets to allow the player to spawn in.

func (*World) Block

func (w *World) Block(pos block.Pos) *block.State

This gets a pointer to a block.State. Block states know everything about their current block, as they contain pointers to the world and chunk they are in. If you only want to set a block, you should call w.SetBlock(), as that does not create a new struct. This function will always create a new block.State, which can be expensive if called a lot.

func (*World) BlockState

func (w *World) BlockState(pos block.Pos) uint32

This returns the block id at the given position. It is shorthand for world.BlockType(pos).State().

func (*World) BlockType

func (w *World) BlockType(pos block.Pos) *block.Type

This returns the block type at the given position. This does not allocate any memory, so it's a lot faster than calling w.Block(pos).Type()

func (*World) BreakBlock

func (w *World) BreakBlock(p *player.Player, pos block.Pos)

This is called whenever a player tries to break a block. This will spawn block breaking particles, and set the block to air.

func (*World) Chunk

func (w *World) Chunk(pos block.ChunkPos) (*chunk.MultiChunk, bool)

This gets the chunk at the given location. If the chunk already exists, it returns that chunk, and false. If terrain generation is enabled, then it generates a new chunk, at returns that (and false). Otherwise, it will return the default chunk, and true.

func (*World) ChunkAtBlock

func (w *World) ChunkAtBlock(pos block.Pos) (*chunk.MultiChunk, block.ChunkPos, bool)

This returns the chunk at the given block. This returns four values: The chunk (can be the default chunk), the chunk's position, and a bool for if this is the default chunk.

func (*World) ChunkNotDefault

func (w *World) ChunkNotDefault(pos block.ChunkPos) *chunk.MultiChunk

This is the same as Chunk(), but if Chunk() would return the default chunk, this function generates a new empty chunk.

func (*World) Chunks

func (w *World) Chunks() map[block.ChunkPos]*chunk.MultiChunk

This returns a copy of the world's chunks. Since this is a copy, it is slow to generate.

func (*World) ClearVoid

func (w *World) ClearVoid()

This will loop through all loaded chunks, and reset them to default chunks, if they are void (all air).

func (*World) Collide

func (w *World) Collide(hitbox Hitbox) *entity.CollisionInfo

func (*World) DisconnectPlayer

func (w *World) DisconnectPlayer(p *player.Player)

This removes the player from the server.

func (*World) FixDesync

func (w *World) FixDesync(pos block.Pos)

This sends a block update to everyone in render distance. As the name implies, this is most commonly used to fix 'ghost' (client-side only) blocks

func (*World) GenerateNewChunkPacket

func (w *World) GenerateNewChunkPacket(chunk *chunk.MultiChunk, pos block.ChunkPos, version block.Version) *packet.OutgoingPacket

func (*World) GenerateUpdateLightPacket

func (w *World) GenerateUpdateLightPacket(chunk *chunk.MultiChunk, pos block.ChunkPos, version block.Version) *packet.OutgoingPacket

func (*World) Generator

func (w *World) Generator() terrain.WorldGenerator

func (*World) GetEntity

func (w *World) GetEntity(id uint32) (entity.Entity, bool)

Gets the entity with the given EID.

It will return (an entity, true) if one was found, and (nil, false) of none was found.

func (*World) HasPlayer

func (w *World) HasPlayer(p *player.Player) bool

This checks if the world has the given player.

func (*World) KickPlayer

func (w *World) KickPlayer(p *player.Player, reason *util.Chat)

This removes the player from the server, and gives them a disconnect reason. This is shown on a dirt screen in the vanilla client.

func (*World) Load

func (w *World) Load()

This loads the world from disk. It does not send any packets, so you should only call this before the server is started.

func (*World) LockSettings

func (w *World) LockSettings()

This finalizes the world settings. This must be called before the world is usable. No terrain will generate before this is called.

func (*World) Name

func (w *World) Name() string

This returns the world's name.

func (*World) NextEID

func (w *World) NextEID() uint32

This returns a unique entity ID, which can be used with a new entity.

func (*World) OnChunkSet

func (w *World) OnChunkSet(f func(pos block.ChunkPos))

func (*World) PlaceBlock

func (w *World) PlaceBlock(p *player.Player, pos block.Pos, t *block.Type) bool

This is called whenever a player tries to place a block. It first calls PlayerCanPlaceBlock, and then either places the block, or sends a packet to cancel the block place on the client. This returns true of the block place was successful.

func (*World) Player

func (w *World) Player(id util.UUID) *player.Player

Gets a player from a UUID. Returns nil if the player is not present.

func (*World) PlayerByName

func (w *World) PlayerByName(name string) *player.Player

This searches for a player with the given username. If no player is found, it will return nil.

func (*World) PlayerCanPlaceBlock

func (w *World) PlayerCanPlaceBlock(player *player.Player, pos block.Pos) bool

This checks if the player can place the block.

TODO: Actually implement this function. Currently, it always returns true.

func (*World) Players

func (w *World) Players() map[util.UUID]*player.Player

This returns a copy of all of the players in the world. This is slow, as it must allocate a new map, and add all of the players to it. For things like fining a player by name, or iterating through players, you should use the utility functions to do that (PlayerByName and ForAllPlayers).

func (*World) RunForAll

func (w *World) RunForAll(f func(p *player.Player) bool)

Runs f for all players in the world. If f returns false, the loop exists.

func (*World) RunInView

func (w *World) RunInView(pos block.ChunkPos, f func(p *player.Player) bool)

Runs a function for all players within view of the given chunk. If f returns false, the loop will exit.

func (*World) SaveChunkToDisk

func (w *World) SaveChunkToDisk(pos block.ChunkPos)

This saves the given chunk to disk, at the default directory.

func (*World) SaveChunkToDiskDir

func (w *World) SaveChunkToDiskDir(pos block.ChunkPos, dir string)

This saves the chunk at the given coordinate to disk, and puts it within the given directory.

func (*World) SaveChunkToS3

func (w *World) SaveChunkToS3(pos block.ChunkPos, bucket string)

This saves the chunk to S3, at the default location.

func (*World) SaveChunkToS3Dir

func (w *World) SaveChunkToS3Dir(pos block.ChunkPos, bucket, key string)

This saves the chunk at the given coordinate to S3, given the bucket and prefix.

func (*World) SaveToDisk

func (w *World) SaveToDisk()

This saves all chunks to the default directory.

func (*World) SaveToDiskDir

func (w *World) SaveToDiskDir(dir string)

This saves all chunk to disk, at the given directory.

func (*World) SaveToS3

func (w *World) SaveToS3()

This saves all chunks to the default location.

func (*World) SaveToS3Dir

func (w *World) SaveToS3Dir(bucket, dir string)

This saves all chunks to S3, given the bucket name and prefix

func (*World) SendInView

func (w *World) SendInView(pos block.ChunkPos, out ...*packet.OutgoingPacket)

Sends the packet to all players within render distance of the given chunk.

func (*World) SendInViewNotID

func (w *World) SendInViewNotID(pos block.ChunkPos, id util.UUID, out ...*packet.OutgoingPacket)

Sends the packet to all players, who do not have the given id, within render distance of the given chunk.

func (*World) SendToAll

func (w *World) SendToAll(out ...*packet.OutgoingPacket)

func (*World) SetBlock

func (w *World) SetBlock(pos block.Pos, t *block.Type)

This sets the block at the given position to the given type. This is faster than world.Block(pos).SetType(t), since this does not allocate any memory on the heap.

func (*World) SetBlockProperties

func (w *World) SetBlockProperties(pos block.Pos, properties map[string]string)

This sets multiple block properties at the given postition. See block.State.SetProperties() for more information.

func (*World) SetBlockProperty

func (w *World) SetBlockProperty(pos block.Pos, category, name string)

This sets the block property at the given position. See block.State.SetProperty() for more information.

func (*World) Spawn

func (w *World) Spawn(etype entity.Type, x, y, z float64, pitch, yaw, head_pitch byte, vx, vy, vz int16) entity.Entity

This will spawn an entity of the given type in the world. This will return nil and do nothing if the given entity type was not an entity. If the entity you passed in was an object, it will call SpawnObject, with a data value of 0.

The returned entity is a pointer to the entity that was just spawned.

vx, vy, and vz are velocity values, in 1/8000 of a block per tick.

func (*World) SpawnObject

func (w *World) SpawnObject(etype entity.Type, x, y, z float64, yaw, pitch byte, vx, vy, vz int16, data int32) entity.Entity

Pass an entity id as the first parameter. The will return nil and do nothing if the given type is not an object.

I understand that object types and entity types are different. To make your life simpler, I have mapped all objects' entity ids to object ids. This means that it is easier to check if an entity id is valid, rather than an object id.

The data field can be set to anything, and that is what will be send in the spawn obejct packet. (There are no checks!) For example, if you wanted to spawn a tnt minecart, you would call this: world.SpawnObject(entity.Type_Minecart, 3)

vx, vy, and vz are velocity values, in 1/8000 of a block per tick.

For exp orbs, the data field is the amount of exp in the orb (will change the size of it)

For paintings, call world.SpawnPainting(). This function will return nil and do nothing of Type_Painting is passed in.

func (*World) StartUpdateLoop

func (w *World) StartUpdateLoop(wg *sync.WaitGroup)

This starts the update loop for the world. Should never be called, as mc.StartUpdateLoop() will call this for you. This is a non-blocking call, as it spawns the update loop as a new go routine.

func (*World) TryUnload

func (w *World) TryUnload(pos block.ChunkPos) bool

This will try to unload the chunk at the given position. It will return true if the chunk was unloaded. If the world is using default chunks, this will always return false. If any players are within view distance of the given chunk, it will return false. Otherwise, it will call Unload(pos).

func (*World) Unload

func (w *World) Unload(pos block.ChunkPos)

This sets the chunk at the given chunk coordinates to a default chunk, or an empty chunk if default chunk is not enabled. If the previous chunk was not a default chunk, or if it was a modified terrain chunk, then it will be saved to disk.

type WorldManager

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

func NewWorldManager

func NewWorldManager(sess *session.Session, path, default_world_name string) *WorldManager

func NewWorldManagerWithSlots

func NewWorldManagerWithSlots(sess *session.Session, path, default_world_name string, timeout time.Duration, max_players int) *WorldManager

func (*WorldManager) AddPlayer

func (w *WorldManager) AddPlayer(player *player.Player, send_login bool)

This adds the player into the default world, and ignores any slot reservation stuff.

func (*WorldManager) AddWorld

func (w *WorldManager) AddWorld(name string)

This adds a new world

func (*WorldManager) DefaultWorld

func (w *WorldManager) DefaultWorld() *World

This returns the default world. This will always return a valid world pointer.

func (*WorldManager) DisconnectPlayer

func (w *WorldManager) DisconnectPlayer(player *player.Player)

This removes the player from the world, and disconnects them.

func (*WorldManager) FindPlayerByName

func (w *WorldManager) FindPlayerByName(name string) *player.Player

This finds the player with the given username, by looping through all players. This is relatively slow, as it needs to (on average) check at least half of the players online. So avoid calling this function if you know which world they are in. If you know the world, then you can call w.GetPlayer(), which is a single map lookup. This will return nil if the player is not online.

func (*WorldManager) GetWorldOfPlayer

func (w *WorldManager) GetWorldOfPlayer(player *player.Player) *World

This gets the world that a player is in. This is very fast, as the world manager stores all players in a map of player -> world.

func (*WorldManager) KickPlayer

func (w *WorldManager) KickPlayer(player *player.Player, reason *util.Chat)

This removes the player from the world, and sends them a disconnect message.

func (*WorldManager) LenPlayers

func (w *WorldManager) LenPlayers() int

This gets the number of online players.

func (*WorldManager) Load

func (w *WorldManager) Load()

This loads all worlds from disk or S3

func (*WorldManager) MaxPlayers

func (w *WorldManager) MaxPlayers() int

This gets the maximum number of players.

func (*WorldManager) MovePlayerToWorld

func (w *WorldManager) MovePlayerToWorld(player *player.Player, world_name string)

This moves the given player to a new world. If the player is not in any world, it will do nothing. If the world name is invalid, it log a warning, and return.

func (*WorldManager) PlayerCanJoin

func (w *WorldManager) PlayerCanJoin(id util.UUID, name string) bool

This checks if a single player can join. If they are already online, it returns fals. If the server requires slot reservation, and this player has not reserved a slot, then it will return false. If they reserved a slot, but it has been too long since they reserved that slot, it will return false. Otherwise, it returns true.

func (*WorldManager) Players

func (w *WorldManager) Players() map[util.UUID]*player.Player

This generates a map of all players online. It is not very fast, as it needs to copy all players into a new map each time you call this function.

func (*WorldManager) ReservePlayers

func (w *WorldManager) ReservePlayers(players []util.UUID) bool

This reserves a list of UUIDS, and returns true if all of those players can join. This is part of the handshake system for switching servers. This will make sure that the current number of online players, plus the new players passed in, is still <= max_players.

func (*WorldManager) SetResourcePack

func (w *WorldManager) SetResourcePack(url string)

Sets the resource pack url. If url is "", then the resource pack is disabled.

func (*WorldManager) StartUpdateLoop

func (w *WorldManager) StartUpdateLoop(waitGroup *sync.WaitGroup)

func (*WorldManager) Worlds

func (w *WorldManager) Worlds() map[string]*World

This returns the map of worlds. It is a reference to the actual worlds map, so modifying it can break things.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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