forked from Tnze/go-mc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
inventory.go
29 lines (23 loc) · 837 Bytes
/
inventory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package screen
import "errors"
type Inventory struct {
Slots [46]Slot
}
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] }