Skip to content

Commit 958ea49

Browse files
committed
Fixed and improved Forced corner stairs voxel shapes
1 parent 87f8f09 commit 958ea49

2 files changed

Lines changed: 127 additions & 27 deletions

File tree

src/main/java/io/github/mikip98/humilityafm/content/blocks/stairs/InnerStairs.java

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,58 @@
1212
import java.util.Map;
1313

1414
public class InnerStairs extends OuterStairs {
15-
protected static final Map<Direction, VoxelShape> bottomVoxelShape = getVoxelShapeMapOfY(0.5f);
16-
protected static final Map<Direction, VoxelShape> topVoxelShape = getVoxelShapeMapOfY(0f);
17-
protected static Map<Direction, VoxelShape> getVoxelShapeMapOfY(double y) {
15+
protected static final VoxelShape voxelShapeBottomNorth;
16+
protected static final VoxelShape voxelShapeBottomSouth;
17+
protected static final VoxelShape voxelShapeBottomEast;
18+
protected static final VoxelShape voxelShapeBottomWest;
19+
20+
protected static final VoxelShape voxelShapeTopNorth;
21+
protected static final VoxelShape voxelShapeTopSouth;
22+
protected static final VoxelShape voxelShapeTopEast;
23+
protected static final VoxelShape voxelShapeTopWest;
24+
25+
protected static Map<Direction, VoxelShape> getVoxelShapeMapOfY ( double y){
26+
VoxelShape base = VoxelShapes.cuboid(
27+
0f, 0.5f - y, 0f,
28+
1f, 1f - y, 1f
29+
);
1830
return Map.of(
1931
Direction.NORTH, VoxelShapes.union(
20-
VoxelShapes.cuboid(0.5f, y, 0f, 1f, y+0.5f, 1f),
21-
VoxelShapes.cuboid(0f, y, 0.5f, 0.5f, y+0.5f, 1f)
32+
base,
33+
VoxelShapes.cuboid(0.5f, y, 0f, 1f, y + 0.5f, 1f),
34+
VoxelShapes.cuboid(0f, y, 0.5f, 0.5f, y + 0.5f, 1f)
2235
), // original
2336
Direction.SOUTH, VoxelShapes.union(
24-
VoxelShapes.cuboid(0f, y, 0f, 0.5f, y+0.5f, 1f),
25-
VoxelShapes.cuboid(0.5f, y, 0f, 1f, y+0.5f, 0.5f)
37+
base,
38+
VoxelShapes.cuboid(0f, y, 0f, 0.5f, y + 0.5f, 1f),
39+
VoxelShapes.cuboid(0.5f, y, 0f, 1f, y + 0.5f, 0.5f)
2640
), // reverse original
2741
Direction.EAST, VoxelShapes.union(
28-
VoxelShapes.cuboid(0f, y, 0.5f, 1f, y+0.5f, 1f),
29-
VoxelShapes.cuboid(0f, y, 0f, 0.5f, y+0.5f, 0.5f)
42+
base,
43+
VoxelShapes.cuboid(0f, y, 0.5f, 1f, y + 0.5f, 1f),
44+
VoxelShapes.cuboid(0f, y, 0f, 0.5f, y + 0.5f, 0.5f)
3045
), // swap x <-> z + reverse
31-
Direction.WEST, VoxelShapes.union(
32-
VoxelShapes.cuboid(0f, y, 0f, 1f, y+0.5f, 0.5f),
33-
VoxelShapes.cuboid(0.5f, y, 0.5f, 1f, y+0.5f, 1f)
46+
Direction.WEST, VoxelShapes.union(
47+
base,
48+
VoxelShapes.cuboid(0f, y, 0f, 1f, y + 0.5f, 0.5f),
49+
VoxelShapes.cuboid(0.5f, y, 0.5f, 1f, y + 0.5f, 1f)
3450
) // swap x <-> z
3551
);
3652
}
53+
static {
54+
final Map<Direction, VoxelShape> bottomVoxelShape = getVoxelShapeMapOfY(0.5f);
55+
final Map<Direction, VoxelShape> topVoxelShape = getVoxelShapeMapOfY(0f);
56+
57+
voxelShapeBottomNorth = bottomVoxelShape.get(Direction.NORTH);
58+
voxelShapeBottomSouth = bottomVoxelShape.get(Direction.SOUTH);
59+
voxelShapeBottomEast = bottomVoxelShape.get(Direction.EAST);
60+
voxelShapeBottomWest = bottomVoxelShape.get(Direction.WEST);
61+
62+
voxelShapeTopNorth = topVoxelShape.get(Direction.NORTH);
63+
voxelShapeTopSouth = topVoxelShape.get(Direction.SOUTH);
64+
voxelShapeTopEast = topVoxelShape.get(Direction.EAST);
65+
voxelShapeTopWest = topVoxelShape.get(Direction.WEST);
66+
}
3767

3868
public InnerStairs(Settings settings) {
3969
super(settings);
@@ -42,8 +72,37 @@ public InnerStairs(Settings settings) {
4272
@Override
4373
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
4474
Direction dir = state.get(FACING);
45-
return state.get(Properties.BLOCK_HALF) == BlockHalf.TOP
46-
? topVoxelShape.get(dir)
47-
: bottomVoxelShape.get(dir);
75+
if (state.get(Properties.BLOCK_HALF) == BlockHalf.BOTTOM) {
76+
switch (dir) {
77+
case NORTH -> {
78+
return voxelShapeBottomNorth;
79+
}
80+
case SOUTH -> {
81+
return voxelShapeBottomSouth;
82+
}
83+
case EAST -> {
84+
return voxelShapeBottomEast;
85+
}
86+
case WEST -> {
87+
return voxelShapeBottomWest;
88+
}
89+
}
90+
} else {
91+
switch (dir) {
92+
case NORTH -> {
93+
return voxelShapeTopNorth;
94+
}
95+
case SOUTH -> {
96+
return voxelShapeTopSouth;
97+
}
98+
case EAST -> {
99+
return voxelShapeTopEast;
100+
}
101+
case WEST -> {
102+
return voxelShapeTopWest;
103+
}
104+
}
105+
}
106+
return VoxelShapes.fullCube(); // Fallback, should not happen
48107
}
49108
}

src/main/java/io/github/mikip98/humilityafm/content/blocks/stairs/OuterStairs.java

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,42 @@
1717
import java.util.Map;
1818

1919
public class OuterStairs extends HorizontalFacingBlock implements Waterloggable {
20-
protected static final Map<Direction, VoxelShape> bottomVoxelShape = getVoxelShapeMapOfY(
21-
VoxelShapes.cuboid(0f, 0f, 0f, 1f, 0.5f, 1.0f),
22-
0.5f
23-
);
24-
protected static final Map<Direction, VoxelShape> topVoxelShape = getVoxelShapeMapOfY(
25-
VoxelShapes.cuboid(0f, 0.5f, 0f, 1f, 1f, 1.0f),
26-
0f
27-
);
28-
protected static Map<Direction, VoxelShape> getVoxelShapeMapOfY(VoxelShape base, double y) {
20+
protected static final VoxelShape voxelShapeBottomNorth;
21+
protected static final VoxelShape voxelShapeBottomSouth;
22+
protected static final VoxelShape voxelShapeBottomEast;
23+
protected static final VoxelShape voxelShapeBottomWest;
24+
25+
protected static final VoxelShape voxelShapeTopNorth;
26+
protected static final VoxelShape voxelShapeTopSouth;
27+
protected static final VoxelShape voxelShapeTopEast;
28+
protected static final VoxelShape voxelShapeTopWest;
29+
30+
protected static Map<Direction, VoxelShape> getVoxelShapeMapOfY(double y) {
31+
VoxelShape base = VoxelShapes.cuboid(
32+
0f, 0.5f - y, 0f,
33+
1f, 1f - y, 1f
34+
);
2935
return Map.of(
3036
Direction.NORTH, VoxelShapes.union(base, VoxelShapes.cuboid(0.5f, y, 0.5f, 1.0f, y+0.5f, 1.0f)), // original
3137
Direction.SOUTH, VoxelShapes.union(base, VoxelShapes.cuboid(0.0f, y, 0.0f, 0.5f, y+0.5f, 0.5f)), // reverse original
3238
Direction.EAST, VoxelShapes.union(base, VoxelShapes.cuboid(0.0f, y, 0.5f, 0.5f, y+0.5f, 1.0f)), // swap x <-> z + reverse
3339
Direction.WEST, VoxelShapes.union(base, VoxelShapes.cuboid(0.5f, y, 0.0f, 1.0f, y+0.5f, 0.5f)) // swap x <-> z
3440
);
3541
}
42+
static {
43+
final Map<Direction, VoxelShape> bottomVoxelShape = getVoxelShapeMapOfY(0.5f);
44+
final Map<Direction, VoxelShape> topVoxelShape = getVoxelShapeMapOfY(0f);
45+
46+
voxelShapeBottomNorth = bottomVoxelShape.get(Direction.NORTH);
47+
voxelShapeBottomSouth = bottomVoxelShape.get(Direction.SOUTH);
48+
voxelShapeBottomEast = bottomVoxelShape.get(Direction.EAST);
49+
voxelShapeBottomWest = bottomVoxelShape.get(Direction.WEST);
50+
51+
voxelShapeTopNorth = topVoxelShape.get(Direction.NORTH);
52+
voxelShapeTopSouth = topVoxelShape.get(Direction.SOUTH);
53+
voxelShapeTopEast = topVoxelShape.get(Direction.EAST);
54+
voxelShapeTopWest = topVoxelShape.get(Direction.WEST);
55+
}
3656

3757
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
3858

@@ -69,8 +89,29 @@ public FluidState getFluidState(BlockState state) {
6989
@Override
7090
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
7191
Direction dir = state.get(FACING);
72-
return state.get(Properties.BLOCK_HALF) == BlockHalf.TOP
73-
? topVoxelShape.get(dir)
74-
: bottomVoxelShape.get(dir);
92+
if (state.get(Properties.BLOCK_HALF) == BlockHalf.BOTTOM) {
93+
switch (dir) {
94+
case NORTH:
95+
return voxelShapeBottomNorth;
96+
case SOUTH:
97+
return voxelShapeBottomSouth;
98+
case EAST:
99+
return voxelShapeBottomEast;
100+
case WEST:
101+
return voxelShapeBottomWest;
102+
}
103+
} else {
104+
switch (dir) {
105+
case NORTH:
106+
return voxelShapeTopNorth;
107+
case SOUTH:
108+
return voxelShapeTopSouth;
109+
case EAST:
110+
return voxelShapeTopEast;
111+
case WEST:
112+
return voxelShapeTopWest;
113+
}
114+
}
115+
return VoxelShapes.fullCube(); // Fallback, should not happen
75116
}
76117
}

0 commit comments

Comments
 (0)