forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flower.go
122 lines (106 loc) · 2.96 KB
/
flower.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package block
import (
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/cube"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/entity/effect"
"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"
"time"
)
// Flower is a non-solid plant that occur in a variety of shapes and colours. They are primarily used for decoration
// and crafted into dyes.
type Flower struct {
empty
transparent
// Type is the type of flower.
Type FlowerType
}
// EntityInside ...
func (f Flower) EntityInside(_ cube.Pos, _ *world.World, e world.Entity) {
if f.Type == WitherRose() {
if living, ok := e.(interface {
AddEffect(effect.Effect)
}); ok {
living.AddEffect(effect.New(effect.Wither{}, 1, 2*time.Second))
}
}
}
// BoneMeal ...
func (f Flower) BoneMeal(pos cube.Pos, w *world.World) (success bool) {
if f.Type == WitherRose() {
return
}
for i := 0; i < 8; i++ {
p := pos.Add(cube.Pos{rand.Intn(7) - 3, rand.Intn(3) - 1, rand.Intn(7) - 3})
if _, ok := w.Block(p).(Air); !ok {
continue
}
if _, ok := w.Block(p.Side(cube.FaceDown)).(Grass); !ok {
continue
}
flowerType := f.Type
if rand.Float64() < 0.1 {
if f.Type == Dandelion() {
flowerType = Poppy()
} else if f.Type == Poppy() {
flowerType = Dandelion()
}
}
w.SetBlock(p, Flower{Type: flowerType}, nil)
success = true
}
return
}
// NeighbourUpdateTick ...
func (f Flower) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if !supportsVegetation(f, w.Block(pos.Side(cube.FaceDown))) {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: f})
dropItem(w, item.NewStack(f, 1), pos.Vec3Centre())
}
}
// UseOnBlock ...
func (f Flower) 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, f)
if !used {
return false
}
if !supportsVegetation(f, w.Block(pos.Side(cube.FaceDown))) {
return false
}
place(w, pos, f, user, ctx)
return placed(ctx)
}
// HasLiquidDrops ...
func (Flower) HasLiquidDrops() bool {
return true
}
// FlammabilityInfo ...
func (f Flower) FlammabilityInfo() FlammabilityInfo {
return newFlammabilityInfo(60, 100, false)
}
// BreakInfo ...
func (f Flower) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, oneOf(f))
}
// CompostChance ...
func (Flower) CompostChance() float64 {
return 0.65
}
// EncodeItem ...
func (f Flower) EncodeItem() (name string, meta int16) {
return "minecraft:" + f.Type.String(), 0
}
// EncodeBlock ...
func (f Flower) EncodeBlock() (string, map[string]any) {
return "minecraft:" + f.Type.String(), nil
}
// allFlowers ...
func allFlowers() (b []world.Block) {
for _, f := range FlowerTypes() {
b = append(b, Flower{Type: f})
}
return
}