forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
double_tall_grass.go
110 lines (97 loc) · 3.18 KB
/
double_tall_grass.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
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"
)
// DoubleTallGrass is a two-block high variety of grass.
type DoubleTallGrass struct {
transparent
replaceable
empty
// UpperPart is set if the plant is the upper part.
UpperPart bool
// Type is the type of double tall grass.
Type DoubleTallGrassType
}
// HasLiquidDrops ...
func (d DoubleTallGrass) HasLiquidDrops() bool {
return true
}
// NeighbourUpdateTick ...
func (d DoubleTallGrass) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if d.UpperPart {
if bottom, ok := w.Block(pos.Side(cube.FaceDown)).(DoubleTallGrass); !ok || bottom.Type != d.Type || bottom.UpperPart {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: d})
}
return
}
if upper, ok := w.Block(pos.Side(cube.FaceUp)).(DoubleTallGrass); !ok || upper.Type != d.Type || !upper.UpperPart {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: d})
return
}
if !supportsVegetation(d, w.Block(pos.Side(cube.FaceDown))) {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: d})
}
}
// UseOnBlock ...
func (d DoubleTallGrass) 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, d)
if !used {
return false
}
if !replaceableWith(w, pos.Side(cube.FaceUp), d) {
return false
}
if !supportsVegetation(d, w.Block(pos.Side(cube.FaceDown))) {
return false
}
place(w, pos, d, user, ctx)
place(w, pos.Side(cube.FaceUp), DoubleTallGrass{Type: d.Type, UpperPart: true}, user, ctx)
return placed(ctx)
}
// FlammabilityInfo ...
func (d DoubleTallGrass) FlammabilityInfo() FlammabilityInfo {
return newFlammabilityInfo(60, 100, true)
}
// BreakInfo ...
func (d DoubleTallGrass) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, func(t item.Tool, enchantments []item.Enchantment) []item.Stack {
if t.ToolType() == item.TypeShears || hasSilkTouch(enchantments) {
return []item.Stack{item.NewStack(d, 1)}
}
if rand.Float32() > 0.57 {
return []item.Stack{item.NewStack(WheatSeeds{}, 1)}
}
return nil
})
}
// CompostChance ...
func (d DoubleTallGrass) CompostChance() float64 {
if d.Type == FernDoubleTallGrass() {
return 0.65
}
return 0.5
}
// EncodeItem ...
func (d DoubleTallGrass) EncodeItem() (name string, meta int16) {
return "minecraft:double_plant", int16(d.Type.Uint8() + 2)
}
// EncodeBlock ...
func (d DoubleTallGrass) EncodeBlock() (string, map[string]any) {
return "minecraft:double_plant", map[string]any{"double_plant_type": d.Type.String(), "upper_block_bit": d.UpperPart}
}
// allDoubleTallGrass ...
func allDoubleTallGrass() (b []world.Block) {
for _, g := range DoubleTallGrassTypes() {
b = append(b, DoubleTallGrass{Type: g})
b = append(b, DoubleTallGrass{Type: g, UpperPart: true})
}
return
}