-
Notifications
You must be signed in to change notification settings - Fork 140
/
cake.go
93 lines (78 loc) · 2.04 KB
/
cake.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package block
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/block/model"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
)
// Cake is an edible block.
type Cake struct {
transparent
// Bites is the amount of bites taken out of the cake.
Bites int
}
// CanDisplace ...
func (c Cake) CanDisplace(b world.Liquid) bool {
_, water := b.(Water)
return water
}
// SideClosed ...
func (c Cake) SideClosed(cube.Pos, cube.Pos, *world.World) bool {
return false
}
// UseOnBlock ...
func (c Cake) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) bool {
pos, _, used := firstReplaceable(w, pos, face, c)
if !used {
return false
}
if _, air := w.Block(pos.Side(cube.FaceDown)).(Air); air {
return false
}
place(w, pos, c, user, ctx)
return placed(ctx)
}
// NeighbourUpdateTick ...
func (c Cake) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if _, air := w.Block(pos.Side(cube.FaceDown)).(Air); air {
w.BreakBlock(pos)
}
}
// Activate ...
func (c Cake) Activate(pos cube.Pos, _ cube.Face, w *world.World, u item.User) {
if i, ok := u.(interface {
Saturate(food int, saturation float64)
}); ok {
i.Saturate(2, 0.4)
c.Bites++
if c.Bites > 6 {
w.BreakBlockWithoutParticles(pos)
return
}
w.PlaceBlock(pos, c)
}
}
// BreakInfo ...
func (c Cake) BreakInfo() BreakInfo {
return newBreakInfo(0.5, alwaysHarvestable, nothingEffective, simpleDrops())
}
// EncodeItem ...
func (c Cake) EncodeItem() (name string, meta int16) {
return "minecraft:cake", 0
}
// EncodeBlock ...
func (c Cake) EncodeBlock() (name string, properties map[string]interface{}) {
return "minecraft:cake", map[string]interface{}{"bite_counter": int32(c.Bites)}
}
// Model ...
func (c Cake) Model() world.BlockModel {
return model.Cake{Bites: c.Bites}
}
// allCake ...
func allCake() (cake []world.Block) {
for bites := 0; bites < 7; bites++ {
cake = append(cake, Cake{Bites: bites})
}
return
}