Documentation ¶
Index ¶
- func GeneratePlayerInfoPacket(players []*player.Player, action int32) *packet.OutgoingPacket
- type Hitbox
- type World
- func (w *World) AddPlayer(p *player.Player)
- func (w *World) Block(pos block.Pos) *block.State
- func (w *World) BlockState(pos block.Pos) uint32
- func (w *World) BlockType(pos block.Pos) *block.Type
- func (w *World) BreakBlock(p *player.Player, pos block.Pos)
- func (w *World) Chunk(pos block.ChunkPos) (*chunk.MultiChunk, bool)
- func (w *World) ChunkAtBlock(pos block.Pos) (*chunk.MultiChunk, block.ChunkPos, bool)
- func (w *World) ChunkNotDefault(pos block.ChunkPos) *chunk.MultiChunk
- func (w *World) Chunks() map[block.ChunkPos]*chunk.MultiChunk
- func (w *World) ClearVoid()
- func (w *World) Collide(hitbox Hitbox) *entity.CollisionInfo
- func (w *World) DisconnectPlayer(p *player.Player)
- func (w *World) FixDesync(pos block.Pos)
- func (w *World) GenerateNewChunkPacket(chunk *chunk.MultiChunk, pos block.ChunkPos, version block.Version) *packet.OutgoingPacket
- func (w *World) GenerateUpdateLightPacket(chunk *chunk.MultiChunk, pos block.ChunkPos, version block.Version) *packet.OutgoingPacket
- func (w *World) Generator() terrain.WorldGenerator
- func (w *World) GetEntity(id uint32) (entity.Entity, bool)
- func (w *World) HasPlayer(p *player.Player) bool
- func (w *World) KickPlayer(p *player.Player, reason *util.Chat)
- func (w *World) Load()
- func (w *World) LockSettings()
- func (w *World) Name() string
- func (w *World) NextEID() uint32
- func (w *World) OnChunkSet(f func(pos block.ChunkPos))
- func (w *World) PlaceBlock(p *player.Player, pos block.Pos, t *block.Type) bool
- func (w *World) Player(id util.UUID) *player.Player
- func (w *World) PlayerByName(name string) *player.Player
- func (w *World) PlayerCanPlaceBlock(player *player.Player, pos block.Pos) bool
- func (w *World) Players() map[util.UUID]*player.Player
- func (w *World) RunForAll(f func(p *player.Player) bool)
- func (w *World) RunInView(pos block.ChunkPos, f func(p *player.Player) bool)
- func (w *World) SaveChunkToDisk(pos block.ChunkPos)
- func (w *World) SaveChunkToDiskDir(pos block.ChunkPos, dir string)
- func (w *World) SaveChunkToS3(pos block.ChunkPos, bucket string)
- func (w *World) SaveChunkToS3Dir(pos block.ChunkPos, bucket, key string)
- func (w *World) SaveToDisk()
- func (w *World) SaveToDiskDir(dir string)
- func (w *World) SaveToS3()
- func (w *World) SaveToS3Dir(bucket, dir string)
- func (w *World) SendInView(pos block.ChunkPos, out ...*packet.OutgoingPacket)
- func (w *World) SendInViewNotID(pos block.ChunkPos, id util.UUID, out ...*packet.OutgoingPacket)
- func (w *World) SendToAll(out ...*packet.OutgoingPacket)
- func (w *World) SetBlock(pos block.Pos, t *block.Type)
- func (w *World) SetBlockProperties(pos block.Pos, properties map[string]string)
- func (w *World) SetBlockProperty(pos block.Pos, category, name string)
- func (w *World) Spawn(etype entity.Type, x, y, z float64, pitch, yaw, head_pitch byte, ...) entity.Entity
- func (w *World) SpawnObject(etype entity.Type, x, y, z float64, yaw, pitch byte, vx, vy, vz int16, ...) entity.Entity
- func (w *World) StartUpdateLoop(wg *sync.WaitGroup)
- func (w *World) TryUnload(pos block.ChunkPos) bool
- func (w *World) Unload(pos block.ChunkPos)
- type WorldManager
- func (w *WorldManager) AddPlayer(player *player.Player, send_login bool)
- func (w *WorldManager) AddWorld(name string)
- func (w *WorldManager) DefaultWorld() *World
- func (w *WorldManager) DisconnectPlayer(player *player.Player)
- func (w *WorldManager) FindPlayerByName(name string) *player.Player
- func (w *WorldManager) GetWorldOfPlayer(player *player.Player) *World
- func (w *WorldManager) KickPlayer(player *player.Player, reason *util.Chat)
- func (w *WorldManager) LenPlayers() int
- func (w *WorldManager) Load()
- func (w *WorldManager) MaxPlayers() int
- func (w *WorldManager) MovePlayerToWorld(player *player.Player, world_name string)
- func (w *WorldManager) PlayerCanJoin(id util.UUID, name string) bool
- func (w *WorldManager) Players() map[util.UUID]*player.Player
- func (w *WorldManager) ReservePlayers(players []util.UUID) bool
- func (w *WorldManager) SetResourcePack(url string)
- func (w *WorldManager) StartUpdateLoop(waitGroup *sync.WaitGroup)
- func (w *WorldManager) Worlds() map[string]*World
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GeneratePlayerInfoPacket ¶
func GeneratePlayerInfoPacket(players []*player.Player, action int32) *packet.OutgoingPacket
Types ¶
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 ¶
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 ¶
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 ¶
This returns the block id at the given position. It is shorthand for world.BlockType(pos).State().
func (*World) BlockType ¶
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 ¶
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 ¶
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 ¶
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) DisconnectPlayer ¶
This removes the player from the server.
func (*World) FixDesync ¶
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 ¶
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) KickPlayer ¶
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) OnChunkSet ¶
func (*World) PlaceBlock ¶
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) PlayerByName ¶
This searches for a player with the given username. If no player is found, it will return nil.
func (*World) PlayerCanPlaceBlock ¶
This checks if the player can place the block.
TODO: Actually implement this function. Currently, it always returns true.
func (*World) Players ¶
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) RunInView ¶
Runs a function for all players within view of the given chunk. If f returns false, the loop will exit.
func (*World) SaveChunkToDisk ¶
This saves the given chunk to disk, at the default directory.
func (*World) SaveChunkToDiskDir ¶
This saves the chunk at the given coordinate to disk, and puts it within the given directory.
func (*World) SaveChunkToS3 ¶
This saves the chunk to S3, at the default location.
func (*World) SaveChunkToS3Dir ¶
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 ¶
This saves all chunk to disk, at the given directory.
func (*World) SaveToS3Dir ¶
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 ¶
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 ¶
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 ¶
This sets multiple block properties at the given postition. See block.State.SetProperties() for more information.
func (*World) SetBlockProperty ¶
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 ¶
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 ¶
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).
type WorldManager ¶
type WorldManager struct {
// contains filtered or unexported fields
}
func NewWorldManager ¶
func NewWorldManager(sess *session.Session, path, default_world_name string) *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) 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) 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.