-
Notifications
You must be signed in to change notification settings - Fork 140
/
torch.go
115 lines (103 loc) · 2.73 KB
/
torch.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/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
)
// Torch are non-solid blocks that emit light.
type Torch struct {
transparent
empty
// Facing is the direction from the torch to the block.
Facing cube.Face
// Type is the type of fire lighting the torch.
Type FireType
}
// BreakInfo ...
func (t Torch) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, oneOf(t))
}
// LightEmissionLevel ...
func (t Torch) LightEmissionLevel() uint8 {
switch t.Type {
case NormalFire():
return 14
default:
return t.Type.LightLevel()
}
}
// UseOnBlock ...
func (t Torch) UseOnBlock(pos cube.Pos, face cube.Face, clickPos mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) bool {
pos, face, used := firstReplaceable(w, pos, face, t)
if !used {
return false
}
if face == cube.FaceDown {
return false
}
if _, ok := w.Block(pos).(world.Liquid); ok {
return false
}
if !w.Block(pos.Side(face.Opposite())).Model().FaceSolid(pos.Side(face.Opposite()), face, w) {
found := false
for _, i := range []cube.Face{cube.FaceSouth, cube.FaceWest, cube.FaceNorth, cube.FaceEast, cube.FaceDown} {
if w.Block(pos.Side(i)).Model().FaceSolid(pos.Side(i), i.Opposite(), w) {
found = true
face = i.Opposite()
break
}
}
if !found {
return false
}
}
t.Facing = face.Opposite()
place(w, pos, t, user, ctx)
return placed(ctx)
}
// NeighbourUpdateTick ...
func (t Torch) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if !w.Block(pos.Side(t.Facing)).Model().FaceSolid(pos.Side(t.Facing), t.Facing.Opposite(), w) {
w.BreakBlockWithoutParticles(pos)
}
}
// HasLiquidDrops ...
func (t Torch) HasLiquidDrops() bool {
return true
}
// EncodeItem ...
func (t Torch) EncodeItem() (name string, meta int16) {
switch t.Type {
case NormalFire():
return "minecraft:torch", 0
case SoulFire():
return "minecraft:soul_torch", 0
}
panic("invalid fire type")
}
// EncodeBlock ...
func (t Torch) EncodeBlock() (name string, properties map[string]interface{}) {
face := t.Facing.String()
if t.Facing == cube.FaceDown {
face = "top"
}
switch t.Type {
case NormalFire():
return "minecraft:torch", map[string]interface{}{"torch_facing_direction": face}
case SoulFire():
return "minecraft:soul_torch", map[string]interface{}{"torch_facing_direction": face}
}
panic("invalid fire type")
}
// allTorches ...
func allTorches() (torch []world.Block) {
for i := cube.Face(0); i < 6; i++ {
if i == cube.FaceUp {
continue
}
torch = append(torch, Torch{Type: NormalFire(), Facing: i})
torch = append(torch, Torch{Type: SoulFire(), Facing: i})
}
return
}