items and struture loading
This commit is contained in:
@@ -69,6 +69,7 @@ func LookupBlockByStateId(version string, stateId int32) (block *Block, ok bool)
|
||||
if b.MinStateId <= stateId && stateId <= b.MaxStateId {
|
||||
block = b
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -100,6 +101,8 @@ func FromBlockState(version string, stateId int32) (b *Block, stateData map[stri
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: mc stores these as strings so we will do the same
|
||||
|
||||
func mcDataBlockStateTypeParse(n int32, s *BlockState) (v any, err error) {
|
||||
switch s.Type {
|
||||
case "int":
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package data
|
||||
|
||||
// {
|
||||
// "id": 2,
|
||||
// "name": "granite",
|
||||
// "displayName": "Granite",
|
||||
// "stackSize": 64
|
||||
// },
|
||||
|
||||
type Item struct {
|
||||
Id int32
|
||||
Name string
|
||||
DisplayName string
|
||||
StackSize int32
|
||||
}
|
||||
|
||||
var ItemsCache = make(map[string][]*Item)
|
||||
|
||||
func ItemsForVersion(v string) (ret []*Item) {
|
||||
var ok bool
|
||||
if ret, ok = ItemsCache[v]; ok {
|
||||
return
|
||||
}
|
||||
var b []*Item
|
||||
must(LoadVersionedJson(v, "items", &b))
|
||||
ItemsCache[v] = b
|
||||
return b
|
||||
}
|
||||
|
||||
func LookupItemById(version string, id int32) (item *Item, ok bool) {
|
||||
for _, i := range ItemsForVersion(version) {
|
||||
if i.Id == id {
|
||||
item = i
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func LookupItemByName(version string, name string) (item *Item, ok bool) {
|
||||
for _, i := range ItemsForVersion(version) {
|
||||
if i.Name == name {
|
||||
item = i
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user