forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pumpkin.go
98 lines (82 loc) · 2.34 KB
/
pumpkin.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
94
95
96
97
98
package block
import (
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/cube"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/item"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/world"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/world/sound"
"github.com/go-gl/mathgl/mgl64"
)
// Pumpkin is a crop block. Interacting with shears results in the carved variant.
type Pumpkin struct {
solid
// Carved is whether the pumpkin is carved.
Carved bool
// Facing is the direction the pumpkin is facing.
Facing cube.Direction
}
// Instrument ...
func (p Pumpkin) Instrument() sound.Instrument {
if !p.Carved {
return sound.Didgeridoo()
}
return sound.Piano()
}
// UseOnBlock ...
func (p Pumpkin) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
pos, _, used = firstReplaceable(w, pos, face, p)
if !used {
return
}
p.Facing = user.Rotation().Direction().Opposite()
place(w, pos, p, user, ctx)
return placed(ctx)
}
// BreakInfo ...
func (p Pumpkin) BreakInfo() BreakInfo {
return newBreakInfo(1, alwaysHarvestable, axeEffective, oneOf(p))
}
// CompostChance ...
func (Pumpkin) CompostChance() float64 {
return 0.65
}
// Carve ...
func (p Pumpkin) Carve(f cube.Face) (world.Block, bool) {
return Pumpkin{Facing: f.Direction(), Carved: true}, !p.Carved
}
// Helmet ...
func (p Pumpkin) Helmet() bool {
return p.Carved
}
// DefencePoints ...
func (p Pumpkin) DefencePoints() float64 {
return 0
}
// Toughness ...
func (p Pumpkin) Toughness() float64 {
return 0
}
// KnockBackResistance ...
func (p Pumpkin) KnockBackResistance() float64 {
return 0
}
// EncodeItem ...
func (p Pumpkin) EncodeItem() (name string, meta int16) {
if p.Carved {
return "minecraft:carved_pumpkin", 0
}
return "minecraft:pumpkin", 0
}
// EncodeBlock ...
func (p Pumpkin) EncodeBlock() (name string, properties map[string]any) {
if p.Carved {
return "minecraft:carved_pumpkin", map[string]any{"minecraft:cardinal_direction": p.Facing.String()}
}
return "minecraft:pumpkin", map[string]any{"minecraft:cardinal_direction": p.Facing.String()}
}
func allPumpkins() (pumpkins []world.Block) {
for i := cube.Direction(0); i <= 3; i++ {
pumpkins = append(pumpkins, Pumpkin{Facing: i})
pumpkins = append(pumpkins, Pumpkin{Facing: i, Carved: true})
}
return
}