Handle screen open/send content
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
@ -47,8 +48,8 @@ func (p *Player) handleJoinGamePacket(packet pk.Packet) error {
|
||||
(*pk.Byte)(&p.PrevGamemode),
|
||||
&WorldCount,
|
||||
pk.Ary{Len: &WorldCount, Ary: &WorldNames},
|
||||
pk.NBT(new(interface{})),
|
||||
pk.NBT(new(interface{})),
|
||||
pk.NBT(new(nbt.RawMessage)),
|
||||
pk.NBT(new(nbt.RawMessage)),
|
||||
(*pk.Identifier)(&p.WorldName),
|
||||
(*pk.Long)(&p.HashedSeed),
|
||||
(*pk.VarInt)(&p.MaxPlayers),
|
||||
|
@ -1,8 +1,16 @@
|
||||
package screen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Tnze/go-mc/data/item"
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
)
|
||||
|
||||
type Inventory struct {
|
||||
}
|
||||
|
||||
func (inv Inventory) SetSlot(i int, id int32, count byte, NBT interface{}) {
|
||||
panic("implement me")
|
||||
func (inv Inventory) SetSlot(i int, id int32, count byte, NBT nbt.RawMessage) {
|
||||
// TODO: accept inv data
|
||||
fmt.Printf("Inventory[%d] = minecraft:%v * %d\n", i, item.ByID[item.ID(id)].Name, count)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/Tnze/go-mc/bot"
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
@ -18,6 +19,7 @@ func NewManager(c *bot.Client) *Manager {
|
||||
m.Screens[0] = &Inventory{}
|
||||
c.Events.AddListener(
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.OpenWindow, F: m.onOpenScreen},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.WindowItems, F: m.onSetContentPacket},
|
||||
)
|
||||
return m
|
||||
}
|
||||
@ -60,7 +62,7 @@ type slot struct {
|
||||
present pk.Boolean
|
||||
id pk.VarInt
|
||||
count pk.Byte
|
||||
nbt interface{}
|
||||
nbt nbt.RawMessage
|
||||
}
|
||||
|
||||
func (s *slot) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
@ -74,7 +76,7 @@ func (s *slot) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
}
|
||||
|
||||
type Container interface {
|
||||
SetSlot(i int, id int32, count byte, NBT interface{})
|
||||
SetSlot(i int, id int32, count byte, NBT nbt.RawMessage)
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
|
29
bot/screen/type.go
Normal file
29
bot/screen/type.go
Normal file
@ -0,0 +1,29 @@
|
||||
package screen
|
||||
|
||||
type Info struct {
|
||||
Name string
|
||||
Start, End int // Player inventory
|
||||
Slots int
|
||||
}
|
||||
|
||||
func (i Info) PlayerInvStart() int {
|
||||
return i.Start
|
||||
}
|
||||
|
||||
func (i Info) PlayerInvEnd() int {
|
||||
return i.End
|
||||
}
|
||||
|
||||
func (i Info) HotbarIdx(place int) int {
|
||||
return i.End - (8 - place)
|
||||
}
|
||||
|
||||
var ByType = map[int]Info{
|
||||
-1: {Name: "inventory", Start: 9, End: 44, Slots: 46},
|
||||
0: {Name: "generic_9x1", Start: 1 * 9, End: 1*9 + 35, Slots: 1*9 + 36},
|
||||
1: {Name: "generic_9x2", Start: 2 * 9, End: 2*9 + 35, Slots: 2*9 + 36},
|
||||
2: {Name: "generic_9x3", Start: 3 * 9, End: 3*9 + 35, Slots: 3*9 + 36},
|
||||
3: {Name: "generic_9x4", Start: 4 * 9, End: 4*9 + 35, Slots: 4*9 + 36},
|
||||
4: {Name: "generic_9x5", Start: 5 * 9, End: 5*9 + 35, Slots: 5*9 + 36},
|
||||
5: {Name: "generic_9x6", Start: 6 * 9, End: 6*9 + 35, Slots: 6*9 + 36},
|
||||
}
|
Reference in New Issue
Block a user