Skip to content

Commit

Permalink
block: Register unknown block states for creative item entries
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Nov 28, 2024
1 parent d4dac4f commit 6ec631b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
6 changes: 6 additions & 0 deletions server/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion server/block/glazed_terracotta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}

Expand All @@ -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})
}
Expand Down
5 changes: 4 additions & 1 deletion server/block/skull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -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)})
Expand Down
17 changes: 11 additions & 6 deletions server/block/torch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
}

0 comments on commit 6ec631b

Please sign in to comment.