forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coral.go
121 lines (107 loc) · 2.81 KB
/
coral.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
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"
"time"
)
// Coral is a non-solid block that comes in 5 variants.
type Coral struct {
empty
transparent
bassDrum
sourceWaterDisplacer
// Type is the type of coral of the block.
Type CoralType
// Dead is whether the coral is dead.
Dead bool
}
// UseOnBlock ...
func (c Coral) 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 !w.Block(pos.Side(cube.FaceDown)).Model().FaceSolid(pos.Side(cube.FaceDown), cube.FaceUp, w) {
return false
}
if liquid, ok := w.Liquid(pos); ok {
if water, ok := liquid.(Water); ok {
if water.Depth != 8 {
return false
}
}
}
place(w, pos, c, user, ctx)
return placed(ctx)
}
// HasLiquidDrops ...
func (c Coral) HasLiquidDrops() bool {
return false
}
// SideClosed ...
func (c Coral) SideClosed(cube.Pos, cube.Pos, *world.World) bool {
return false
}
// NeighbourUpdateTick ...
func (c Coral) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if !w.Block(pos.Side(cube.FaceDown)).Model().FaceSolid(pos.Side(cube.FaceDown), cube.FaceUp, w) {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: c})
return
}
if c.Dead {
return
}
w.ScheduleBlockUpdate(pos, time.Second*5/2)
}
// ScheduledTick ...
func (c Coral) ScheduledTick(pos cube.Pos, w *world.World, _ *rand.Rand) {
if c.Dead {
return
}
adjacentWater := false
pos.Neighbours(func(neighbour cube.Pos) {
if liquid, ok := w.Liquid(neighbour); ok {
if _, ok := liquid.(Water); ok {
adjacentWater = true
}
}
}, w.Range())
if !adjacentWater {
c.Dead = true
w.SetBlock(pos, c, nil)
}
}
// BreakInfo ...
func (c Coral) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, silkTouchOnlyDrop(c))
}
// EncodeBlock ...
func (c Coral) EncodeBlock() (name string, properties map[string]any) {
if c.Dead {
return "minecraft:dead_" + c.Type.String() + "_coral", nil
}
return "minecraft:" + c.Type.String() + "_coral", nil
}
// EncodeItem ...
func (c Coral) EncodeItem() (name string, meta int16) {
if c.Dead {
return "minecraft:dead_" + c.Type.String() + "_coral", 0
}
return "minecraft:" + c.Type.String() + "_coral", 0
}
// allCoral returns a list of all coral block variants
func allCoral() (c []world.Block) {
f := func(dead bool) {
for _, t := range CoralTypes() {
c = append(c, Coral{Type: t, Dead: dead})
}
}
f(true)
f(false)
return
}