Documentation ¶
Index ¶
- Variables
- type BlockActorDataHandler
- type BlockPickRequestHandler
- type BookEditHandler
- type ClientCacheBlobStatusHandler
- type CommandRequestHandler
- type Conn
- type ContainerCloseHandler
- type Controllable
- type EmoteHandler
- type InteractHandler
- type InventoryTransactionHandler
- type ItemStackRequestHandler
- type LevelSoundEventHandler
- type Logger
- type MobEquipmentHandler
- type ModalFormResponseHandler
- type NetworkEncodeableEntity
- type PlayerActionHandler
- type PlayerAuthInputHandler
- type PlayerSkinHandler
- type RequestAbilityHandler
- type RequestChunkRadiusHandler
- type RespawnHandler
- type Session
- func (s *Session) Addr() net.Addr
- func (s *Session) ClientData() login.ClientData
- func (s *Session) Close() error
- func (s *Session) CloseConnection()
- func (s *Session) Controllable() Controllable
- func (s *Session) Disconnect(message string)
- func (s *Session) EmptyUIInventory()
- func (s *Session) EnableCoordinates(enable bool)
- func (s *Session) EnableInstantRespawn(enable bool)
- func (s *Session) HandleInventories() (inv, offHand, enderChest *inventory.Inventory, armour *inventory.Armour, ...)
- func (s *Session) HideEntity(e world.Entity)
- func (s *Session) Latency() time.Duration
- func (s *Session) OpenBlockContainer(pos cube.Pos)
- func (s *Session) PlaySound(t world.Sound)
- func (s *Session) RemoveBossBar()
- func (s *Session) RemoveScoreboard()
- func (s *Session) SendAbsorption(value float64)
- func (s *Session) SendActionBarMessage(text string)
- func (s *Session) SendAnnouncement(message string)
- func (s *Session) SendBossBar(text string, colour uint8, healthPercentage float64)
- func (s *Session) SendCommandOutput(output *cmd.Output)
- func (s *Session) SendEffect(e effect.Effect)
- func (s *Session) SendEffectRemoval(e effect.Type)
- func (s *Session) SendExperience(e *entity.ExperienceManager)
- func (s *Session) SendFood(food int, saturation, exhaustion float64)
- func (s *Session) SendForm(f form.Form)
- func (s *Session) SendGameMode(mode world.GameMode)
- func (s *Session) SendHealth(health *entity.HealthManager)
- func (s *Session) SendJukeboxPopup(message string)
- func (s *Session) SendMessage(message string)
- func (s *Session) SendPopup(message string)
- func (s *Session) SendRespawn(pos mgl64.Vec3)
- func (s *Session) SendScoreboard(sb *scoreboard.Scoreboard)
- func (s *Session) SendSpeed(speed float64)
- func (s *Session) SendSubtitle(text string)
- func (s *Session) SendTip(message string)
- func (s *Session) SendTitle(text string)
- func (s *Session) SendToast(title, message string)
- func (s *Session) SetHeldSlot(slot int) error
- func (s *Session) SetTitleDurations(fadeInDuration, remainDuration, fadeOutDuration time.Duration)
- func (s *Session) Spawn(c Controllable, pos mgl64.Vec3, w *world.World, gm world.GameMode, ...)
- func (s *Session) Start()
- func (s *Session) StartShowingEntity(e world.Entity)
- func (s *Session) StopShowingEntity(e world.Entity)
- func (s *Session) Transfer(ip net.IP, port int)
- func (s *Session) UpdateHeldSlot(slot int, expected item.Stack) error
- func (s *Session) ViewBlockAction(pos cube.Pos, a world.BlockAction)
- func (s *Session) ViewBlockUpdate(pos cube.Pos, b world.Block, layer int)
- func (s *Session) ViewChunk(pos world.ChunkPos, c *chunk.Chunk, blockEntities map[cube.Pos]world.Block)
- func (s *Session) ViewEmote(player world.Entity, emote uuid.UUID)
- func (s *Session) ViewEntity(e world.Entity)
- func (s *Session) ViewEntityAction(e world.Entity, a world.EntityAction)
- func (s *Session) ViewEntityArmour(e world.Entity)
- func (s *Session) ViewEntityItems(e world.Entity)
- func (s *Session) ViewEntityMovement(e world.Entity, pos mgl64.Vec3, yaw, pitch float64, onGround bool)
- func (s *Session) ViewEntityState(e world.Entity)
- func (s *Session) ViewEntityTeleport(e world.Entity, position mgl64.Vec3)
- func (s *Session) ViewEntityVelocity(e world.Entity, velocity mgl64.Vec3)
- func (s *Session) ViewFurnaceUpdate(...)
- func (s *Session) ViewItemCooldown(item world.Item, duration time.Duration)
- func (s *Session) ViewParticle(pos mgl64.Vec3, p world.Particle)
- func (s *Session) ViewSkin(e world.Entity)
- func (s *Session) ViewSlotChange(slot int, newItem item.Stack)
- func (s *Session) ViewSound(pos mgl64.Vec3, soundType world.Sound)
- func (s *Session) ViewSubChunks(center world.SubChunkPos, offsets []protocol.SubChunkOffset)
- func (s *Session) ViewTime(time int)
- func (s *Session) ViewWeather(raining, thunder bool)
- func (s *Session) ViewWorldSpawn(pos cube.Pos)
- type SubChunkRequestHandler
- type TextHandler
Constants ¶
This section is empty.
Variables ¶
var Nop = &Session{}
Nop represents a no-operation session. It does not do anything when sending a packet to it.
Functions ¶
This section is empty.
Types ¶
type BlockActorDataHandler ¶ added in v0.2.0
type BlockActorDataHandler struct{}
BlockActorDataHandler handles an incoming BlockActorData packet from the client, sent for some block entities like signs when they are edited.
type BlockPickRequestHandler ¶
type BlockPickRequestHandler struct{}
BlockPickRequestHandler handles the BlockPickRequest packet.
type BookEditHandler ¶ added in v0.8.3
type BookEditHandler struct{}
BookEditHandler handles the BookEdit packet.
type ClientCacheBlobStatusHandler ¶
type ClientCacheBlobStatusHandler struct { }
ClientCacheBlobStatusHandler handles the ClientCacheBlobStatus packet.
type CommandRequestHandler ¶
type CommandRequestHandler struct {
// contains filtered or unexported fields
}
CommandRequestHandler handles the CommandRequest packet.
type Conn ¶ added in v0.3.0
type Conn interface { io.Closer // IdentityData returns the login.IdentityData of a Conn. It contains the UUID, XUID and username of the connection. IdentityData() login.IdentityData // ClientData returns the login.ClientData of a Conn. This includes less sensitive data of the player like its skin, // language code and other non-essential information. ClientData() login.ClientData // ClientCacheEnabled specifies if the Conn has the client cache, used for caching chunks client-side, enabled or // not. Some platforms, like the Nintendo Switch, have this disabled at all times. ClientCacheEnabled() bool // ChunkRadius returns the chunk radius as requested by the client at the other end of the Conn. ChunkRadius() int // Latency returns the current latency measured over the Conn. Latency() time.Duration // Flush flushes the packets buffered by the Conn, sending all of them out immediately. Flush() error // RemoteAddr returns the remote network address. RemoteAddr() net.Addr // ReadPacket reads a packet.Packet from the Conn. An error is returned if a deadline was set that was // exceeded or if the Conn was closed while awaiting a packet. ReadPacket() (pk packet.Packet, err error) // WritePacket writes a packet.Packet to the Conn. An error is returned if the Conn was closed before sending the // packet. WritePacket(pk packet.Packet) error // StartGameContext starts the game for the Conn with a context to cancel it. StartGameContext(ctx context.Context, data minecraft.GameData) error }
Conn represents a connection that packets are read from and written to by a Session. In addition, it holds some information on the identity of the Session.
type ContainerCloseHandler ¶
type ContainerCloseHandler struct{}
ContainerCloseHandler handles the ContainerClose packet.
type Controllable ¶
type Controllable interface { Name() string world.Entity item.User form.Submitter cmd.Source chat.Subscriber Locale() language.Tag SetHeldItems(right, left item.Stack) Move(deltaPos mgl64.Vec3, deltaYaw, deltaPitch float64) Speed() float64 Chat(msg ...any) ExecuteCommand(commandLine string) GameMode() world.GameMode SetGameMode(mode world.GameMode) Effects() []effect.Effect UseItem() ReleaseItem() UseItemOnBlock(pos cube.Pos, face cube.Face, clickPos mgl64.Vec3) UseItemOnEntity(e world.Entity) bool BreakBlock(pos cube.Pos) PickBlock(pos cube.Pos) AttackEntity(e world.Entity) bool Drop(s item.Stack) (n int) SwingArm() PunchAir() ExperienceLevel() int SetExperienceLevel(level int) EnchantmentSeed() int64 ResetEnchantmentSeed() Respawn() Dead() bool StartSneaking() Sneaking() bool StopSneaking() StartSprinting() Sprinting() bool StopSprinting() StartSwimming() Swimming() bool StopSwimming() StartFlying() Flying() bool StopFlying() StartGliding() Gliding() bool StopGliding() Jump() StartBreaking(pos cube.Pos, face cube.Face) ContinueBreaking(face cube.Face) FinishBreaking() AbortBreaking() Exhaust(points float64) EditSign(pos cube.Pos, text string) error EnderChestInventory() *inventory.Inventory // UUID returns the UUID of the controllable. It must be unique for all controllable entities present in // the server. UUID() uuid.UUID // XUID returns the XBOX Live User ID of the controllable. Every controllable must have one of these if // they are authenticated via XBOX Live, as they must be connected to an XBOX Live account. XUID() string // Skin returns the skin of the controllable. Each controllable must have a skin, as it defines how the // entity looks in the world. Skin() skin.Skin SetSkin(skin.Skin) }
Controllable represents an entity that may be controlled by a Session. Generally, Controllable is implemented in the form of a Player. Methods in Controllable will be added as Session needs them in order to handle packets.
type EmoteHandler ¶
EmoteHandler handles the Emote packet.
type InventoryTransactionHandler ¶
type InventoryTransactionHandler struct{}
InventoryTransactionHandler handles the InventoryTransaction packet.
type ItemStackRequestHandler ¶
type ItemStackRequestHandler struct {
// contains filtered or unexported fields
}
ItemStackRequestHandler handles the ItemStackRequest packet. It handles the actions done within the inventory.
type LevelSoundEventHandler ¶
type LevelSoundEventHandler struct{}
type Logger ¶ added in v0.7.0
Logger is used to write debug messages to. These messages are sent whenever handling of a packet of a client fails.
type MobEquipmentHandler ¶
type MobEquipmentHandler struct{}
MobEquipmentHandler handles the MobEquipment packet.
type ModalFormResponseHandler ¶
type ModalFormResponseHandler struct {
// contains filtered or unexported fields
}
ModalFormResponseHandler handles the ModalFormResponse packet.
type NetworkEncodeableEntity ¶ added in v0.8.2
type NetworkEncodeableEntity interface { // NetworkEncodeEntity returns the network type ID of the entity. This is NOT the save ID. NetworkEncodeEntity() string }
NetworkEncodeableEntity is an Entity where the save ID and network ID are not the same.
type PlayerActionHandler ¶
type PlayerActionHandler struct{}
PlayerActionHandler handles the PlayerAction packet.
type PlayerAuthInputHandler ¶
type PlayerAuthInputHandler struct{}
PlayerAuthInputHandler handles the PlayerAuthInput packet.
type PlayerSkinHandler ¶ added in v0.1.0
type PlayerSkinHandler struct{}
PlayerSkinHandler handles the PlayerSkin packet.
type RequestAbilityHandler ¶ added in v0.7.2
type RequestAbilityHandler struct{}
RequestAbilityHandler handles the RequestAbility packet.
type RequestChunkRadiusHandler ¶
type RequestChunkRadiusHandler struct{}
RequestChunkRadiusHandler handles the RequestChunkRadius packet.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session handles incoming packets from connections and sends outgoing packets by providing a thin layer of abstraction over direct packets. A Session basically 'controls' an entity.
func New ¶
New returns a new session using a controllable entity. The session will control this entity using the packets that it receives. New takes the connection from which to accept packets. It will start handling these packets after a call to Session.Spawn().
func (*Session) ClientData ¶
func (s *Session) ClientData() login.ClientData
ClientData returns the login.ClientData of the underlying *minecraft.Conn.
func (*Session) Close ¶
Close closes the session, which in turn closes the controllable and the connection that the session manages. Close ensures the method only runs code on the first call.
func (*Session) CloseConnection ¶
func (s *Session) CloseConnection()
CloseConnection closes the underlying connection of the session so that the session ends up being closed eventually.
func (*Session) Controllable ¶ added in v0.7.0
func (s *Session) Controllable() Controllable
Controllable returns the Controllable entity that the Session controls.
func (*Session) Disconnect ¶
Disconnect disconnects the client and ultimately closes the session. If the message passed is non-empty, it will be shown to the client.
func (*Session) EmptyUIInventory ¶ added in v0.8.4
func (s *Session) EmptyUIInventory()
EmptyUIInventory attempts to move all items in the UI inventory to the player's main inventory. If the main inventory is full, the items are dropped on the ground instead.
func (*Session) EnableCoordinates ¶
EnableCoordinates will either enable or disable coordinates for the player depending on the value given.
func (*Session) EnableInstantRespawn ¶ added in v0.3.0
EnableInstantRespawn will either enable or disable instant respawn for the player depending on the value given.
func (*Session) HandleInventories ¶
func (s *Session) HandleInventories() (inv, offHand, enderChest *inventory.Inventory, armour *inventory.Armour, heldSlot *atomic.Uint32)
HandleInventories starts handling the inventories of the Controllable entity of the session. It sends packets when slots in the inventory are changed.
func (*Session) OpenBlockContainer ¶
OpenBlockContainer ...
func (*Session) PlaySound ¶ added in v0.7.0
PlaySound plays a world.Sound to the client. The volume is not dependent on the distance to the source if it is a sound of the LevelSoundEvent packet.
func (*Session) RemoveBossBar ¶
func (s *Session) RemoveBossBar()
RemoveBossBar removes any boss bar currently active on the player's screen.
func (*Session) SendAbsorption ¶
SendAbsorption sends the absorption value passed to the player.
func (*Session) SendActionBarMessage ¶
SendActionBarMessage ...
func (*Session) SendAnnouncement ¶
SendAnnouncement ...
func (*Session) SendBossBar ¶
SendBossBar sends a boss bar to the player with the text passed and the health percentage of the bar. SendBossBar removes any boss bar that might be active before sending the new one.
func (*Session) SendCommandOutput ¶
SendCommandOutput sends the output of a command to the player. It will be shown to the caller of the command, which might be the player or a websocket server.
func (*Session) SendEffect ¶
SendEffect sends an effects passed to the player.
func (*Session) SendEffectRemoval ¶
SendEffectRemoval sends the removal of an effect passed.
func (*Session) SendExperience ¶ added in v0.7.0
func (s *Session) SendExperience(e *entity.ExperienceManager)
SendExperience sends the experience level and progress from the given experience manager to the player.
func (*Session) SendForm ¶
SendForm sends a form to the client of the connection. The Submit method of the form is called when the client submits the form.
func (*Session) SendGameMode ¶
SendGameMode sends the game mode of the Controllable entity of the session to the client. It makes sure the right flags are set to create the full game mode.
func (*Session) SendHealth ¶
func (s *Session) SendHealth(health *entity.HealthManager)
SendHealth sends the health and max health to the player.
func (*Session) SendJukeboxPopup ¶
SendJukeboxPopup ...
func (*Session) SendRespawn ¶
SendRespawn spawns the Controllable entity of the session client-side in the world, provided it has died.
func (*Session) SendScoreboard ¶
func (s *Session) SendScoreboard(sb *scoreboard.Scoreboard)
SendScoreboard ...
func (*Session) SendSpeed ¶
SendSpeed sends the speed of the player in an UpdateAttributes packet, so that it is updated client-side.
func (*Session) SetHeldSlot ¶
SetHeldSlot sets the currently held hotbar slot.
func (*Session) SetTitleDurations ¶
SetTitleDurations ...
func (*Session) Spawn ¶ added in v0.7.0
func (s *Session) Spawn(c Controllable, pos mgl64.Vec3, w *world.World, gm world.GameMode, onStop func(controllable Controllable))
Spawn makes the Controllable passed spawn in the world.World. The function passed will be called when the session stops running.
func (*Session) Start ¶
func (s *Session) Start()
Start makes the session start handling incoming packets from the client.
func (*Session) StartShowingEntity ¶ added in v0.4.0
StartShowingEntity starts showing a world.Entity to the Session that was previously hidden using StopShowingEntity.
func (*Session) StopShowingEntity ¶ added in v0.4.0
StopShowingEntity stops showing a world.Entity to the Session. It will be completely invisible until a call to StartShowingEntity is made.
func (*Session) UpdateHeldSlot ¶ added in v0.6.0
UpdateHeldSlot updates the held slot of the Session to the slot passed. It also verifies that the item in that slot matches an expected item stack.
func (*Session) ViewBlockAction ¶
func (s *Session) ViewBlockAction(pos cube.Pos, a world.BlockAction)
ViewBlockAction ...
func (*Session) ViewBlockUpdate ¶
ViewBlockUpdate ...
func (*Session) ViewChunk ¶
func (s *Session) ViewChunk(pos world.ChunkPos, c *chunk.Chunk, blockEntities map[cube.Pos]world.Block)
ViewChunk ...
func (*Session) ViewEntityAction ¶
func (s *Session) ViewEntityAction(e world.Entity, a world.EntityAction)
ViewEntityAction ...
func (*Session) ViewEntityArmour ¶
ViewEntityArmour ...
func (*Session) ViewEntityItems ¶
ViewEntityItems ...
func (*Session) ViewEntityMovement ¶
func (s *Session) ViewEntityMovement(e world.Entity, pos mgl64.Vec3, yaw, pitch float64, onGround bool)
ViewEntityMovement ...
func (*Session) ViewEntityState ¶
ViewEntityState ...
func (*Session) ViewEntityTeleport ¶
ViewEntityTeleport ...
func (*Session) ViewEntityVelocity ¶
ViewEntityVelocity ...
func (*Session) ViewFurnaceUpdate ¶ added in v0.8.0
func (s *Session) ViewFurnaceUpdate(prevCookTime, cookTime, prevRemainingFuelTime, remainingFuelTime, prevMaxFuelTime, maxFuelTime time.Duration)
ViewFurnaceUpdate updates a furnace for the associated session based on previous times.
func (*Session) ViewItemCooldown ¶ added in v0.8.0
ViewItemCooldown ...
func (*Session) ViewParticle ¶
ViewParticle ...
func (*Session) ViewSlotChange ¶
ViewSlotChange ...
func (*Session) ViewSubChunks ¶ added in v0.7.0
func (s *Session) ViewSubChunks(center world.SubChunkPos, offsets []protocol.SubChunkOffset)
ViewSubChunks ...
func (*Session) ViewWeather ¶ added in v0.4.0
ViewWeather ...
func (*Session) ViewWorldSpawn ¶ added in v0.1.0
ViewWorldSpawn ...
type SubChunkRequestHandler ¶ added in v0.7.0
type SubChunkRequestHandler struct{}
SubChunkRequestHandler handles sub-chunk requests from the client. The server will respond with a packet containing the requested sub-chunks.
Source Files ¶
- chunk.go
- command.go
- controllable.go
- enchantment_texts.go
- entity_metadata.go
- handler.go
- handler_anvil.go
- handler_beacon.go
- handler_block_actor_data.go
- handler_block_pick_request.go
- handler_book_edit.go
- handler_client_cache_blob_status.go
- handler_command_request.go
- handler_container_close.go
- handler_crafting.go
- handler_emote.go
- handler_enchanting.go
- handler_grindstone.go
- handler_interact.go
- handler_inventory_transaction.go
- handler_item_stack_request.go
- handler_level_sound_event.go
- handler_loom.go
- handler_mob_equipment.go
- handler_modal_form_response.go
- handler_player_action.go
- handler_player_auth_input.go
- handler_player_skin.go
- handler_request_ability.go
- handler_request_chunk_radius.go
- handler_respawn.go
- handler_smithing.go
- handler_stonecutter.go
- handler_sub_chunk_request.go
- handler_text.go
- player.go
- session.go
- text.go
- world.go