new block and better additivity #24
@ -73,6 +73,13 @@ public class ReFramedHalfStairBlock extends WaterloggableReFramedBlock {
|
|||||||
ReFramed.SMALL_CUBE.getDefaultState().with(CORNER, corner.getOpposite(dir))
|
ReFramed.SMALL_CUBE.getDefaultState().with(CORNER, corner.getOpposite(dir))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (block == ReFramed.SLAB)
|
||||||
|
return ReFramed.SLAB.matchesShape(
|
||||||
|
context.getHitPos(),
|
||||||
|
context.getBlockPos(),
|
||||||
|
ReFramed.SLAB.getDefaultState().with(FACING, dir.getOpposite())
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +142,7 @@ public class ReFramedHalfStairBlock extends WaterloggableReFramedBlock {
|
|||||||
|| new_state.isOf(ReFramed.HALF_STAIRS_CUBE_STAIR)
|
|| new_state.isOf(ReFramed.HALF_STAIRS_CUBE_STAIR)
|
||||||
|| new_state.isOf(ReFramed.HALF_STAIRS_STEP_STAIR)
|
|| new_state.isOf(ReFramed.HALF_STAIRS_STEP_STAIR)
|
||||||
) return Map.of(1, 1);
|
) return Map.of(1, 1);
|
||||||
|
if (new_state.isOf(ReFramed.SLABS_INNER_STAIR)) return Map.of(1, 2);
|
||||||
if (new_state.isOf(ReFramed.HALF_STAIRS_STAIR))
|
if (new_state.isOf(ReFramed.HALF_STAIRS_STAIR))
|
||||||
return Map.of(
|
return Map.of(
|
||||||
1,
|
1,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package fr.adrien1106.reframed.block;
|
package fr.adrien1106.reframed.block;
|
||||||
|
|
||||||
import fr.adrien1106.reframed.ReFramed;
|
import fr.adrien1106.reframed.ReFramed;
|
||||||
|
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||||
|
import fr.adrien1106.reframed.util.blocks.Corner;
|
||||||
import fr.adrien1106.reframed.util.blocks.Edge;
|
import fr.adrien1106.reframed.util.blocks.Edge;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
@ -19,8 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.EDGE;
|
import static fr.adrien1106.reframed.util.blocks.BlockProperties.*;
|
||||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.EDGE_FACE;
|
|
||||||
import static net.minecraft.state.property.Properties.*;
|
import static net.minecraft.state.property.Properties.*;
|
||||||
|
|
||||||
public class ReFramedSlabBlock extends WaterloggableReFramedBlock {
|
public class ReFramedSlabBlock extends WaterloggableReFramedBlock {
|
||||||
@ -89,6 +90,72 @@ public class ReFramedSlabBlock extends WaterloggableReFramedBlock {
|
|||||||
.with(WATERLOGGED, current_state.get(WATERLOGGED));
|
.with(WATERLOGGED, current_state.get(WATERLOGGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (current_state.isOf(ReFramed.HALF_STAIR)) {
|
||||||
|
Corner corner = current_state.get(CORNER);
|
||||||
|
Direction face = corner.getDirection(current_state.get(CORNER_FACE));
|
||||||
|
corner = corner.change(face);
|
||||||
|
return ReFramed.SLABS_INNER_STAIR.getDefaultState()
|
||||||
|
.with(CORNER, corner)
|
||||||
|
.with(CORNER_FACE, corner.getDirectionIndex(face.getOpposite()))
|
||||||
|
.with(WATERLOGGED, current_state.get(WATERLOGGED));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_state.isOf(ReFramed.STEP)) {
|
||||||
|
Edge edge = current_state.get(EDGE),
|
||||||
|
placed = BlockHelper.getPlacementEdge(ctx),
|
||||||
|
new_edge;
|
||||||
|
Direction face = edge.getFirstDirection(),
|
||||||
|
other = edge.getSecondDirection().getOpposite();
|
||||||
|
|
||||||
|
if (!ReFramed.STEP.matchesShape(
|
||||||
|
ctx.getHitPos(),
|
||||||
|
ctx.getBlockPos(),
|
||||||
|
current_state.with(EDGE, new_edge = edge.getOpposite(face))
|
||||||
|
)
|
||||||
|
&& ctx.getSide() != other.getOpposite()
|
||||||
|
&& (placed.getAxis() == edge.getAxis()
|
||||||
|
|| ctx.getSide() == other
|
||||||
|
|| !placed.hasDirection(other))
|
||||||
|
) {
|
||||||
|
new_edge = edge.getOpposite(edge.getSecondDirection());
|
||||||
|
other = edge.getFirstDirection().getOpposite();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ReFramed.SLABS_STAIR.getDefaultState()
|
||||||
|
.with(EDGE, new_edge)
|
||||||
|
.with(EDGE_FACE, new_edge.getDirectionIndex(other))
|
||||||
|
.with(WATERLOGGED, current_state.get(WATERLOGGED));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_state.isOf(ReFramed.SMALL_CUBE)) {
|
||||||
|
Corner corner = current_state.get(CORNER);
|
||||||
|
Edge placed = BlockHelper.getPlacementEdge(ctx);
|
||||||
|
Direction face;
|
||||||
|
Corner new_corner;
|
||||||
|
|
||||||
|
if (!corner.hasDirection(face = ctx.getSide())) {
|
||||||
|
int i = 0;
|
||||||
|
do {
|
||||||
|
face = corner.getDirection(i);
|
||||||
|
new_corner = corner.change(face);
|
||||||
|
} while (!ReFramed.SMALL_CUBE.matchesShape(
|
||||||
|
ctx.getHitPos(),
|
||||||
|
ctx.getBlockPos(),
|
||||||
|
current_state.with(CORNER, new_corner)
|
||||||
|
) && ++i < 3);
|
||||||
|
|
||||||
|
if (i == 3) {
|
||||||
|
face = placed.getOtherDirection(corner.getMatchingDirection(placed)).getOpposite();
|
||||||
|
new_corner = corner.change(face);
|
||||||
|
}
|
||||||
|
} else new_corner = corner.change(face);
|
||||||
|
|
||||||
|
return ReFramed.SLABS_OUTER_STAIR.getDefaultState()
|
||||||
|
.with(CORNER, new_corner)
|
||||||
|
.with(CORNER_FACE, new_corner.getDirectionIndex(face.getOpposite()))
|
||||||
|
.with(WATERLOGGED, current_state.get(WATERLOGGED));
|
||||||
|
}
|
||||||
|
|
||||||
return super.getPlacementState(ctx).with(FACING, ctx.getSide().getOpposite());
|
return super.getPlacementState(ctx).with(FACING, ctx.getSide().getOpposite());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import fr.adrien1106.reframed.ReFramed;
|
|||||||
import fr.adrien1106.reframed.util.VoxelHelper;
|
import fr.adrien1106.reframed.util.VoxelHelper;
|
||||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||||
import fr.adrien1106.reframed.util.blocks.Corner;
|
import fr.adrien1106.reframed.util.blocks.Corner;
|
||||||
|
import fr.adrien1106.reframed.util.blocks.Edge;
|
||||||
|
import fr.adrien1106.reframed.util.blocks.StairShape;
|
||||||
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;
|
||||||
@ -45,51 +47,51 @@ public class ReFramedSmallCubeBlock extends WaterloggableReFramedBlock {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public boolean canReplace(BlockState state, ItemPlacementContext context) {
|
public boolean canReplace(BlockState state, ItemPlacementContext context) {
|
||||||
if (context.getPlayer() == null) return false;
|
if (context.getPlayer() == null
|
||||||
|
|| context.getPlayer().isSneaking()
|
||||||
|
|| !(context.getStack().getItem() instanceof BlockItem block_item)
|
||||||
|
) return false;
|
||||||
|
|
||||||
|
Block block = block_item.getBlock();
|
||||||
Corner corner = state.get(CORNER);
|
Corner corner = state.get(CORNER);
|
||||||
return !(
|
if (block == this)
|
||||||
context.getPlayer().isSneaking()
|
return matchesShape(
|
||||||
|| !(context.getStack().getItem() instanceof BlockItem block_item)
|
context.getHitPos(),
|
||||||
|| (
|
context.getBlockPos(),
|
||||||
!(
|
getDefaultState().with(CORNER, corner.change(corner.getFirstDirection()))
|
||||||
block_item.getBlock() == ReFramed.HALF_STAIR
|
) || matchesShape(
|
||||||
&& !(corner.hasDirection(context.getSide())
|
context.getHitPos(),
|
||||||
|| (corner.hasDirection(context.getSide().getOpposite())
|
context.getBlockPos(),
|
||||||
&& BlockHelper.cursorMatchesFace(
|
getDefaultState().with(CORNER, corner.change(corner.getSecondDirection()))
|
||||||
getOutlineShape(state, context.getWorld(), context.getBlockPos(), null),
|
) || matchesShape(
|
||||||
BlockHelper.getRelativePos(context.getHitPos(), context.getBlockPos())
|
context.getHitPos(),
|
||||||
)
|
context.getBlockPos(),
|
||||||
)
|
getDefaultState().with(CORNER, corner.change(corner.getThirdDirection()))
|
||||||
)
|
);
|
||||||
|
|
||||||
|
if (block == ReFramed.HALF_STAIR || block == ReFramed.SLAB) {
|
||||||
|
corner = corner.getOpposite();
|
||||||
|
Direction face = corner.getFirstDirection();
|
||||||
|
Edge edge = corner.getEdge(face);
|
||||||
|
if (ReFramed.STAIR.matchesShape(
|
||||||
|
context.getHitPos(),
|
||||||
|
context.getBlockPos(),
|
||||||
|
ReFramed.STAIR.getDefaultState()
|
||||||
|
.with(EDGE, edge)
|
||||||
|
.with(
|
||||||
|
STAIR_SHAPE,
|
||||||
|
face.getDirection() == Direction.AxisDirection.POSITIVE
|
||||||
|
? StairShape.INNER_LEFT
|
||||||
|
: StairShape.INNER_RIGHT
|
||||||
)
|
)
|
||||||
&& !(
|
)) return block == ReFramed.SLAB || !matchesShape(
|
||||||
block_item.getBlock() == this
|
context.getHitPos(),
|
||||||
&& (
|
context.getBlockPos(),
|
||||||
ReFramed.SMALL_CUBES_STEP
|
getDefaultState().with(CORNER, corner)
|
||||||
.matchesShape(
|
);
|
||||||
context.getHitPos(),
|
}
|
||||||
context.getBlockPos(),
|
|
||||||
ReFramed.SMALL_CUBES_STEP.getDefaultState().with(EDGE, corner.getEdge(corner.getFirstDirection())),
|
return false;
|
||||||
corner.getFirstDirection().getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2
|
|
||||||
)
|
|
||||||
|| ReFramed.SMALL_CUBES_STEP
|
|
||||||
.matchesShape(
|
|
||||||
context.getHitPos(),
|
|
||||||
context.getBlockPos(),
|
|
||||||
ReFramed.SMALL_CUBES_STEP.getDefaultState().with(EDGE, corner.getEdge(corner.getSecondDirection())),
|
|
||||||
corner.getSecondDirection().getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2
|
|
||||||
)
|
|
||||||
|| ReFramed.SMALL_CUBES_STEP
|
|
||||||
.matchesShape(
|
|
||||||
context.getHitPos(),
|
|
||||||
context.getBlockPos(),
|
|
||||||
ReFramed.SMALL_CUBES_STEP.getDefaultState().with(EDGE, corner.getEdge(corner.getThirdDirection())),
|
|
||||||
corner.getThirdDirection().getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -163,7 +165,9 @@ public class ReFramedSmallCubeBlock extends WaterloggableReFramedBlock {
|
|||||||
|
|
||||||
@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)
|
||||||
|
|| new_state.isOf(ReFramed.SLABS_OUTER_STAIR)
|
||||||
|
) return Map.of(1, 2);
|
||||||
if (new_state.isOf(ReFramed.SMALL_CUBES_STEP))
|
if (new_state.isOf(ReFramed.SMALL_CUBES_STEP))
|
||||||
return Map.of(
|
return Map.of(
|
||||||
1,
|
1,
|
||||||
|
@ -63,7 +63,10 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// allow replacing with stair
|
// allow replacing with stair
|
||||||
if (block != this && block != ReFramed.STAIR) return false;
|
if (block != this
|
||||||
|
&& block != ReFramed.STAIR
|
||||||
|
&& block != ReFramed.SLAB
|
||||||
|
) return false;
|
||||||
|
|
||||||
return ReFramed.STAIR
|
return ReFramed.STAIR
|
||||||
.matchesShape(
|
.matchesShape(
|
||||||
@ -186,7 +189,8 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock {
|
|||||||
if (new_state.isOf(ReFramed.STEPS_CROSS)
|
if (new_state.isOf(ReFramed.STEPS_CROSS)
|
||||||
|| new_state.isOf(ReFramed.STEPS_HALF_LAYER)
|
|| new_state.isOf(ReFramed.STEPS_HALF_LAYER)
|
||||||
) return Map.of(1, 1);
|
) return Map.of(1, 1);
|
||||||
if (new_state.isOf(ReFramed.STAIRS_CUBE)) return Map.of(1, 2);
|
if (new_state.isOf(ReFramed.STAIRS_CUBE)
|
||||||
|
|| new_state.isOf(ReFramed.SLABS_STAIR)) return Map.of(1, 2);
|
||||||
if (new_state.isOf(ReFramed.STEPS_SLAB))
|
if (new_state.isOf(ReFramed.STEPS_SLAB))
|
||||||
return Map.of(
|
return Map.of(
|
||||||
1,
|
1,
|
||||||
|
@ -154,4 +154,8 @@ public enum Corner implements StringIdentifiable {
|
|||||||
third_direction == face ? opposite : third_direction
|
third_direction == face ? opposite : third_direction
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Direction getMatchingDirection(Edge edge) {
|
||||||
|
return hasDirection(edge.getSecondDirection()) ? edge.getSecondDirection() : edge.getFirstDirection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user