Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -8,13 +8,13 @@
|
|||||||
There's some library in Go support you to create your Minecraft client or server.
|
There's some library in Go support you to create your Minecraft client or server.
|
||||||
这是一些Golang库,用于帮助你编写自己的Minecraft客户端或服务器,
|
这是一些Golang库,用于帮助你编写自己的Minecraft客户端或服务器,
|
||||||
- [x] Chat
|
- [x] Chat
|
||||||
- [x] Parse NBT
|
- [x] NBT
|
||||||
- [x] Simple MC robot lib
|
|
||||||
- [x] Yggdrasil
|
- [x] Yggdrasil
|
||||||
- [x] Minecraft network protocol
|
- [x] Realms Server
|
||||||
- [x] RCON protocol
|
- [x] RCON protocol
|
||||||
- [x] Saves decoding /encoding
|
- [x] Saves decoding /encoding
|
||||||
- [x] Realms Server
|
- [x] Minecraft network protocol
|
||||||
|
- [x] Simple MC robot lib
|
||||||
|
|
||||||
bot:
|
bot:
|
||||||
- [x] Swing arm
|
- [x] Swing arm
|
||||||
@ -27,6 +27,7 @@ bot:
|
|||||||
- [x] Attack entity
|
- [x] Attack entity
|
||||||
- [x] Use/Place block
|
- [x] Use/Place block
|
||||||
- [x] Mine block
|
- [x] Mine block
|
||||||
|
- [x] Custom packets
|
||||||
- [ ] Record entities
|
- [ ] Record entities
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package bot
|
|||||||
import (
|
import (
|
||||||
"github.com/Tnze/go-mc/bot/world/entity"
|
"github.com/Tnze/go-mc/bot/world/entity"
|
||||||
"github.com/Tnze/go-mc/chat"
|
"github.com/Tnze/go-mc/chat"
|
||||||
|
|
||||||
|
pk "github.com/Tnze/go-mc/net/packet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type eventBroker struct {
|
type eventBroker struct {
|
||||||
@ -17,4 +19,8 @@ type eventBroker struct {
|
|||||||
|
|
||||||
WindowsItem func(id byte, slots []entity.Slot) error
|
WindowsItem func(id byte, slots []entity.Slot) error
|
||||||
WindowsItemChange func(id byte, slotID int, slot entity.Slot) error
|
WindowsItemChange func(id byte, slotID int, slot entity.Slot) error
|
||||||
|
|
||||||
|
// ReceivePacket will be called when new packet arrive.
|
||||||
|
// Default handler will run only if pass == false.
|
||||||
|
ReceivePacket func(p pk.Packet) (pass bool, err error)
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,16 @@ func (c *Client) HandleGame() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) handlePacket(p pk.Packet) (disconnect bool, err error) {
|
func (c *Client) handlePacket(p pk.Packet) (disconnect bool, err error) {
|
||||||
|
if c.Events.ReceivePacket != nil {
|
||||||
|
pass, err := c.Events.ReceivePacket(p)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if pass {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch p.ID {
|
switch p.ID {
|
||||||
case data.JoinGame:
|
case data.JoinGame:
|
||||||
err = handleJoinGamePacket(c, p)
|
err = handleJoinGamePacket(c, p)
|
||||||
|
@ -2,6 +2,7 @@ package bot
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/Tnze/go-mc/chat"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/data"
|
"github.com/Tnze/go-mc/data"
|
||||||
@ -178,3 +179,17 @@ func (c *Client) UseItemEnd() error {
|
|||||||
func (c *Client) SwapItem() error {
|
func (c *Client) SwapItem() error {
|
||||||
return c.playerAction(6, 0, 0, 0, 0)
|
return c.playerAction(6, 0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disconnect send disconnect packet to server.
|
||||||
|
// Server will close the connection after receive this packet.
|
||||||
|
func (c *Client) Disconnect(reason chat.Message) error {
|
||||||
|
return c.conn.WritePacket(pk.Marshal(
|
||||||
|
data.DisconnectPlay,
|
||||||
|
reason,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendPacket send the packet to server.
|
||||||
|
func (c *Client) SendPacket(packet pk.Packet) error {
|
||||||
|
return c.conn.WritePacket(packet)
|
||||||
|
}
|
||||||
|
6
go.mod
6
go.mod
@ -2,8 +2,4 @@ module github.com/Tnze/go-mc
|
|||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require github.com/google/uuid v1.1.1
|
||||||
github.com/google/uuid v1.1.1
|
|
||||||
github.com/mattn/go-colorable v0.1.2
|
|
||||||
github.com/satori/go.uuid v1.2.0 // indirect
|
|
||||||
)
|
|
||||||
|
8
go.sum
8
go.sum
@ -1,10 +1,2 @@
|
|||||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
|
||||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
|
||||||
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
|
||||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
|
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
|
Reference in New Issue
Block a user