Documentation ¶
Index ¶
- type Registry
- func (r *Registry) Add(id int32, item interface{})
- func (r *Registry) AddAt(index, id int32, item interface{})
- func (r *Registry) Copy() *Registry
- func (r *Registry) Get(id int32) (item interface{}, index int32, ok bool)
- func (r *Registry) GetReverse(index int32) (item interface{}, id int32, ok bool)
- func (r *Registry) Insert(index, id int32, item interface{})
- func (r *Registry) List() []interface{}
- func (r *Registry) Move(id, new_index int32)
- func (r *Registry) Remove(index int32)
- func (r *Registry) Set(id int32, item interface{})
- func (r *Registry) String() string
- func (r *Registry) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Add ¶
This registers a new item. id should be a constant, defined in user-space code (probably with iota). id is not used for sorting, the order of items depends on the order that Add is called. So, for packets, ID would be the grpc packet id, which doesn't need to be the same as any minecraft packet id. If id is -1, then this is treated as a placeholder, and nil will be inserted into the internal array.
func (*Registry) AddAt ¶
This is an odd function. It turns out that 1.8 starts entity ids off at id 50, so I don't want to call Add(-1, nil) 50 times. This function will do a couple things: If index is <= len(r.items), then this is a nop. If it is == len(r.items) + 1, then this is the same as Add(). If it is anything else, then it will add a bunch of nil entries, and then item at the end. So this is simply the avoid calling Add(-1, nil) a lot. For example, after you call AddAt(id, 50, item), then the next call to Add() will put that new item at index 51.
func (*Registry) Get ¶
This gets the item at the id, and returns false if the id is not within the registry.
func (*Registry) GetReverse ¶
This gets an item based on it's index. The returned int32 is the new id.
func (*Registry) Insert ¶
This inserts a new item at index, shifting all packets with a greater index down by one. Useful if a new version adds an item near the beginning, and you need to shift all the other items down by one.
Index should be the old item id (say, and old block id), and id should be the constant defined in user space code (a custom constant refering to that block). The old ids greater than index will all be shifted down by one, and then this new item will be inserted. The new ids will not be modified.
func (*Registry) List ¶
func (r *Registry) List() []interface{}
This lists all elements added to the registry, in the order that they were addded.
func (*Registry) Move ¶
This moves an item around within the registry. Useful for when a packet changes id, or an entity changes name. The first argument is the user defined id that you want to access. The second argument is the new index you would like to move that item to. This does the same thing as Remove() then Insert(), but it is more efficient.
func (*Registry) Remove ¶
Will remove an item from the registry. This will decrease all items that have a greater index down by one.