added support for rotation and mirroring
This commit is contained in:
parent
d5369823d9
commit
752ee956eb
@ -21,14 +21,13 @@ or based on preferences add the person(s) to the project
|
|||||||
|
|
||||||
### What Shapes are planed to be added
|
### 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:
|
Currently, the list of shapes to be added is pretty simple as the mod is still under development:
|
||||||
- Wall
|
|
||||||
- Fence
|
- Fence
|
||||||
- Pane
|
- Pane
|
||||||
- Button
|
- Button
|
||||||
- Pressure Plate
|
- Pressure Plate
|
||||||
- Trapdoor
|
- Trapdoor
|
||||||
- Door
|
- Door
|
||||||
- Carpet
|
- Carpet (maybe redundant with Layer)
|
||||||
- Post
|
- Post
|
||||||
- Half Slab (maybe redundant with Layer)
|
- Half Slab (maybe redundant with Layer)
|
||||||
- Slabs Stair (a stair with one end being of a second theme, might be done in multiple blocks)
|
- Slabs Stair (a stair with one end being of a second theme, might be done in multiple blocks)
|
||||||
|
@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://modmuss50.me/fabric.html
|
||||||
minecraft_version=1.20.4
|
minecraft_version=1.20.4
|
||||||
yarn_mappings=1.20.4+build.3
|
yarn_mappings=1.20.4+build.3
|
||||||
loader_version=0.15.10
|
loader_version=0.15.11
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
modrinth_id = jCpoCBpn
|
modrinth_id = jCpoCBpn
|
||||||
|
@ -10,6 +10,8 @@ import net.minecraft.block.ShapeContext;
|
|||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.function.BooleanBiFunction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
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];
|
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
|
@Override
|
||||||
public Map<Integer, Integer> getThemeMap(BlockState state, BlockState new_state) {
|
public Map<Integer, Integer> getThemeMap(BlockState state, BlockState new_state) {
|
||||||
if (new_state.isOf(ReFramed.HALF_STAIRS_SLAB)) return Map.of(1, 1);
|
if (new_state.isOf(ReFramed.HALF_STAIRS_SLAB)) return Map.of(1, 1);
|
||||||
|
@ -7,7 +7,10 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -50,6 +53,20 @@ public class ReFramedHalfStairsSlabBlock extends WaterloggableReFramedDoubleBloc
|
|||||||
return getSlabShape(state.get(CORNER).getDirection(state.get(CORNER_FACE)));
|
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
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, int i) {
|
public VoxelShape getShape(BlockState state, int i) {
|
||||||
Corner corner = state.get(CORNER);
|
Corner corner = state.get(CORNER);
|
||||||
|
@ -9,6 +9,8 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
@ -48,6 +50,16 @@ public class ReFramedHalfStairsStairBlock extends WaterloggableReFramedDoubleBlo
|
|||||||
return getStairShape(state.get(EDGE), StairShape.STRAIGHT);
|
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
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, int i) {
|
public VoxelShape getShape(BlockState state, int i) {
|
||||||
Edge edge = state.get(EDGE);
|
Edge edge = state.get(EDGE);
|
||||||
|
@ -7,6 +7,8 @@ import net.minecraft.block.ShapeContext;
|
|||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
@ -51,6 +53,16 @@ public class ReFramedLayerBlock extends ReFramedSlabBlock {
|
|||||||
return previous.with(LAYERS, previous.get(LAYERS) + 1);
|
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 {
|
static {
|
||||||
VoxelListBuilder builder = VoxelListBuilder.create(createCuboidShape(0, 0, 0, 16, 2, 16), 48)
|
VoxelListBuilder builder = VoxelListBuilder.create(createCuboidShape(0, 0, 0, 16, 2, 16), 48)
|
||||||
.add(createCuboidShape(0, 0, 0, 16, 4, 16))
|
.add(createCuboidShape(0, 0, 0, 16, 4, 16))
|
||||||
|
@ -4,17 +4,16 @@ import fr.adrien1106.reframed.util.VoxelHelper;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.item.BlockItem;
|
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static net.minecraft.state.property.Properties.AXIS;
|
import static net.minecraft.state.property.Properties.AXIS;
|
||||||
|
|
||||||
public class ReFramedPillarBlock extends WaterloggableReFramedBlock {
|
public class ReFramedPillarBlock extends WaterloggableReFramedBlock {
|
||||||
@ -31,20 +30,8 @@ public class ReFramedPillarBlock extends WaterloggableReFramedBlock {
|
|||||||
super.appendProperties(builder.add(AXIS));
|
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
|
@Override
|
||||||
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) {
|
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||||
// TODO: PILLARS WALL
|
|
||||||
return super.getPlacementState(ctx).with(AXIS, ctx.getSide().getAxis());
|
return super.getPlacementState(ctx).with(AXIS, ctx.getSide().getAxis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,9 +45,13 @@ public class ReFramedPillarBlock extends WaterloggableReFramedBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Integer, Integer> getThemeMap(BlockState state, BlockState new_state) {
|
public BlockState rotate(BlockState state, BlockRotation rotation) {
|
||||||
// if (new_state.getBlock() == ReFramed.PILLARS_WALL) return Map.of(1, 1); // TODO: PILLARS WALL
|
return state.with(AXIS, rotation.rotate(Direction.get(Direction.AxisDirection.POSITIVE, state.get(AXIS))).getAxis());
|
||||||
return super.getThemeMap(state, new_state);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState mirror(BlockState state, BlockMirror mirror) {
|
||||||
|
return state.with(AXIS, mirror.apply(Direction.get(Direction.AxisDirection.POSITIVE, state.get(AXIS))).getAxis());
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -6,6 +6,8 @@ import net.minecraft.block.ShapeContext;
|
|||||||
import net.minecraft.block.enums.WallShape;
|
import net.minecraft.block.enums.WallShape;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
@ -103,6 +105,20 @@ public class ReFramedPillarsWallBlock extends WaterloggableReFramedDoubleBlock {
|
|||||||
return shape;
|
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
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, int i) {
|
public VoxelShape getShape(BlockState state, int i) {
|
||||||
if (i == 1) return WALL_VOXELS[0];
|
if (i == 1) return WALL_VOXELS[0];
|
||||||
|
@ -7,6 +7,8 @@ import net.minecraft.block.ShapeContext;
|
|||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
@ -72,6 +74,16 @@ public class ReFramedSlabBlock extends WaterloggableReFramedBlock {
|
|||||||
return getSlabShape(state.get(FACING));
|
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) {
|
public static VoxelShape getSlabShape(Direction side) {
|
||||||
return switch (side) {
|
return switch (side) {
|
||||||
case DOWN -> DOWN;
|
case DOWN -> DOWN;
|
||||||
|
@ -4,11 +4,14 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import static fr.adrien1106.reframed.block.ReFramedSlabBlock.*;
|
import static fr.adrien1106.reframed.block.ReFramedSlabBlock.*;
|
||||||
|
import static fr.adrien1106.reframed.util.blocks.BlockProperties.EDGE;
|
||||||
import static net.minecraft.state.property.Properties.AXIS;
|
import static net.minecraft.state.property.Properties.AXIS;
|
||||||
|
|
||||||
public class ReFramedSlabsCubeBlock extends ReFramedDoubleBlock {
|
public class ReFramedSlabsCubeBlock extends ReFramedDoubleBlock {
|
||||||
@ -29,6 +32,16 @@ public class ReFramedSlabsCubeBlock extends ReFramedDoubleBlock {
|
|||||||
return super.getPlacementState(ctx).with(AXIS, ctx.getSide().getAxis());
|
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
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, int i) {
|
public VoxelShape getShape(BlockState state, int i) {
|
||||||
return switch (state.get(AXIS)) {
|
return switch (state.get(AXIS)) {
|
||||||
|
@ -10,6 +10,8 @@ import net.minecraft.block.ShapeContext;
|
|||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
@ -125,6 +127,16 @@ public class ReFramedSmallCubeBlock extends WaterloggableReFramedBlock {
|
|||||||
return SMALL_CUBE_VOXELS[state.get(CORNER).getID()];
|
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
|
@Override
|
||||||
public Map<Integer, Integer> getThemeMap(BlockState state, BlockState new_state) {
|
public Map<Integer, Integer> getThemeMap(BlockState state, BlockState new_state) {
|
||||||
if (new_state.isOf(ReFramed.HALF_STAIRS_SLAB)) return Map.of(1, 2);
|
if (new_state.isOf(ReFramed.HALF_STAIRS_SLAB)) return Map.of(1, 2);
|
||||||
|
@ -8,6 +8,8 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
@ -46,6 +48,16 @@ public class ReFramedSmallCubesStepBlock extends WaterloggableReFramedDoubleBloc
|
|||||||
return getStepShape(state.get(EDGE));
|
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
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, int i) {
|
public VoxelShape getShape(BlockState state, int i) {
|
||||||
Edge edge = state.get(EDGE);
|
Edge edge = state.get(EDGE);
|
||||||
|
@ -11,6 +11,8 @@ import net.minecraft.block.ShapeContext;
|
|||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.function.BooleanBiFunction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
@ -95,6 +97,31 @@ public class ReFramedStairBlock extends WaterloggableReFramedBlock {
|
|||||||
return getStairShape(state.get(EDGE), state.get(STAIR_SHAPE));
|
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) {
|
public static VoxelShape getStairShape(Edge edge, StairShape shape) {
|
||||||
return STAIR_VOXELS[edge.getID() * 9 + shape.getID()];
|
return STAIR_VOXELS[edge.getID() * 9 + shape.getID()];
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
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);
|
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
|
@Override
|
||||||
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
|
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
|
||||||
super.onStateReplaced(state, world, pos, newState, moved);
|
super.onStateReplaced(state, world, pos, newState, moved);
|
||||||
|
@ -10,6 +10,8 @@ import net.minecraft.block.ShapeContext;
|
|||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
@ -125,6 +127,16 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock {
|
|||||||
return getStepShape(state.get(EDGE));
|
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) {
|
public static VoxelShape getStepShape(Edge edge) {
|
||||||
return STEP_VOXELS[edge.getID()];
|
return STEP_VOXELS[edge.getID()];
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Direction.Axis;
|
import net.minecraft.util.math.Direction.Axis;
|
||||||
@ -51,6 +53,21 @@ public class ReFramedStepsSlabBlock extends WaterloggableReFramedDoubleBlock {
|
|||||||
return getSlabShape(state.get(FACING));
|
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
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, int i) {
|
public VoxelShape getShape(BlockState state, int i) {
|
||||||
Axis axis = state.get(AXIS);
|
Axis axis = state.get(AXIS);
|
||||||
|
@ -7,6 +7,8 @@ import net.minecraft.item.ItemPlacementContext;
|
|||||||
import net.minecraft.registry.tag.BlockTags;
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.Property;
|
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.function.BooleanBiFunction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
@ -106,6 +108,20 @@ public class ReFramedWallBlock extends WaterloggableReFramedBlock {
|
|||||||
return shape;
|
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<Direction, BlockState> neighbors, VoxelShape top_shape, boolean fs, WorldView world, BlockPos pos) {
|
public static BlockState getWallState(BlockState state, BlockState top_state, Map<Direction, BlockState> neighbors, VoxelShape top_shape, boolean fs, WorldView world, BlockPos pos) {
|
||||||
for (Direction dir : Direction.Type.HORIZONTAL) {
|
for (Direction dir : Direction.Type.HORIZONTAL) {
|
||||||
BlockPos offset = pos.offset(dir);
|
BlockPos offset = pos.offset(dir);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package fr.adrien1106.reframed.util.blocks;
|
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.StringIdentifiable;
|
||||||
import net.minecraft.util.math.Direction;
|
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;
|
if (edge.getFirstDirection() != third_direction && edge.getSecondDirection() != third_direction) return third_direction;
|
||||||
return first_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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package fr.adrien1106.reframed.util.blocks;
|
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.StringIdentifiable;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
@ -48,13 +50,19 @@ public enum Edge implements StringIdentifiable {
|
|||||||
public Direction getSecondDirection() {
|
public Direction getSecondDirection() {
|
||||||
return second_direction;
|
return second_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction getRightDirection() {
|
public Direction getRightDirection() {
|
||||||
return Direction.from(axis, Direction.AxisDirection.NEGATIVE);
|
return Direction.from(axis, Direction.AxisDirection.NEGATIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction getLeftDirection() {
|
public Direction getLeftDirection() {
|
||||||
return Direction.from(axis, Direction.AxisDirection.POSITIVE);
|
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) {
|
public boolean hasDirection(Direction direction) {
|
||||||
return this.first_direction.equals(direction)
|
return this.first_direction.equals(direction)
|
||||||
|| this.second_direction.equals(direction);
|
|| this.second_direction.equals(direction);
|
||||||
@ -97,4 +105,18 @@ public enum Edge implements StringIdentifiable {
|
|||||||
.filter(value -> value.name().equals(name))
|
.filter(value -> value.name().equals(name))
|
||||||
.findFirst().orElse(Edge.NORTH_DOWN);
|
.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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,4 +48,31 @@ public enum StairShape implements StringIdentifiable {
|
|||||||
.findFirst().orElse(StairShape.STRAIGHT);
|
.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;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user