multiserver/hand.go

52 lines
867 B
Go
Raw Normal View History

2021-02-25 00:11:37 -08:00
package main
import (
2021-02-28 12:59:55 -08:00
"errors"
2021-02-25 00:11:37 -08:00
"github.com/anon55555/mt"
)
2021-02-28 12:59:55 -08:00
var ErrNoHandCaps = errors.New("hand tool capabilities missing")
2021-02-25 00:11:37 -08:00
func (p *Peer) UpdateHandCapabs() error {
l := p.Inv().List("hand")
if l == nil {
*p.inv = mt.Inv(append([]mt.NamedInvList(*p.inv), mt.NamedInvList{
Name: "hand",
InvList: mt.InvList{
Width: 1,
},
}))
l = p.Inv().List("hand")
}
var hand mt.Stack
2021-02-25 00:11:37 -08:00
if len(l.Stacks) == 1 && l.Stacks[0].Name != "multiserver:hand_"+p.ServerName() {
hand = l.Stacks[0]
2021-02-28 12:59:55 -08:00
caps := handcapabs[p.ServerName()]
if caps == nil {
return ErrNoHandCaps
}
s, err := caps.SerializeJSON()
if err != nil {
return err
}
2021-02-25 02:21:32 -08:00
hand.SetField("tool_capabilities", s)
} else {
hand = mt.Stack{
Item: mt.Item{
Name: "multiserver:hand_" + p.ServerName(),
},
Count: 1,
}
}
2021-02-25 02:21:32 -08:00
2021-02-25 00:11:37 -08:00
l.Stacks = []mt.Stack{hand}
return nil
}