diff --git a/server/block/block.go b/server/block/block.go index 27420e620..09b0130a6 100644 --- a/server/block/block.go +++ b/server/block/block.go @@ -92,6 +92,12 @@ type Permutable interface { Permutations() []customblock.Permutation } +// unknownFace is a face that is used for certain block items. This should not be exposed in the API. +var unknownFace = cube.Face(len(cube.Faces())) + +// unknownDirection is a direction that is used for certain block items. This should not be exposed in the API. +var unknownDirection = cube.Direction(len(cube.Directions())) + func calculateFace(user item.User, placePos cube.Pos) cube.Face { userPos := user.Position() pos := cube.PosFromVec3(userPos) diff --git a/server/block/glazed_terracotta.go b/server/block/glazed_terracotta.go index 5fec06c5e..fe10f65ac 100644 --- a/server/block/glazed_terracotta.go +++ b/server/block/glazed_terracotta.go @@ -30,6 +30,9 @@ func (t GlazedTerracotta) EncodeItem() (name string, meta int16) { // EncodeBlock ... func (t GlazedTerracotta) EncodeBlock() (name string, properties map[string]any) { + if t.Facing == unknownDirection { + return "minecraft:" + t.Colour.SilverString() + "_glazed_terracotta", map[string]any{"facing_direction": int32(0)} + } return "minecraft:" + t.Colour.SilverString() + "_glazed_terracotta", map[string]any{"facing_direction": int32(2 + t.Facing)} } @@ -47,7 +50,7 @@ func (t GlazedTerracotta) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, // allGlazedTerracotta returns glazed terracotta blocks with all possible colours. func allGlazedTerracotta() (b []world.Block) { - for dir := cube.Direction(0); dir < 4; dir++ { + for _, dir := range append(cube.Directions(), unknownDirection) { for _, c := range item.Colours() { b = append(b, GlazedTerracotta{Colour: c, Facing: dir}) } diff --git a/server/block/skull.go b/server/block/skull.go index a23c5379c..55fd90980 100644 --- a/server/block/skull.go +++ b/server/block/skull.go @@ -108,6 +108,9 @@ func (s Skull) EncodeNBT() map[string]interface{} { // EncodeBlock ... func (s Skull) EncodeBlock() (string, map[string]interface{}) { if s.Attach.hanging { + if s.Attach.facing == unknownDirection { + return "minecraft:" + s.Type.String(), map[string]interface{}{"facing_direction": int32(0)} + } return "minecraft:" + s.Type.String(), map[string]interface{}{"facing_direction": int32(s.Attach.facing) + 2} } return "minecraft:" + s.Type.String(), map[string]interface{}{"facing_direction": int32(1)} @@ -116,7 +119,7 @@ func (s Skull) EncodeBlock() (string, map[string]interface{}) { // allSkulls ... func allSkulls() (skulls []world.Block) { for _, t := range SkullTypes() { - for _, d := range cube.Directions() { + for _, d := range append(cube.Directions(), unknownDirection) { skulls = append(skulls, Skull{Type: t, Attach: WallAttachment(d)}) } skulls = append(skulls, Skull{Type: t, Attach: StandingAttachment(0)}) diff --git a/server/block/torch.go b/server/block/torch.go index 8b15a535d..8e20f780b 100644 --- a/server/block/torch.go +++ b/server/block/torch.go @@ -90,10 +90,15 @@ func (t Torch) EncodeItem() (name string, meta int16) { // EncodeBlock ... func (t Torch) EncodeBlock() (name string, properties map[string]any) { - face := t.Facing.String() + var face string if t.Facing == cube.FaceDown { face = "top" + } else if t.Facing == unknownFace { + face = "unknown" + } else { + face = t.Facing.String() } + switch t.Type { case NormalFire(): return "minecraft:torch", map[string]any{"torch_facing_direction": face} @@ -105,12 +110,12 @@ func (t Torch) EncodeBlock() (name string, properties map[string]any) { // allTorches ... func allTorches() (torch []world.Block) { - for i := cube.Face(0); i < 6; i++ { - if i == cube.FaceUp { - continue + for _, face := range cube.Faces() { + if face == cube.FaceUp { + face = unknownFace } - torch = append(torch, Torch{Type: NormalFire(), Facing: i}) - torch = append(torch, Torch{Type: SoulFire(), Facing: i}) + torch = append(torch, Torch{Type: NormalFire(), Facing: face}) + torch = append(torch, Torch{Type: SoulFire(), Facing: face}) } return }