diff --git a/common/src/main/java/com/copycatsplus/copycats/CCShapes.java b/common/src/main/java/com/copycatsplus/copycats/CCShapes.java index 52fd07d5..4c4bac51 100644 --- a/common/src/main/java/com/copycatsplus/copycats/CCShapes.java +++ b/common/src/main/java/com/copycatsplus/copycats/CCShapes.java @@ -176,43 +176,53 @@ public class CCShapes { line(vec3(16, 0, 0), vec3(0, 0, 16)), line(vec3(16, 16, 0), vec3(0, 16, 16)) )); - public static final Map>> SLOPE_LAYER = - forHorizontalDirections(forHalves(forAll(LAYERS, - layer -> layer <= 4 ? - shape( - IntStream.range(0, SLOPE_SUBDIVISIONS) - .mapToObj(i -> aabb(16, (i + 1.0) / SLOPE_SUBDIVISIONS * 16 * layer / 4.0, 16.0 / SLOPE_SUBDIVISIONS).move(0, 0, i * 16.0 / SLOPE_SUBDIVISIONS)) - .toArray(MutableAABB[]::new) - ).outline( - line(vec3(0, 0, 0), vec3(16, 0, 0)), - line(vec3(0, 0, 16), vec3(16, 0, 16)), - line(vec3(0, 0, 0), vec3(0, 0, 16)), - line(vec3(16, 0, 0), vec3(16, 0, 16)), - line(vec3(0, 0, 16), vec3(0, 4 * layer, 16)), - line(vec3(16, 0, 16), vec3(16, 4 * layer, 16)), - line(vec3(0, 4 * layer, 16), vec3(16, 4 * layer, 16)), - line(vec3(0, 0, 0), vec3(0, 4 * layer, 16)), - line(vec3(16, 0, 0), vec3(16, 4 * layer, 16)) - ) : - shape( - IntStream.range(0, SLOPE_SUBDIVISIONS) - .mapToObj(i -> aabb(16, 16 * (layer - 4) / 4.0 + (i + 1.0) / SLOPE_SUBDIVISIONS * 16 * (1 - (layer - 4) / 4.0), 16.0 / SLOPE_SUBDIVISIONS).move(0, 0, i * 16.0 / SLOPE_SUBDIVISIONS)) - .toArray(MutableAABB[]::new) - ).outline( - line(vec3(0, 0, 0), vec3(16, 0, 0)), - line(vec3(0, 0, 16), vec3(16, 0, 16)), - line(vec3(0, 0, 0), vec3(0, 0, 16)), - line(vec3(16, 0, 0), vec3(16, 0, 16)), - line(vec3(0, 0, 0), vec3(0, (layer - 4) * 4, 0)), - line(vec3(16, 0, 0), vec3(16, (layer - 4) * 4, 0)), - line(vec3(0, 0, 16), vec3(0, 16, 16)), - line(vec3(16, 0, 16), vec3(16, 16, 16)), - line(vec3(0, 16, 16), vec3(16, 16, 16)), - line(vec3(0, (layer - 4) * 4, 0), vec3(16, (layer - 4) * 4, 0)), - line(vec3(0, (layer - 4) * 4, 0), vec3(0, 16, 16)), - line(vec3(16, (layer - 4) * 4, 0), vec3(16, 16, 16)) - ) - ))); + public static final Map>>> SLOPE_LAYER = + forHorizontalDirections(forHalves(forAll(IN_WALL, + in_wall -> forAll(LAYERS, + layer -> { + MutableShape baseShape = layer <= 4 ? + shape( + IntStream.range(0, SLOPE_SUBDIVISIONS) + .mapToObj(i -> aabb(16, (i + 1.0) / SLOPE_SUBDIVISIONS * 16 * layer / 4.0, 16.0 / SLOPE_SUBDIVISIONS).move(0, 0, i * 16.0 / SLOPE_SUBDIVISIONS)) + .toArray(MutableAABB[]::new) + ).outline( + line(vec3(0, 0, 0), vec3(16, 0, 0)), + line(vec3(0, 0, 16), vec3(16, 0, 16)), + line(vec3(0, 0, 0), vec3(0, 0, 16)), + line(vec3(16, 0, 0), vec3(16, 0, 16)), + line(vec3(0, 0, 16), vec3(0, 4 * layer, 16)), + line(vec3(16, 0, 16), vec3(16, 4 * layer, 16)), + line(vec3(0, 4 * layer, 16), vec3(16, 4 * layer, 16)), + line(vec3(0, 0, 0), vec3(0, 4 * layer, 16)), + line(vec3(16, 0, 0), vec3(16, 4 * layer, 16)) + ) : + shape( + IntStream.range(0, SLOPE_SUBDIVISIONS) + .mapToObj(i -> aabb(16, 16 * (layer - 4) / 4.0 + (i + 1.0) / SLOPE_SUBDIVISIONS * 16 * (1 - (layer - 4) / 4.0), 16.0 / SLOPE_SUBDIVISIONS).move(0, 0, i * 16.0 / SLOPE_SUBDIVISIONS)) + .toArray(MutableAABB[]::new) + ).outline( + line(vec3(0, 0, 0), vec3(16, 0, 0)), + line(vec3(0, 0, 16), vec3(16, 0, 16)), + line(vec3(0, 0, 0), vec3(0, 0, 16)), + line(vec3(16, 0, 0), vec3(16, 0, 16)), + line(vec3(0, 0, 0), vec3(0, (layer - 4) * 4, 0)), + line(vec3(16, 0, 0), vec3(16, (layer - 4) * 4, 0)), + line(vec3(0, 0, 16), vec3(0, 16, 16)), + line(vec3(16, 0, 16), vec3(16, 16, 16)), + line(vec3(0, 16, 16), vec3(16, 16, 16)), + line(vec3(0, (layer - 4) * 4, 0), vec3(16, (layer - 4) * 4, 0)), + line(vec3(0, (layer - 4) * 4, 0), vec3(0, 16, 16)), + line(vec3(16, (layer - 4) * 4, 0), vec3(16, 16, 16)) + ); + + MutableShape shape = baseShape.copy(); + if (in_wall) { + shape.rotateX(270); + } + + return shape; + } + )))); public static AssemblyTransform halves(Half half) { return t -> t.flipY(half == Half.TOP); diff --git a/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerBlock.java b/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerBlock.java index 5a4dcf6c..2623d49f 100644 --- a/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerBlock.java +++ b/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerBlock.java @@ -44,6 +44,7 @@ public class CopycatSlopeLayerBlock extends CCWaterloggedCopycatBlock implements public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final EnumProperty HALF = BlockStateProperties.HALF; + public static final BooleanProperty IN_WALL = BlockStateProperties.IN_WALL; public static final IntegerProperty LAYERS = BlockStateProperties.LAYERS; public CopycatSlopeLayerBlock(Properties pProperties) { @@ -51,13 +52,14 @@ public CopycatSlopeLayerBlock(Properties pProperties) { registerDefaultState(defaultBlockState() .setValue(FACING, Direction.NORTH) .setValue(HALF, Half.BOTTOM) + .setValue(IN_WALL, false) .setValue(LAYERS, 1) ); } @Override protected void createBlockStateDefinition(StateDefinition.Builder pBuilder) { - super.createBlockStateDefinition(pBuilder.add(FACING, HALF, LAYERS)); + super.createBlockStateDefinition(pBuilder.add(FACING, HALF, IN_WALL, LAYERS)); } @Override @@ -74,16 +76,26 @@ public BlockState getStateForPlacement(BlockPlaceContext context) { return state; } } else { - Half half = context.getClickedFace() == Direction.DOWN - ? Half.TOP - : context.getClickedFace() == Direction.UP - ? Half.BOTTOM - : context.getClickLocation().y - context.getClickedPos().getY() > 0.5 - ? Half.TOP - : Half.BOTTOM; - return stateForPlacement - .setValue(FACING, context.getHorizontalDirection()) - .setValue(HALF, half); + Direction playerHorizontal = context.getHorizontalDirection(); + Direction clickedFace = context.getClickedFace(); + if (clickedFace == Direction.UP || clickedFace == Direction.DOWN) { + Half half = clickedFace == Direction.DOWN + ? Half.TOP + : Half.BOTTOM; + return stateForPlacement + .setValue(FACING, playerHorizontal) + .setValue(IN_WALL, false) + .setValue(HALF, half); + } + else { + Half half = context.getClickLocation().y - context.getClickedPos().getY() > 0.5 + ? Half.TOP + : Half.BOTTOM; + return stateForPlacement + .setValue(FACING, clickedFace) + .setValue(IN_WALL, true) + .setValue(HALF, half); + } } } @@ -94,8 +106,14 @@ public boolean canBeReplaced(@NotNull BlockState pState, BlockPlaceContext pUseC if (!itemstack.is(this.asItem())) return false; if (pState.getValue(LAYERS) == 8) return false; Half half = pState.getValue(HALF); + boolean inWall = pState.getValue(IN_WALL); Direction facing = pState.getValue(FACING); - if (pUseContext.getClickedFace() == facing.getOpposite()) return true; + if(!inWall) { + if (pUseContext.getClickedFace() == facing.getOpposite()) return true; + } + else { + if (pUseContext.getClickedFace() == facing) return true; + } if (half == Half.TOP && pUseContext.getClickedFace() == Direction.DOWN) return true; if (half == Half.BOTTOM && pUseContext.getClickedFace() == Direction.UP) return true; return false; @@ -155,9 +173,10 @@ public boolean isPathfindable(@NotNull BlockState pState, @NotNull PathComputati }; } + @SuppressWarnings("deprecation") @Override public @NotNull VoxelShape getShape(BlockState pState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos, @NotNull CollisionContext pContext) { - return CCShapes.SLOPE_LAYER.get(pState.getValue(FACING)).get(pState.getValue(HALF)).get(pState.getValue(LAYERS)).toShape(); + return CCShapes.SLOPE_LAYER.get(pState.getValue(FACING)).get(pState.getValue(HALF)).get(pState.getValue(IN_WALL)).get(pState.getValue(LAYERS)).toShape(); } diff --git a/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerModelCore.java b/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerModelCore.java index baa97b07..b9896c93 100644 --- a/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerModelCore.java +++ b/common/src/main/java/com/copycatsplus/copycats/content/copycat/slope_layer/CopycatSlopeLayerModelCore.java @@ -15,8 +15,20 @@ public void emitCopycatQuads(String key, BlockState state, CopycatRenderContext int layer = state.getValue(CopycatSlopeLayerBlock.LAYERS); Direction facing = state.getValue(CopycatSlopeLayerBlock.FACING); Half half = state.getValue(CopycatSlopeLayerBlock.HALF); + boolean in_wall = state.getValue(CopycatSlopeLayerBlock.IN_WALL); - AssemblyTransform transform = t -> t.rotateY((int) facing.toYRot()).flipY(half == Half.TOP); + AssemblyTransform transform = t -> { + t.rotateY((int) facing.toYRot()).flipY(half == Half.TOP); + + if (in_wall) { + switch (facing){ + case NORTH -> t.rotateX(half == Half.TOP ? 270 : 90); + case SOUTH -> t.rotateX(half == Half.TOP ? 90 : 270); + case WEST -> t.rotateZ(half == Half.TOP ? 90 : 270); + case EAST -> t.rotateZ(half == Half.TOP ? 270 : 90); + } + } + }; if (layer <= 4) CopycatSlopeModelCore.assembleSlope(context, transform, 0, layer * 4, enhanced);