Skip to content

Commit

Permalink
block/ladder.go: Change Direction to Face to allow states 0 and 1 (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gewinum authored Aug 15, 2024
1 parent 990932b commit 674dff6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions server/block/ladder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ type Ladder struct {
transparent
sourceWaterDisplacer

// Facing is the side of the block the ladder is currently attached to.
Facing cube.Direction
// Facing is the side of the block the ladder is currently attached to. cube.FaceDown and cube.FaceUp
// do not do anything in game but they are still valid states.
Facing cube.Face
}

// NeighbourUpdateTick ...
func (l Ladder) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if _, ok := w.Block(pos.Side(l.Facing.Opposite().Face())).(LightDiffuser); ok {
if _, ok := w.Block(pos.Side(l.Facing.Opposite())).(LightDiffuser); ok {
w.SetBlock(pos, nil, nil)
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: l})
dropItem(w, item.NewStack(l, 1), pos.Vec3Centre())
Expand Down Expand Up @@ -51,7 +52,7 @@ func (l Ladder) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.
return false
}
}
l.Facing = face.Direction()
l.Facing = face

place(w, pos, l, user, ctx)
return placed(ctx)
Expand Down Expand Up @@ -86,7 +87,7 @@ func (l Ladder) EncodeItem() (name string, meta int16) {

// EncodeBlock ...
func (l Ladder) EncodeBlock() (string, map[string]any) {
return "minecraft:ladder", map[string]any{"facing_direction": int32(l.Facing + 2)}
return "minecraft:ladder", map[string]any{"facing_direction": int32(l.Facing)}
}

// Model ...
Expand All @@ -96,8 +97,8 @@ func (l Ladder) Model() world.BlockModel {

// allLadders ...
func allLadders() (b []world.Block) {
for i := cube.Direction(0); i <= 3; i++ {
b = append(b, Ladder{Facing: i})
for _, f := range cube.Faces() {
b = append(b, Ladder{Facing: f})
}
return
}
4 changes: 2 additions & 2 deletions server/block/model/ladder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
// Ladder is the model for a ladder block.
type Ladder struct {
// Facing is the side opposite to the block the Ladder is currently attached to.
Facing cube.Direction
Facing cube.Face
}

// BBox returns one physics.BBox that depends on the facing direction of the Ladder.
func (l Ladder) BBox(cube.Pos, *world.World) []cube.BBox {
return []cube.BBox{full.ExtendTowards(l.Facing.Face(), -0.8125)}
return []cube.BBox{full.ExtendTowards(l.Facing, -0.8125)}
}

// FaceSolid always returns false.
Expand Down

0 comments on commit 674dff6

Please sign in to comment.