This repository was archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Handle events
Tnze edited this page Jan 23, 2019
·
6 revisions
After you go g.HandleGame(), you have to get event channel by events := g.GetEvents() and receive Events from events. The events hasn't buffer so if you don't receive Event, game handler will be block.
Generally, you should handle events after you go g.HandleGame() like this:
for e := range events {
switch e {
case mb.PlayerSpawnEvent:
fmt.Println("Player is spawn!")
case mb.PlayerDeadEvent:
fmt.Println("Player is dead")
default:
fmt.Println("Other event: ", e)
}
}Chat message is not sending by previous. However, if you want to handle chat messages, you should set a callback function:
game.SetChatCallBack(func(msg string, pos byte) {
if pos == 0 {
fmt.Println(msg)
}
})The pos can be 0, 1 or 2. It tells where client should display this message:
- 0: chat (chat box)
- 1: system message (chat box)
- 2: game info (above hotbar)
The msg is a JSON string which format you can found here
Like Chat, the sound played event is also a callback. To set a sound callback function, use
func (g *Game) SetSoundCallBack(handler func(sound int32, x, y, z float64, Volume, Pitch float32))For sound id, see: https://pokechu22.github.io/Burger/1.13.2.html#sounds
- x, y, z is the position the sound played.
- Volume is the volume of the sound.
- Pitch is the direction of the sound.