github.com/df-mc/dragonfly@v0.9.13/server/entity/effect/poison.go (about) 1 package effect 2 3 import ( 4 "github.com/df-mc/dragonfly/server/world" 5 "image/color" 6 "time" 7 ) 8 9 // Poison is a lasting effect that causes the affected entity to lose health gradually. Poison cannot kill, 10 // unlike FatalPoison. 11 type Poison struct { 12 nopLasting 13 } 14 15 // Apply ... 16 func (Poison) Apply(e world.Entity, lvl int, d time.Duration) { 17 interval := 50 >> (lvl - 1) 18 if interval < 1 { 19 interval = 1 20 } 21 if tickDuration(d)%interval == 0 { 22 if l, ok := e.(living); ok && l.Health() > 1 { 23 l.Hurt(1, PoisonDamageSource{}) 24 } 25 } 26 } 27 28 // RGBA ... 29 func (Poison) RGBA() color.RGBA { 30 return color.RGBA{R: 0x4e, G: 0x93, B: 0x31, A: 0xff} 31 } 32 33 // PoisonDamageSource is used for damage caused by an effect.Poison or 34 // effect.FatalPoison applied to an entity. 35 type PoisonDamageSource struct { 36 // Fatal specifies if the damage was caused by effect.FatalPoison and if 37 // the damage could therefore kill the entity. 38 Fatal bool 39 } 40 41 func (PoisonDamageSource) ReducedByResistance() bool { return true } 42 func (PoisonDamageSource) ReducedByArmour() bool { return false } 43 func (PoisonDamageSource) Fire() bool { return false }