implementing storing chest data into Manager.Screens in bot/screen (#279)

This commit is contained in:
Lukas
2024-05-01 20:01:02 +08:00
committed by GitHub
parent 010ce516d7
commit d63cc1de3f
5 changed files with 225 additions and 5 deletions

39
bot/screen/chest.go Normal file
View File

@ -0,0 +1,39 @@
package screen
import (
"errors"
"github.com/Tnze/go-mc/chat"
"github.com/Tnze/go-mc/data/inventory"
)
type Chest struct {
Type inventory.InventoryID
Title chat.Message
Slots []Slot
Rows int
}
func (c *Chest) onSetSlot(i int, slot Slot) error {
if i < 0 || i >= len(c.Slots) {
return errors.New("slot index out of bounds")
}
c.Slots[i] = slot
return nil
}
func (c *Chest) onClose() error {
return nil
}
func (c *Chest) Container() []Slot {
return c.Slots[0 : c.Rows*9]
}
func (c *Chest) Main() []Slot {
return c.Slots[c.Rows*9 : c.Rows*9+27]
}
func (c *Chest) Hotbar() []Slot {
return c.Slots[c.Rows*9+27 : (c.Rows+4)*9]
}