github.com/df-mc/dragonfly@v0.9.13/server/entity/effect/register.go (about) 1 package effect 2 3 import ( 4 "reflect" 5 ) 6 7 // Register registers an Effect with a specific ID to translate from and to on disk and network. An Effect 8 // instance may be created by creating a struct instance in this package like 9 // effect.Regeneration{}. 10 func Register(id int, e Type) { 11 effects[id] = e 12 effectIds[reflect.TypeOf(e)] = id 13 } 14 15 // init registers all implemented effects. 16 func init() { 17 Register(1, Speed{}) 18 Register(2, Slowness{}) 19 Register(3, Haste{}) 20 Register(4, MiningFatigue{}) 21 Register(5, Strength{}) 22 Register(6, InstantHealth{}) 23 Register(7, InstantDamage{}) 24 Register(8, JumpBoost{}) 25 Register(9, Nausea{}) 26 Register(10, Regeneration{}) 27 Register(11, Resistance{}) 28 Register(12, FireResistance{}) 29 Register(13, WaterBreathing{}) 30 Register(14, Invisibility{}) 31 Register(15, Blindness{}) 32 Register(16, NightVision{}) 33 Register(17, Hunger{}) 34 Register(18, Weakness{}) 35 Register(19, Poison{}) 36 Register(20, Wither{}) 37 Register(21, HealthBoost{}) 38 Register(22, Absorption{}) 39 Register(23, Saturation{}) 40 Register(24, Levitation{}) 41 Register(25, FatalPoison{}) 42 Register(26, ConduitPower{}) 43 Register(27, SlowFalling{}) 44 // TODO: (28) Bad omen. (Requires villages ...) 45 // TODO: (29) Hero of the village. (Requires villages ...) 46 Register(30, Darkness{}) 47 } 48 49 var ( 50 effects = map[int]Type{} 51 effectIds = map[reflect.Type]int{} 52 ) 53 54 // ByID attempts to return an effect by the ID it was registered with. If found, the effect found 55 // is returned and the bool true. 56 func ByID(id int) (Type, bool) { 57 effect, ok := effects[id] 58 return effect, ok 59 } 60 61 // ID attempts to return the ID an effect was registered with. If found, the id is returned and 62 // the bool true. 63 func ID(e Type) (int, bool) { 64 id, ok := effectIds[reflect.TypeOf(e)] 65 return id, ok 66 }