fix item displays name on example/daze
This commit is contained in:
@ -21,7 +21,7 @@ type Client struct {
|
||||
// These are filled when login process
|
||||
Name string
|
||||
UUID uuid.UUID
|
||||
Registries registry.NetworkCodec
|
||||
Registries registry.Registries
|
||||
Cookies map[string][]byte
|
||||
|
||||
// Ingame packet handlers
|
||||
|
17
data/registryid/bootstrap/builtinregistries.go
Normal file
17
data/registryid/bootstrap/builtinregistries.go
Normal file
@ -0,0 +1,17 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/Tnze/go-mc/data/registryid"
|
||||
"github.com/Tnze/go-mc/level/block"
|
||||
"github.com/Tnze/go-mc/registry"
|
||||
)
|
||||
|
||||
func RegisterBlocks(reg *registry.Registry[block.Block]) {
|
||||
reg.Clear()
|
||||
for i, key := range registryid.Block {
|
||||
id, val := reg.Put(key, block.FromID[key])
|
||||
if int32(i) != id || val == nil || *val == nil {
|
||||
panic("register blocks failed")
|
||||
}
|
||||
}
|
||||
}
|
@ -23,8 +23,8 @@ import (
|
||||
"github.com/Tnze/go-mc/bot/screen"
|
||||
"github.com/Tnze/go-mc/bot/world"
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
"github.com/Tnze/go-mc/data/item"
|
||||
_ "github.com/Tnze/go-mc/data/lang/zh-cn"
|
||||
"github.com/Tnze/go-mc/data/registryid"
|
||||
"github.com/Tnze/go-mc/level"
|
||||
)
|
||||
|
||||
@ -161,11 +161,14 @@ func onScreenSlotChange(id, index int) error {
|
||||
container, ok := screenManager.Screens[id]
|
||||
if ok {
|
||||
// Currently, only inventory container is supported
|
||||
switch container.(type) {
|
||||
switch container := container.(type) {
|
||||
case *screen.Inventory:
|
||||
slot := container.(*screen.Inventory).Slots[index]
|
||||
itemInfo := item.ByID[item.ID(slot.ID)]
|
||||
log.Printf("Slot: Screen[%d].Slot[%d]: [%v] * %d | NBT: %v", id, index, itemInfo, slot.Count, slot.NBT)
|
||||
slot := container.Slots[index]
|
||||
itemName := "nil"
|
||||
if slot.ID >= 0 && int(slot.ID) < len(registryid.Item) {
|
||||
itemName = registryid.Item[slot.ID]
|
||||
}
|
||||
log.Printf("Slot: Screen[%d].Slot[%d]: [%v] * %d | NBT: %v", id, index, itemName, slot.Count, slot.NBT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
type NetworkCodec struct {
|
||||
type Registries struct {
|
||||
ChatType Registry[ChatType] `registry:"minecraft:chat_type"`
|
||||
DamageType Registry[DamageType] `registry:"minecraft:damage_type"`
|
||||
DimensionType Registry[Dimension] `registry:"minecraft:dimension_type"`
|
||||
@ -23,8 +23,8 @@ type NetworkCodec struct {
|
||||
JukeboxSong Registry[nbt.RawMessage] `registry:"minecraft:jukebox_song"`
|
||||
}
|
||||
|
||||
func NewNetworkCodec() NetworkCodec {
|
||||
return NetworkCodec{
|
||||
func NewNetworkCodec() Registries {
|
||||
return Registries{
|
||||
ChatType: NewRegistry[ChatType](),
|
||||
DamageType: NewRegistry[DamageType](),
|
||||
DimensionType: NewRegistry[Dimension](),
|
||||
@ -79,7 +79,7 @@ type RegistryCodec interface {
|
||||
ReadTagsFrom(r io.Reader) (int64, error)
|
||||
}
|
||||
|
||||
func (c *NetworkCodec) Registry(id string) RegistryCodec {
|
||||
func (c *Registries) Registry(id string) RegistryCodec {
|
||||
codecVal := reflect.ValueOf(c).Elem()
|
||||
codecTyp := codecVal.Type()
|
||||
numField := codecVal.NumField()
|
||||
|
@ -13,7 +13,7 @@ type ConfigHandler interface {
|
||||
}
|
||||
|
||||
type Configurations struct {
|
||||
Registries registry.NetworkCodec
|
||||
Registries registry.Registries
|
||||
}
|
||||
|
||||
func (c *Configurations) AcceptConfig(conn *net.Conn) error {
|
||||
|
Reference in New Issue
Block a user