From 62ea0c324fd6cce32ba4e380b9d73de811dc99a4 Mon Sep 17 00:00:00 2001 From: ANAVGAR Date: Sat, 9 Aug 2025 18:27:06 +0200 Subject: [PATCH] Vertical slope layers for 1.20 --- .../com/copycatsplus/copycats/CCShapes.java | 84 +++++++++++-------- .../slope_layer/CopycatSlopeLayerBlock.java | 50 +++++++---- .../CopycatSlopeLayerModelCore.java | 14 +++- 3 files changed, 94 insertions(+), 54 deletions(-) diff --git a/common/src/main/java/com/copycatsplus/copycats/CCShapes.java b/common/src/main/java/com/copycatsplus/copycats/CCShapes.java index 52fd07d51..75bd9481a 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 = + forDirections(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 ba27f93db..54f21069e 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 @@ -35,15 +35,16 @@ import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; -import static net.minecraft.core.Direction.UP; +import static net.minecraft.core.Direction.DOWN; @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault public class CopycatSlopeLayerBlock extends CCWaterloggedCopycatBlock implements SpecialBlockItemRequirement, IStateType { - public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; + public static final DirectionProperty FACING = BlockStateProperties.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; @@ -151,7 +169,7 @@ public BlockState transform(BlockState state, StructureTransform transform) { @Override public boolean isPathfindable(@NotNull BlockState pState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos, @NotNull PathComputationType pType) { return switch (pType) { - case LAND -> pState.getValue(LAYERS) < 5 && pState.getValue(FACING).equals(UP); + case LAND -> pState.getValue(LAYERS) < 5 && !pState.getValue(FACING).equals(DOWN); default -> false; }; } @@ -159,7 +177,7 @@ public boolean isPathfindable(@NotNull BlockState pState, @NotNull BlockGetter p @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 baa97b07a..b9896c931 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);