Rename cmd -> examples

This commit is contained in:
Tnze
2021-02-27 15:00:25 +08:00
parent 8e7ac43bf5
commit a7bf3b683f
12 changed files with 28 additions and 17 deletions

View File

@ -22,7 +22,7 @@ jobs:
- run: mkdir -p ./bin/tools
- name: Build tools
run: go build -o ./bin/tools ./cmd/...
run: go build -o ./bin/tools ./examples/...
- name: Upload tools
uses: actions/upload-artifact@v1

2
.gitignore vendored
View File

@ -14,6 +14,6 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
cmd/test/test.go
examples/test/test.go
.idea/
.vscode/

View File

@ -33,9 +33,6 @@ bot:
> 由于仍在开发中部分API在未来版本中可能会变动
Some examples are at `/cmd` folder.
有一些例子在cmd目录下
> `1.13.2` version is at [gomcbot](https://github.com/Tnze/gomcbot).
## Getting start
@ -105,4 +102,4 @@ Originally it's all right to write a bot with only `go-mc/net` package, but cons
理论上讲,只用`go-mc/net`包实现一个bot是完全可行的但是为了节省大家从头去理解MC握手、登录、加密等协议的过程`go-mc/bot`中我已经把这些都实现了,只不过它不是跨版本的。你可以直接使用,或者作为自己实现的参考。
Now, go and have a look at the example!
Now, go and have a look at the examples!

View File

@ -1,7 +1,7 @@
// Package bot implements a simple Minecraft client that can join a server
// or just ping it for getting information.
//
// Runnable example could be found at cmd/ .
// Runnable example could be found at examples/ .
package bot
import (

View File

@ -1,6 +1,9 @@
package main
import (
"github.com/Tnze/go-mc/bot/basic"
"github.com/Tnze/go-mc/data/packetid"
pk "github.com/Tnze/go-mc/net/packet"
"log"
"time"
@ -16,12 +19,30 @@ const timeout = 45
var (
c *bot.Client
p *basic.Player
watch chan time.Time
)
func main() {
log.SetOutput(colorable.NewColorableStdout())
c = bot.NewClient()
p = basic.NewPlayer(c, basic.DefaultSettings)
//Register event handlers
basic.EventsListener{
GameStart: onGameStart,
ChatMsg: onChatMsg,
Disconnect: onDisconnect,
Death: onDeath,
}.Attach(c)
c.Events.AddListener(bot.PacketHandler{
ID: packetid.NamedSoundEffect,
Priority: 0,
F: func(p pk.Packet) error {
return onSound()
},
})
//Login
err := c.JoinServer("127.0.0.1")
@ -30,13 +51,6 @@ func main() {
}
log.Println("Login success")
//Register event handlers
c.Events.GameStart = onGameStart
c.Events.ChatMsg = onChatMsg
c.Events.Disconnect = onDisconnect
c.Events.SoundPlay = onSound
c.Events.Die = onDeath
//JoinGame
err = c.HandleGame()
if err != nil {
@ -47,7 +61,7 @@ func main() {
func onDeath() error {
log.Println("Died and Respawned")
// If we exclude Respawn(...) then the player won't press the "Respawn" button upon death
return c.Respawn()
return p.Respawn()
}
func onGameStart() error {

View File

@ -1,4 +1,4 @@
// Usage: go run cmd/ping/ping.go localhost
// Usage: go run examples/ping/ping.go localhost
package main
import (