-
Notifications
You must be signed in to change notification settings - Fork 140
/
chicken.go
45 lines (39 loc) · 937 Bytes
/
chicken.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package item
import (
"github.com/df-mc/dragonfly/server/entity/effect"
"github.com/df-mc/dragonfly/server/world"
"math/rand"
"time"
)
// Chicken is a food item obtained from chickens. It can be cooked in a furnace, smoker, or campfire.
type Chicken struct {
defaultFood
// Cooked is whether the chicken is cooked.
Cooked bool
}
// Consume ...
func (c Chicken) Consume(_ *world.World, co Consumer) Stack {
if c.Cooked {
co.Saturate(6, 7.2)
} else {
co.Saturate(2, 1.2)
if rand.Float64() < 0.3 {
co.AddEffect(effect.New(effect.Hunger{}, 1, 30*time.Second))
}
}
return Stack{}
}
// SmeltInfo ...
func (c Chicken) SmeltInfo() SmeltInfo {
if c.Cooked {
return SmeltInfo{}
}
return newFoodSmeltInfo(NewStack(Chicken{Cooked: true}, 1), 0.35)
}
// EncodeItem ...
func (c Chicken) EncodeItem() (name string, meta int16) {
if c.Cooked {
return "minecraft:cooked_chicken", 0
}
return "minecraft:chicken", 0
}