summaryrefslogtreecommitdiff
path: root/itemmeta.go
diff options
context:
space:
mode:
authoranon5 <anon5clam@protonmail.com>2021-09-19 12:45:50 +0000
committeranon5 <anon5clam@protonmail.com>2021-09-19 12:45:50 +0000
commitbcc58cb3048faa146ed0f90b330ebbe791d53b5c (patch)
tree2373852a0557ea584a62134159eb646b15619be3 /itemmeta.go
parentd6ba88b091f6c9be3b48ab0fe3f94211ee210700 (diff)
Switch to Minetest 5.4.1 protocol and other changes
Diffstat (limited to 'itemmeta.go')
-rw-r--r--itemmeta.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/itemmeta.go b/itemmeta.go
index 563de99..d5d5ff0 100644
--- a/itemmeta.go
+++ b/itemmeta.go
@@ -1,6 +1,9 @@
package mt
-import "strings"
+import (
+ "encoding/json"
+ "strings"
+)
type ItemMeta string
@@ -71,3 +74,25 @@ func (m *ItemMeta) SetField(name, value string) {
fields = append(fields, Field{name, value})
*m = NewItemMeta(fields)
}
+
+func (m ItemMeta) ToolCaps() (ToolCaps, bool) {
+ f, ok := m.Field("tool_capabilities")
+ if !ok {
+ return ToolCaps{}, false
+ }
+
+ var tc ToolCaps
+ if err := json.Unmarshal([]byte(f), &tc); err != nil {
+ return tc, false
+ }
+ return tc, true
+}
+
+func (m *ItemMeta) SetToolCaps(tc ToolCaps) {
+ b, err := tc.MarshalJSON()
+ if err != nil {
+ panic(err)
+ }
+
+ m.SetField("tool_capabilities", string(b))
+}