-
Notifications
You must be signed in to change notification settings - Fork 140
/
lantern.go
115 lines (101 loc) · 2.79 KB
/
lantern.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
package block
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/block/model"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
)
// Lantern is a light emitting block.
type Lantern struct {
transparent
// Hanging determines if a lantern is hanging off a block.
Hanging bool
// Type of fire lighting the lantern.
Type FireType
}
// Model ...
func (l Lantern) Model() world.BlockModel {
return model.Lantern{Hanging: l.Hanging}
}
// NeighbourUpdateTick ...
func (l Lantern) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if l.Hanging {
up := pos.Side(cube.FaceUp)
if !w.Block(up).Model().FaceSolid(up, cube.FaceDown, w) {
w.BreakBlockWithoutParticles(pos)
}
} else {
down := pos.Side(cube.FaceDown)
if !w.Block(down).Model().FaceSolid(down, cube.FaceUp, w) {
w.BreakBlockWithoutParticles(pos)
}
}
}
// LightEmissionLevel ...
func (l Lantern) LightEmissionLevel() uint8 {
return l.Type.LightLevel()
}
// UseOnBlock ...
func (l Lantern) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) bool {
pos, face, used := firstReplaceable(w, pos, face, l)
if !used {
return false
}
if face == cube.FaceDown {
upPos := pos.Side(cube.FaceUp)
if !w.Block(upPos).Model().FaceSolid(upPos, cube.FaceDown, w) {
face = cube.FaceUp
}
}
if face != cube.FaceDown {
downPos := pos.Side(cube.FaceDown)
if !w.Block(downPos).Model().FaceSolid(downPos, cube.FaceUp, w) {
return false
}
}
l.Hanging = face == cube.FaceDown
place(w, pos, l, user, ctx)
return placed(ctx)
}
// CanDisplace ...
func (l Lantern) CanDisplace(b world.Liquid) bool {
_, water := b.(Water)
return water
}
// SideClosed ...
func (l Lantern) SideClosed(cube.Pos, cube.Pos, *world.World) bool {
return false
}
// BreakInfo ...
func (l Lantern) BreakInfo() BreakInfo {
return newBreakInfo(3.5, pickaxeHarvestable, pickaxeEffective, oneOf(l))
}
// EncodeItem ...
func (l Lantern) EncodeItem() (name string, meta int16) {
switch l.Type {
case NormalFire():
return "minecraft:lantern", 0
case SoulFire():
return "minecraft:soul_lantern", 0
}
panic("invalid fire type")
}
// EncodeBlock ...
func (l Lantern) EncodeBlock() (name string, properties map[string]interface{}) {
switch l.Type {
case NormalFire():
return "minecraft:lantern", map[string]interface{}{"hanging": l.Hanging}
case SoulFire():
return "minecraft:soul_lantern", map[string]interface{}{"hanging": l.Hanging}
}
panic("invalid fire type")
}
// allLanterns ...
func allLanterns() (lanterns []world.Block) {
for _, f := range FireTypes() {
lanterns = append(lanterns, Lantern{Hanging: false, Type: f})
lanterns = append(lanterns, Lantern{Hanging: true, Type: f})
}
return
}