-
Notifications
You must be signed in to change notification settings - Fork 140
/
coral.go
121 lines (106 loc) · 2.66 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/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
"time"
)
// Coral is a non solid block that comes in 5 variants.
type Coral struct {
empty
transparent
bassDrum
// 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, clickPos 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
}
// CanDisplace ...
func (c Coral) CanDisplace(b world.Liquid) bool {
_, water := b.(Water)
return water
}
// SideClosed ...
func (c Coral) SideClosed(pos, side cube.Pos, w *world.World) bool {
return false
}
// NeighbourUpdateTick ...
func (c Coral) NeighbourUpdateTick(pos, changedNeighbour cube.Pos, w *world.World) {
if !w.Block(pos.Side(cube.FaceDown)).Model().FaceSolid(pos.Side(cube.FaceDown), cube.FaceUp, w) {
w.BreakBlock(pos)
return
}
if c.Dead {
return
}
w.ScheduleBlockUpdate(pos, time.Second*5/2)
}
// ScheduledTick ...
func (c Coral) ScheduledTick(pos cube.Pos, w *world.World) {
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
}
}
})
if !adjacentWater {
c.Dead = true
w.PlaceBlock(pos, c)
}
}
// BreakInfo ...
func (c Coral) BreakInfo() BreakInfo {
// TODO: Silk touch.
return newBreakInfo(0, neverHarvestable, nothingEffective, simpleDrops())
}
// EncodeBlock ...
func (c Coral) EncodeBlock() (name string, properties map[string]interface{}) {
return "minecraft:coral", map[string]interface{}{"coral_color": c.Type.Colour().String(), "dead_bit": c.Dead}
}
// EncodeItem ...
func (c Coral) EncodeItem() (name string, meta int16) {
if c.Dead {
return "minecraft:coral", int16(c.Type.Uint8() | 8)
}
return "minecraft:coral", int16(c.Type.Uint8())
}
// 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
}