Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ func (b *hashBuilder) ftype(structName, s string, expr ast.Expr, directives map[
return "uint64(" + s + ".FaceUint8())", 3
}
return "uint64(" + s + ".Uint8())", 5
case "HangingAttachment":
// Wall (0-3), Ceiling non-attached (4-7), Ceiling attached (8-23) = 24 values, 5 bits.
return "uint64(" + s + ".Uint8())", 5
case "GrindstoneAttachment":
return "uint64(" + s + ".Uint8())", 2
case "WoodType", "LeavesType", "FlowerType", "DoubleFlowerType", "Colour":
Expand Down
48 changes: 48 additions & 0 deletions server/block/hanging_attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package block

import "github.com/df-mc/dragonfly/server/block/cube"

// HangingAttachment describes how a hanging sign is attached. It may be mounted to the side of a block, hang
// underneath a block by chains, or be attached underneath a block with the 16-direction ceiling variant.
type HangingAttachment struct {
ceiling bool
attached bool
facing cube.Direction
o cube.Orientation
}

// WallHangingAttachment returns a HangingAttachment for a hanging sign mounted to the side of a block.
func WallHangingAttachment(facing cube.Direction) HangingAttachment {
return HangingAttachment{facing: facing}
}

// CeilingHangingAttachment returns a HangingAttachment for a hanging sign hanging underneath a block.
func CeilingHangingAttachment(facing cube.Direction) HangingAttachment {
return HangingAttachment{ceiling: true, facing: facing}
}

// AttachedCeilingHangingAttachment returns a HangingAttachment for a hanging sign attached underneath a block using
// the 16-direction ceiling variant.
func AttachedCeilingHangingAttachment(o cube.Orientation) HangingAttachment {
return HangingAttachment{ceiling: true, attached: true, o: o}
}

// Uint8 returns the HangingAttachment as a uint8.
// Wall: 0-3, Ceiling (non-attached): 4-7, Ceiling (attached): 8-23.
func (a HangingAttachment) Uint8() uint8 {
if !a.ceiling {
return uint8(a.facing)
}
if !a.attached {
return 4 + uint8(a.facing)
}
return 8 + uint8(a.o)
}

// Rotation returns the rotation of the HangingAttachment.
func (a HangingAttachment) Rotation() cube.Rotation {
if a.attached {
return cube.Rotation{a.o.Yaw()}
}
return WallAttachment(a.facing).Rotation()
}
Loading