Enhance support of screens

This commit is contained in:
Tnze
2021-07-04 12:38:24 +08:00
parent ebc44e7c8b
commit 7cfe5145d2
6 changed files with 148 additions and 63 deletions

View File

@ -1,16 +1,29 @@
package screen
import (
"fmt"
"github.com/Tnze/go-mc/data/item"
"github.com/Tnze/go-mc/nbt"
)
import "errors"
type Inventory struct {
Slots [46]Slot
}
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)
func (inv *Inventory) onClose() error {
return nil
}
func (inv *Inventory) onSetSlot(i int, s Slot) error {
if i < 0 || i >= len(inv.Slots) {
return errors.New("slot index out of bounds")
}
inv.Slots[i] = s
return nil
}
func (inv *Inventory) CraftingOutput() *Slot { return &inv.Slots[0] }
func (inv *Inventory) CraftingInput() []Slot { return inv.Slots[1 : 1+4] }
// Armor returns to the armor section of the Inventory.
// The length is 4, which are head, chest, legs and feet.
func (inv *Inventory) Armor() []Slot { return inv.Slots[5 : 5+4] }
func (inv *Inventory) Main() []Slot { return inv.Slots[9 : 9+3*9] }
func (inv *Inventory) Hotbar() []Slot { return inv.Slots[36 : 36+9] }
func (inv *Inventory) Offhand() *Slot { return &inv.Slots[45] }