github.com/df-mc/dragonfly@v0.9.13/server/entity/effect/regeneration.go (about)

     1  package effect
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/world"
     5  	"image/color"
     6  	"time"
     7  )
     8  
     9  // Regeneration is an effect that causes the entity that it is added to slowly regenerate health. The level
    10  // of the effect influences the speed with which the entity regenerates.
    11  type Regeneration struct {
    12  	nopLasting
    13  }
    14  
    15  // Apply applies health to the world.Entity passed if the duration of the effect is at the right tick.
    16  func (Regeneration) 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 {
    23  			l.Heal(1, RegenerationHealingSource{})
    24  		}
    25  	}
    26  }
    27  
    28  // RGBA ...
    29  func (Regeneration) RGBA() color.RGBA {
    30  	return color.RGBA{R: 0xcd, G: 0x5c, B: 0xab, A: 0xff}
    31  }
    32  
    33  // RegenerationHealingSource is a healing source used when an entity regenerates
    34  // health from an effect.Regeneration.
    35  type RegenerationHealingSource struct{}
    36  
    37  func (RegenerationHealingSource) HealingSource() {}