/
end_brick_stairs.go
76 lines (64 loc) · 2.33 KB
/
end_brick_stairs.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
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"
)
// EndBrickStairs are blocks that allow entities to walk up blocks without jumping. They are crafted using end bricks.
type EndBrickStairs struct {
transparent
// UpsideDown specifies if the stairs are upside down. If set to true, the full side is at the top part
// of the block.
UpsideDown bool
// Facing is the direction that the full side of the stairs is facing.
Facing cube.Direction
}
// UseOnBlock handles the directional placing of stairs and makes sure they are properly placed upside down
// when needed.
func (s EndBrickStairs) UseOnBlock(pos cube.Pos, face cube.Face, clickPos mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
pos, face, used = firstReplaceable(w, pos, face, s)
if !used {
return
}
s.Facing = user.Facing()
if face == cube.FaceDown || (clickPos[1] > 0.5 && face != cube.FaceUp) {
s.UpsideDown = true
}
place(w, pos, s, user, ctx)
return placed(ctx)
}
// Model ...
func (s EndBrickStairs) Model() world.BlockModel {
return model.Stair{Facing: s.Facing, UpsideDown: s.UpsideDown}
}
// BreakInfo ...
func (s EndBrickStairs) BreakInfo() BreakInfo {
return newBreakInfo(3, pickaxeHarvestable, pickaxeEffective, oneOf(s))
}
// EncodeItem ...
func (s EndBrickStairs) EncodeItem() (name string, meta int16) {
return "minecraft:end_brick_stairs", 0
}
// EncodeBlock ...
func (s EndBrickStairs) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:end_brick_stairs", map[string]any{"upside_down_bit": s.UpsideDown, "weirdo_direction": toStairsDirection(s.Facing)}
}
// CanDisplace ...
func (EndBrickStairs) CanDisplace(b world.Liquid) bool {
_, ok := b.(Water)
return ok
}
// SideClosed ...
func (s EndBrickStairs) SideClosed(pos, side cube.Pos, w *world.World) bool {
return s.Model().FaceSolid(pos, pos.Face(side), w)
}
// allEndBrickStairs ...
func allEndBrickStairs() (stairs []world.Block) {
for direction := cube.Direction(0); direction <= 3; direction++ {
stairs = append(stairs, EndBrickStairs{Facing: direction, UpsideDown: true})
stairs = append(stairs, EndBrickStairs{Facing: direction, UpsideDown: false})
}
return
}