refactor package
This commit is contained in:
23
pkg/protocol/slot/component.go
Normal file
23
pkg/protocol/slot/component.go
Normal file
@ -0,0 +1,23 @@
|
||||
package slot
|
||||
|
||||
import pk "github.com/Tnze/go-mc/net/packet"
|
||||
|
||||
type Component interface {
|
||||
Type() ComponentID
|
||||
ID() string
|
||||
|
||||
pk.Field
|
||||
}
|
||||
|
||||
type ComponentID int32
|
||||
type componentCreator func() Component
|
||||
|
||||
var components = make(map[ComponentID]componentCreator)
|
||||
|
||||
func ComponentFromID(id ComponentID) Component {
|
||||
return components[id]()
|
||||
}
|
||||
|
||||
func RegisterComponent(c componentCreator) {
|
||||
components[c().Type()] = c
|
||||
}
|
Reference in New Issue
Block a user