forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheat_seeds.go
90 lines (77 loc) · 2.26 KB
/
wheat_seeds.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
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/particle"
"github.com/go-gl/mathgl/mgl64"
"math/rand"
)
// WheatSeeds are a crop that can be harvested to craft bread, cake, & cookies.
type WheatSeeds struct {
crop
}
// SameCrop ...
func (WheatSeeds) SameCrop(c Crop) bool {
_, ok := c.(WheatSeeds)
return ok
}
// BoneMeal ...
func (s WheatSeeds) BoneMeal(pos cube.Pos, w *world.World) bool {
if s.Growth == 7 {
return false
}
s.Growth = min(s.Growth+rand.Intn(4)+2, 7)
w.SetBlock(pos, s, nil)
return true
}
// UseOnBlock ...
func (s WheatSeeds) 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, s)
if !used {
return false
}
if _, ok := w.Block(pos.Side(cube.FaceDown)).(Farmland); !ok {
return false
}
place(w, pos, s, user, ctx)
return placed(ctx)
}
// BreakInfo ...
func (s WheatSeeds) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, func(item.Tool, []item.Enchantment) []item.Stack {
if s.Growth < 7 {
return []item.Stack{item.NewStack(s, 1)}
}
return []item.Stack{item.NewStack(item.Wheat{}, 1), item.NewStack(s, rand.Intn(4)+1)}
})
}
// CompostChance ...
func (WheatSeeds) CompostChance() float64 {
return 0.3
}
// EncodeItem ...
func (s WheatSeeds) EncodeItem() (name string, meta int16) {
return "minecraft:wheat_seeds", 0
}
// RandomTick ...
func (s WheatSeeds) RandomTick(pos cube.Pos, w *world.World, r *rand.Rand) {
if w.Light(pos) < 8 {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: s})
} else if s.Growth < 7 && r.Float64() <= s.CalculateGrowthChance(pos, w) {
s.Growth++
w.SetBlock(pos, s, nil)
}
}
// EncodeBlock ...
func (s WheatSeeds) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:wheat", map[string]any{"growth": int32(s.Growth)}
}
// allWheat ...
func allWheat() (wheat []world.Block) {
for i := 0; i <= 7; i++ {
wheat = append(wheat, WheatSeeds{crop{Growth: i}})
}
return
}