1.19.2 chat support
This commit is contained in:
31
registry/registry.go
Normal file
31
registry/registry.go
Normal file
@ -0,0 +1,31 @@
|
||||
package registry
|
||||
|
||||
type Registry[E any] struct {
|
||||
Type string `nbt:"type"`
|
||||
Value []struct {
|
||||
Name string `nbt:"name"`
|
||||
ID int32 `nbt:"id"`
|
||||
Element E `nbt:"element"`
|
||||
} `nbt:"value"`
|
||||
}
|
||||
|
||||
func (r *Registry[E]) Find(name string) (int32, *E) {
|
||||
for i := range r.Value {
|
||||
if r.Value[i].Name == name {
|
||||
return int32(i), &r.Value[i].Element
|
||||
}
|
||||
}
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
func (r *Registry[E]) FindByID(id int32) *E {
|
||||
if id >= 0 && id < int32(len(r.Value)) && r.Value[id].ID == id {
|
||||
return &r.Value[id].Element
|
||||
}
|
||||
for i := range r.Value {
|
||||
if r.Value[i].ID == id {
|
||||
return &r.Value[i].Element
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user