registry

package
v0.0.0-...-2a33acd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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 New

func New() *Registry

func (*Registry) Add

func (r *Registry) Add(id int32, item interface{})

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

func (r *Registry) AddAt(index, id int32, item interface{})

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) Copy

func (r *Registry) Copy() *Registry

func (*Registry) Get

func (r *Registry) Get(id int32) (item interface{}, index int32, ok bool)

This gets the item at the id, and returns false if the id is not within the registry.

func (*Registry) GetReverse

func (r *Registry) GetReverse(index int32) (item interface{}, id int32, ok bool)

This gets an item based on it's index. The returned int32 is the new id.

func (*Registry) Insert

func (r *Registry) Insert(index, id int32, item interface{})

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

func (r *Registry) Move(id, new_index int32)

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

func (r *Registry) Remove(index int32)

Will remove an item from the registry. This will decrease all items that have a greater index down by one.

func (*Registry) Set

func (r *Registry) Set(id int32, item interface{})

This overrides an item. Useful for if a packet slightly changes between versions.

The old id is infered, since this should only be used to override packets. If you call this function, and id is not in the registry, it will panic. To add a new item, use Add or Insert instead.

func (*Registry) String

func (r *Registry) String() string

func (*Registry) Validate

func (r *Registry) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL