forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ladder.go
103 lines (89 loc) · 2.78 KB
/
ladder.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
package block
import (
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/cube"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/model"
"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"
"time"
)
// Ladder is a wooden block used for climbing walls either vertically or horizontally. They can be placed only on
// the sides of other blocks.
type Ladder struct {
transparent
sourceWaterDisplacer
// Facing is the side of the block the ladder is currently attached to.
Facing cube.Direction
}
// NeighbourUpdateTick ...
func (l Ladder) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if _, ok := w.Block(pos.Side(l.Facing.Opposite().Face())).(LightDiffuser); ok {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: l})
dropItem(w, item.NewStack(l, 1), pos.Vec3Centre())
}
}
// UseOnBlock ...
func (l Ladder) 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.FaceUp || face == cube.FaceDown {
return false
}
if _, ok := w.Block(pos.Side(face.Opposite())).(LightDiffuser); ok {
found := false
for _, i := range []cube.Face{cube.FaceSouth, cube.FaceNorth, cube.FaceEast, cube.FaceWest} {
if diffuser, ok := w.Block(pos.Side(i)).(LightDiffuser); !ok || diffuser.LightDiffusionLevel() == 15 {
found = true
face = i.Opposite()
break
}
}
if !found {
return false
}
}
l.Facing = face.Direction()
place(w, pos, l, user, ctx)
return placed(ctx)
}
// EntityInside ...
func (l Ladder) EntityInside(_ cube.Pos, _ *world.World, e world.Entity) {
if fallEntity, ok := e.(fallDistanceEntity); ok {
fallEntity.ResetFallDistance()
}
}
// SideClosed ...
func (l Ladder) SideClosed(cube.Pos, cube.Pos, *world.World) bool {
return false
}
// BreakInfo ...
func (l Ladder) BreakInfo() BreakInfo {
return newBreakInfo(0.4, alwaysHarvestable, axeEffective, oneOf(l))
}
// FuelInfo ...
func (Ladder) FuelInfo() item.FuelInfo {
return newFuelInfo(time.Second * 15)
}
// EncodeItem ...
func (l Ladder) EncodeItem() (name string, meta int16) {
return "minecraft:ladder", 0
}
// EncodeBlock ...
func (l Ladder) EncodeBlock() (string, map[string]any) {
return "minecraft:ladder", map[string]any{"facing_direction": int32(l.Facing + 2)}
}
// Model ...
func (l Ladder) Model() world.BlockModel {
return model.Ladder{Facing: l.Facing}
}
// allLadders ...
func allLadders() (b []world.Block) {
for i := cube.Direction(0); i <= 3; i++ {
b = append(b, Ladder{Facing: i})
}
return
}