diff --git a/README.md b/README.md index 7b670aa..1fdf2b1 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,13 @@ or based on preferences add the person(s) to the project ### What Shapes are planed to be added Currently, the list of shapes to be added is pretty simple as the mod is still under development: -- Wall - Fence - Pane - Button - Pressure Plate - Trapdoor - Door -- Carpet +- Carpet (maybe redundant with Layer) - Post - Half Slab (maybe redundant with Layer) - Slabs Stair (a stair with one end being of a second theme, might be done in multiple blocks) diff --git a/gradle.properties b/gradle.properties index d16d0cf..8d57023 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx1G # check these on https://modmuss50.me/fabric.html minecraft_version=1.20.4 yarn_mappings=1.20.4+build.3 -loader_version=0.15.10 +loader_version=0.15.11 # Mod Properties modrinth_id = jCpoCBpn diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java index 9088703..9d2efb7 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java @@ -10,6 +10,8 @@ import net.minecraft.block.ShapeContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.function.BooleanBiFunction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -101,6 +103,20 @@ public class ReFramedHalfStairBlock extends WaterloggableReFramedBlock { return HALF_STAIR_VOXELS[state.get(CORNER_FACE) + state.get(CORNER).getID() * 3]; } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + Corner corner = state.get(CORNER).rotate(rotation); + Direction face = state.get(CORNER).getDirection(state.get(CORNER_FACE)); + return state.with(CORNER, corner).with(CORNER_FACE, corner.getDirectionIndex(rotation.rotate(face))); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + Corner corner = state.get(CORNER).mirror(mirror); + Direction face = state.get(CORNER).getDirection(state.get(CORNER_FACE)); + return state.with(CORNER, corner).with(CORNER_FACE, corner.getDirectionIndex(mirror.apply(face))); + } + @Override public Map getThemeMap(BlockState state, BlockState new_state) { if (new_state.isOf(ReFramed.HALF_STAIRS_SLAB)) return Map.of(1, 1); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java index b8c55fa..18fbb1d 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java @@ -7,7 +7,10 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import org.jetbrains.annotations.Nullable; @@ -50,6 +53,20 @@ public class ReFramedHalfStairsSlabBlock extends WaterloggableReFramedDoubleBloc return getSlabShape(state.get(CORNER).getDirection(state.get(CORNER_FACE))); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + Corner corner = state.get(CORNER).rotate(rotation); + Direction face = state.get(CORNER).getDirection(state.get(CORNER_FACE)); + return state.with(CORNER, corner).with(CORNER_FACE, corner.getDirectionIndex(rotation.rotate(face))); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + Corner corner = state.get(CORNER).mirror(mirror); + Direction face = state.get(CORNER).getDirection(state.get(CORNER_FACE)); + return state.with(CORNER, corner).with(CORNER_FACE, corner.getDirectionIndex(mirror.apply(face))); + } + @Override public VoxelShape getShape(BlockState state, int i) { Corner corner = state.get(CORNER); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java index 9f3d7ed..6f84264 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java @@ -9,6 +9,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; @@ -48,6 +50,16 @@ public class ReFramedHalfStairsStairBlock extends WaterloggableReFramedDoubleBlo return getStairShape(state.get(EDGE), StairShape.STRAIGHT); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(EDGE, state.get(EDGE).rotate(rotation)); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(EDGE, state.get(EDGE).mirror(mirror)); + } + @Override public VoxelShape getShape(BlockState state, int i) { Edge edge = state.get(EDGE); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java index 662115c..a0ab9e9 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java @@ -7,6 +7,8 @@ import net.minecraft.block.ShapeContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; @@ -51,6 +53,16 @@ public class ReFramedLayerBlock extends ReFramedSlabBlock { return previous.with(LAYERS, previous.get(LAYERS) + 1); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(FACING, rotation.rotate(state.get(FACING))); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(FACING, mirror.apply(state.get(FACING))); + } + static { VoxelListBuilder builder = VoxelListBuilder.create(createCuboidShape(0, 0, 0, 16, 2, 16), 48) .add(createCuboidShape(0, 0, 0, 16, 4, 16)) diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java index 61bcf6c..9b9a379 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java @@ -4,17 +4,16 @@ import fr.adrien1106.reframed.util.VoxelHelper; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; -import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import org.jetbrains.annotations.Nullable; -import java.util.Map; - import static net.minecraft.state.property.Properties.AXIS; public class ReFramedPillarBlock extends WaterloggableReFramedBlock { @@ -31,20 +30,8 @@ public class ReFramedPillarBlock extends WaterloggableReFramedBlock { super.appendProperties(builder.add(AXIS)); } - @Override - public boolean canReplace(BlockState state, ItemPlacementContext context) { - return !(context.getPlayer().isSneaking() - || !(context.getStack().getItem() instanceof BlockItem block_item) - || !( - block_item.getBlock() == this - && state.get(AXIS) != context.getSide().getAxis() - ) - ); - } - @Override public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) { - // TODO: PILLARS WALL return super.getPlacementState(ctx).with(AXIS, ctx.getSide().getAxis()); } @@ -58,9 +45,13 @@ public class ReFramedPillarBlock extends WaterloggableReFramedBlock { } @Override - public Map getThemeMap(BlockState state, BlockState new_state) { -// if (new_state.getBlock() == ReFramed.PILLARS_WALL) return Map.of(1, 1); // TODO: PILLARS WALL - return super.getThemeMap(state, new_state); + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(AXIS, rotation.rotate(Direction.get(Direction.AxisDirection.POSITIVE, state.get(AXIS))).getAxis()); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(AXIS, mirror.apply(Direction.get(Direction.AxisDirection.POSITIVE, state.get(AXIS))).getAxis()); } static { diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarsWallBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarsWallBlock.java index 9e1a86f..952fc7e 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarsWallBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarsWallBlock.java @@ -6,6 +6,8 @@ import net.minecraft.block.ShapeContext; import net.minecraft.block.enums.WallShape; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; @@ -103,6 +105,20 @@ public class ReFramedPillarsWallBlock extends WaterloggableReFramedDoubleBlock { return shape; } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return Direction.Type.HORIZONTAL.stream().reduce(state, (s, dir) -> + s.with(getWallShape(rotation.rotate(dir)), state.get(getWallShape(dir))) + , (prev, next) -> next); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return Direction.Type.HORIZONTAL.stream().reduce(state, (s, dir) -> + s.with(getWallShape(mirror.apply(dir)), state.get(getWallShape(dir))) + , (prev, next) -> next); + } + @Override public VoxelShape getShape(BlockState state, int i) { if (i == 1) return WALL_VOXELS[0]; diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java index 1453aa2..3818508 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java @@ -7,6 +7,8 @@ import net.minecraft.block.ShapeContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; @@ -72,6 +74,16 @@ public class ReFramedSlabBlock extends WaterloggableReFramedBlock { return getSlabShape(state.get(FACING)); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(FACING, rotation.rotate(state.get(FACING))); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(FACING, mirror.apply(state.get(FACING))); + } + public static VoxelShape getSlabShape(Direction side) { return switch (side) { case DOWN -> DOWN; diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java index e899488..cec5797 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java @@ -4,11 +4,14 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import org.jetbrains.annotations.Nullable; import static fr.adrien1106.reframed.block.ReFramedSlabBlock.*; +import static fr.adrien1106.reframed.util.blocks.BlockProperties.EDGE; import static net.minecraft.state.property.Properties.AXIS; public class ReFramedSlabsCubeBlock extends ReFramedDoubleBlock { @@ -29,6 +32,16 @@ public class ReFramedSlabsCubeBlock extends ReFramedDoubleBlock { return super.getPlacementState(ctx).with(AXIS, ctx.getSide().getAxis()); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(AXIS, rotation.rotate(Direction.get(Direction.AxisDirection.POSITIVE, state.get(AXIS))).getAxis()); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(AXIS, mirror.apply(Direction.get(Direction.AxisDirection.POSITIVE, state.get(AXIS))).getAxis()); + } + @Override public VoxelShape getShape(BlockState state, int i) { return switch (state.get(AXIS)) { diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java index fa4f9dd..a4efbeb 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java @@ -10,6 +10,8 @@ import net.minecraft.block.ShapeContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; @@ -125,6 +127,16 @@ public class ReFramedSmallCubeBlock extends WaterloggableReFramedBlock { return SMALL_CUBE_VOXELS[state.get(CORNER).getID()]; } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(CORNER, state.get(CORNER).rotate(rotation)); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(CORNER, state.get(CORNER).mirror(mirror)); + } + @Override public Map getThemeMap(BlockState state, BlockState new_state) { if (new_state.isOf(ReFramed.HALF_STAIRS_SLAB)) return Map.of(1, 2); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java index 9eb3349..7d5b4fb 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java @@ -8,6 +8,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; @@ -46,6 +48,16 @@ public class ReFramedSmallCubesStepBlock extends WaterloggableReFramedDoubleBloc return getStepShape(state.get(EDGE)); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(EDGE, state.get(EDGE).rotate(rotation)); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(EDGE, state.get(EDGE).mirror(mirror)); + } + @Override public VoxelShape getShape(BlockState state, int i) { Edge edge = state.get(EDGE); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java index 6c8933c..c5b1a67 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java @@ -11,6 +11,8 @@ import net.minecraft.block.ShapeContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.function.BooleanBiFunction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -95,6 +97,31 @@ public class ReFramedStairBlock extends WaterloggableReFramedBlock { return getStairShape(state.get(EDGE), state.get(STAIR_SHAPE)); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + Edge prev_edge = state.get(EDGE); + Edge edge = prev_edge.rotate(rotation); + if (prev_edge.getAxis() == Direction.Axis.Y) return state.with(EDGE, edge); + + if (prev_edge.getFace().getDirection() == edge.getFace().getDirection()) // 90° rotations + state = state.with(STAIR_SHAPE, state.get(STAIR_SHAPE).mirror()); + else state = state.with(STAIR_SHAPE, state.get(STAIR_SHAPE).flip()); + + if (prev_edge.getAxis() == edge.getAxis()) // 180° rotation + state = state.with(STAIR_SHAPE, state.get(STAIR_SHAPE).mirror()); + + return state.with(EDGE, edge); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + Edge prev_edge = state.get(EDGE); + Edge edge = prev_edge.mirror(mirror); + return state + .with(STAIR_SHAPE, prev_edge == edge ? state.get(STAIR_SHAPE).mirror() : state.get(STAIR_SHAPE).flip()) + .with(EDGE, edge); + } + public static VoxelShape getStairShape(Edge edge, StairShape shape) { return STAIR_VOXELS[edge.getID() * 9 + shape.getID()]; } diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java index e528f89..b1dcb6f 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java @@ -7,6 +7,8 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; @@ -48,6 +50,32 @@ public class ReFramedStairsCubeBlock extends ReFramedDoubleBlock { return super.getPlacementState(ctx).with(EDGE, face).with(STAIR_SHAPE, shape); } + + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + Edge prev_edge = state.get(EDGE); + Edge edge = prev_edge.rotate(rotation); + if (prev_edge.getAxis() == Direction.Axis.Y) return state.with(EDGE, edge); + + if (prev_edge.getFace().getDirection() == edge.getFace().getDirection()) // 90° rotations + state = state.with(STAIR_SHAPE, state.get(STAIR_SHAPE).mirror()); + else state = state.with(STAIR_SHAPE, state.get(STAIR_SHAPE).flip()); + + if (prev_edge.getAxis() == edge.getAxis()) // 180° rotation + state = state.with(STAIR_SHAPE, state.get(STAIR_SHAPE).mirror()); + + return state.with(EDGE, edge); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + Edge prev_edge = state.get(EDGE); + Edge edge = prev_edge.mirror(mirror); + return state + .with(STAIR_SHAPE, prev_edge == edge ? state.get(STAIR_SHAPE).mirror() : state.get(STAIR_SHAPE).flip()) + .with(EDGE, edge); + } + @Override public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { super.onStateReplaced(state, world, pos, newState, moved); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java index 0239520..607f8d3 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java @@ -10,6 +10,8 @@ import net.minecraft.block.ShapeContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; @@ -125,6 +127,16 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock { return getStepShape(state.get(EDGE)); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(EDGE, state.get(EDGE).rotate(rotation)); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return state.with(EDGE, state.get(EDGE).mirror(mirror)); + } + public static VoxelShape getStepShape(Edge edge) { return STEP_VOXELS[edge.getID()]; } diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java index 8751090..82ebc0a 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java @@ -7,6 +7,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction.Axis; @@ -51,6 +53,21 @@ public class ReFramedStepsSlabBlock extends WaterloggableReFramedDoubleBlock { return getSlabShape(state.get(FACING)); } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return state + .with(AXIS, rotation.rotate(Direction.get(Direction.AxisDirection.POSITIVE, state.get(AXIS))).getAxis()) + .with(FACING, rotation.rotate(state.get(FACING))); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + if (state.get(FACING).getAxis() != Axis.Y) + return state.with(FACING, mirror.apply(state.get(FACING))); + + return state; + } + @Override public VoxelShape getShape(BlockState state, int i) { Axis axis = state.get(AXIS); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedWallBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedWallBlock.java index 4123723..7fcd9f9 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedWallBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedWallBlock.java @@ -7,6 +7,8 @@ import net.minecraft.item.ItemPlacementContext; import net.minecraft.registry.tag.BlockTags; import net.minecraft.state.StateManager; import net.minecraft.state.property.Property; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.function.BooleanBiFunction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -106,6 +108,20 @@ public class ReFramedWallBlock extends WaterloggableReFramedBlock { return shape; } + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return Direction.Type.HORIZONTAL.stream().reduce(state, (s, dir) -> + s.with(getWallShape(rotation.rotate(dir)), state.get(getWallShape(dir))) + , (prev, next) -> next); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return Direction.Type.HORIZONTAL.stream().reduce(state, (s, dir) -> + s.with(getWallShape(mirror.apply(dir)), state.get(getWallShape(dir))) + , (prev, next) -> next); + } + public static BlockState getWallState(BlockState state, BlockState top_state, Map neighbors, VoxelShape top_shape, boolean fs, WorldView world, BlockPos pos) { for (Direction dir : Direction.Type.HORIZONTAL) { BlockPos offset = pos.offset(dir); diff --git a/src/main/java/fr/adrien1106/reframed/util/blocks/Corner.java b/src/main/java/fr/adrien1106/reframed/util/blocks/Corner.java index e1843de..f6a2f65 100644 --- a/src/main/java/fr/adrien1106/reframed/util/blocks/Corner.java +++ b/src/main/java/fr/adrien1106/reframed/util/blocks/Corner.java @@ -1,5 +1,7 @@ package fr.adrien1106.reframed.util.blocks; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.StringIdentifiable; import net.minecraft.util.math.Direction; @@ -119,4 +121,20 @@ public enum Corner implements StringIdentifiable { if (edge.getFirstDirection() != third_direction && edge.getSecondDirection() != third_direction) return third_direction; return first_direction; } + + public Corner rotate(BlockRotation rotation) { + return getByDirections( + rotation.rotate(first_direction), + rotation.rotate(second_direction), + rotation.rotate(third_direction) + ); + } + + public Corner mirror(BlockMirror mirror) { + return getByDirections( + mirror.apply(first_direction), + mirror.apply(second_direction), + mirror.apply(third_direction) + ); + } } diff --git a/src/main/java/fr/adrien1106/reframed/util/blocks/Edge.java b/src/main/java/fr/adrien1106/reframed/util/blocks/Edge.java index 9c8e34d..1642f56 100644 --- a/src/main/java/fr/adrien1106/reframed/util/blocks/Edge.java +++ b/src/main/java/fr/adrien1106/reframed/util/blocks/Edge.java @@ -1,5 +1,7 @@ package fr.adrien1106.reframed.util.blocks; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.StringIdentifiable; import net.minecraft.util.math.Direction; @@ -48,13 +50,19 @@ public enum Edge implements StringIdentifiable { public Direction getSecondDirection() { return second_direction; } + public Direction getRightDirection() { return Direction.from(axis, Direction.AxisDirection.NEGATIVE); } + public Direction getLeftDirection() { return Direction.from(axis, Direction.AxisDirection.POSITIVE); } + public Direction getFace() { + return first_direction == Direction.UP || first_direction == Direction.DOWN ? second_direction : first_direction; + } + public boolean hasDirection(Direction direction) { return this.first_direction.equals(direction) || this.second_direction.equals(direction); @@ -97,4 +105,18 @@ public enum Edge implements StringIdentifiable { .filter(value -> value.name().equals(name)) .findFirst().orElse(Edge.NORTH_DOWN); } + + public Edge rotate(BlockRotation rotation) { + return getByDirections( + rotation.rotate(first_direction), + rotation.rotate(second_direction) + ); + } + + public Edge mirror(BlockMirror mirror) { + return getByDirections( + mirror.apply(first_direction), + mirror.apply(second_direction) + ); + } } diff --git a/src/main/java/fr/adrien1106/reframed/util/blocks/StairShape.java b/src/main/java/fr/adrien1106/reframed/util/blocks/StairShape.java index 5019e89..63a1b62 100644 --- a/src/main/java/fr/adrien1106/reframed/util/blocks/StairShape.java +++ b/src/main/java/fr/adrien1106/reframed/util/blocks/StairShape.java @@ -48,4 +48,31 @@ public enum StairShape implements StringIdentifiable { .findFirst().orElse(StairShape.STRAIGHT); } + public StairShape mirror() { + return switch (this) { + case STRAIGHT -> STRAIGHT; + case INNER_RIGHT -> INNER_LEFT; + case INNER_LEFT -> INNER_RIGHT; + case OUTER_RIGHT -> OUTER_LEFT; + case OUTER_LEFT -> OUTER_RIGHT; + case FIRST_OUTER_RIGHT -> FIRST_OUTER_LEFT; + case FIRST_OUTER_LEFT -> FIRST_OUTER_RIGHT; + case SECOND_OUTER_RIGHT -> SECOND_OUTER_LEFT; + case SECOND_OUTER_LEFT -> SECOND_OUTER_RIGHT; + }; + } + + public StairShape flip() { + return switch (this) { + case STRAIGHT -> STRAIGHT; + case INNER_RIGHT -> INNER_RIGHT; + case INNER_LEFT -> INNER_LEFT; + case OUTER_RIGHT -> OUTER_RIGHT; + case OUTER_LEFT -> OUTER_LEFT; + case FIRST_OUTER_RIGHT -> SECOND_OUTER_RIGHT; + case FIRST_OUTER_LEFT -> SECOND_OUTER_LEFT; + case SECOND_OUTER_RIGHT -> FIRST_OUTER_RIGHT; + case SECOND_OUTER_LEFT -> FIRST_OUTER_LEFT; + }; + } }