26ed99fda6
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
36 lines
854 B
Go
36 lines
854 B
Go
package item
|
|
|
|
import (
|
|
"github.com/df-mc/dragonfly/server/entity/effect"
|
|
"github.com/df-mc/dragonfly/server/world"
|
|
"time"
|
|
)
|
|
|
|
// GoldenApple is a special food item that bestows beneficial effects.
|
|
type GoldenApple struct{}
|
|
|
|
// AlwaysConsumable ...
|
|
func (e GoldenApple) AlwaysConsumable() bool {
|
|
return true
|
|
}
|
|
|
|
// ConsumeDuration ...
|
|
func (e GoldenApple) ConsumeDuration() time.Duration {
|
|
return DefaultConsumeDuration
|
|
}
|
|
|
|
// Consume ...
|
|
func (e GoldenApple) Consume(_ *world.Tx, c Consumer) Stack {
|
|
c.Saturate(4, 9.6)
|
|
prev := c.Absorption()
|
|
c.AddEffect(effect.New(effect.Absorption, 1, 2*time.Minute))
|
|
c.SetAbsorption(max(prev, min(prev+4, 16)))
|
|
c.AddEffect(effect.New(effect.Regeneration, 2, 5*time.Second))
|
|
return Stack{}
|
|
}
|
|
|
|
// EncodeItem ...
|
|
func (e GoldenApple) EncodeItem() (name string, meta int16) {
|
|
return "minecraft:golden_apple", 0
|
|
}
|