More merging logic + 11 new block + Fix server / client sync #23

Merged
Adrien1106 merged 10 commits from dev into master 2024-06-19 14:42:55 +02:00
5 changed files with 87 additions and 82 deletions
Showing only changes of commit d7ad6ed0c1 - Show all commits

View File

@ -37,7 +37,7 @@ public class ReFramed implements ModInitializer {
public static final String MODID = "reframed"; public static final String MODID = "reframed";
public static final ArrayList<Block> BLOCKS = new ArrayList<>(); public static final ArrayList<Block> BLOCKS = new ArrayList<>();
public static Block public static ReFramedBlock
CUBE, CUBE,
SMALL_CUBE, SMALL_CUBES_STEP, SMALL_CUBE, SMALL_CUBES_STEP,
STAIR, STAIRS_CUBE, STAIR, STAIRS_CUBE,

View File

@ -20,6 +20,7 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
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.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes; import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
@ -136,6 +137,19 @@ public class ReFramedBlock extends Block implements BlockEntityProvider {
onPlaced(world, pos, state, placer, stack); onPlaced(world, pos, state, placer, stack);
} }
public boolean matchesShape(Vec3d hit, BlockPos pos, BlockState state) {
return matchesShape(hit, pos, state, 0);
}
public boolean matchesShape(Vec3d hit, BlockPos pos, BlockState state, int i) {
Vec3d rel = BlockHelper.getRelativePos(hit, pos);
return matchesShape(rel, getShape(state, i));
}
public boolean matchesShape(Vec3d rel_hit, VoxelShape shape) {
return BlockHelper.cursorMatchesFace(shape, rel_hit);
}
@Override @Override
public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
return isGhost(view, pos) return isGhost(view, pos)

View File

@ -49,14 +49,6 @@ public abstract class ReFramedDoubleBlock extends ReFramedBlock {
return 0; return 0;
} }
public boolean matchesShape(Vec3d hit, BlockPos pos, BlockState state, int i) {
Vec3d rel = BlockHelper.getRelativePos(hit, pos);
return BlockHelper.cursorMatchesFace(
getShape(state, i),
rel
);
}
@Override @Override
public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) { public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {
return world.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity return world.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity

View File

@ -42,21 +42,23 @@ public class ReFramedSlabBlock extends WaterloggableReFramedBlock {
@Override @Override
public boolean canReplace(BlockState state, ItemPlacementContext context) { public boolean canReplace(BlockState state, ItemPlacementContext context) {
if (context.getPlayer() == null) return false; if (context.getPlayer() == null
return !( || context.getPlayer().isSneaking()
context.getPlayer().isSneaking() || !(context.getStack().getItem() instanceof BlockItem block_item)
|| !(context.getStack().getItem() instanceof BlockItem block_item) ) return false;
|| !(
block_item.getBlock() == this // allow replacing with slab and step
&& ((ReFramedSlabsCubeBlock) ReFramed.SLABS_CUBE) if (block_item.getBlock() != this && block_item.getBlock() != ReFramed.STEP)
.matchesShape( return false;
context.getHitPos(),
context.getBlockPos(), // check if the player is clicking on the inner part of the block
ReFramed.SLABS_CUBE.getDefaultState().with(AXIS, state.get(FACING).getAxis()), return ReFramed.SLABS_CUBE
state.get(FACING).getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2 .matchesShape(
) context.getHitPos(),
) context.getBlockPos(),
); ReFramed.SLABS_CUBE.getDefaultState().with(AXIS, state.get(FACING).getAxis()),
state.get(FACING).getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2
);
} }
@Nullable @Nullable

View File

@ -22,10 +22,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.Map; import java.util.Map;
import static fr.adrien1106.reframed.util.VoxelHelper.VoxelListBuilder; import static fr.adrien1106.reframed.util.VoxelHelper.VoxelListBuilder;
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.STAIR_SHAPE; import static fr.adrien1106.reframed.util.blocks.BlockProperties.STAIR_SHAPE;
import static net.minecraft.state.property.Properties.*; import static net.minecraft.state.property.Properties.*;
import static net.minecraft.state.property.Properties.WATERLOGGED;
public class ReFramedStepBlock extends WaterloggableReFramedBlock { public class ReFramedStepBlock extends WaterloggableReFramedBlock {
@ -43,48 +42,32 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock {
@Override @Override
public boolean canReplace(BlockState state, ItemPlacementContext context) { public boolean canReplace(BlockState state, ItemPlacementContext context) {
if (context.getPlayer() == null) return false; if (context.getPlayer() == null
Edge edge = state.get(EDGE); || context.getPlayer().isSneaking()
return !(
context.getPlayer().isSneaking()
|| !(context.getStack().getItem() instanceof BlockItem block_item) || !(context.getStack().getItem() instanceof BlockItem block_item)
|| ( ) return false;
!(
block_item.getBlock() == ReFramed.STAIR
&& ((ReFramedStairsCubeBlock) ReFramed.STAIRS_CUBE)
.matchesShape(
context.getHitPos(),
context.getBlockPos(),
ReFramed.STAIRS_CUBE.getDefaultState().with(EDGE, edge.opposite()),
1
)
) Edge edge = state.get(EDGE);
&& !( // allow replacing with stair
block_item.getBlock() == this if (block_item.getBlock() == ReFramed.STAIR)
&& ( return ReFramed.STAIRS_CUBE
((ReFramedStepsSlabBlock) ReFramed.STEPS_SLAB) .matchesShape(
.matchesShape( context.getHitPos(),
context.getHitPos(), context.getBlockPos(),
context.getBlockPos(), ReFramed.STAIRS_CUBE.getDefaultState().with(EDGE, edge.opposite()),
ReFramed.STEPS_SLAB.getDefaultState() 1
.with(FACING, edge.getFirstDirection()) );
.with(AXIS, edge.getSecondDirection().getAxis()),
edge.getSecondDirection().getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2 if (block_item.getBlock() == this)
) return ReFramed.STAIR
|| ((ReFramedStepsSlabBlock) ReFramed.STEPS_SLAB) .matchesShape(
.matchesShape( context.getHitPos(),
context.getHitPos(), context.getBlockPos(),
context.getBlockPos(), ReFramed.STAIR.getDefaultState()
ReFramed.STEPS_SLAB.getDefaultState() .with(EDGE, edge.opposite())
.with(FACING, edge.getSecondDirection()) );
.with(AXIS, edge.getFirstDirection().getAxis()),
edge.getFirstDirection().getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2 return false;
)
)
)
)
);
} }
@Nullable @Nullable
@ -101,23 +84,37 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock {
if (current_state.isOf(this)) { if (current_state.isOf(this)) {
Vec3d hit = ctx.getHitPos(); Vec3d hit = ctx.getHitPos();
Edge edge = current_state.get(EDGE); Edge edge = current_state.get(EDGE);
Direction dir = edge.getFirstDirection();
ReFramedStepsSlabBlock block = ((ReFramedStepsSlabBlock) ReFramed.STEPS_SLAB); // Steps Slab
BlockState state = block.getDefaultState() if (matchesShape(hit, pos,
.with(FACING, dir) current_state.with(EDGE, edge.getOpposite(edge.getFirstDirection()))
.with(AXIS, edge.getOtherDirection(dir).getAxis()) )) return ReFramed.STEPS_SLAB.getDefaultState()
.with(FACING, edge.getFirstDirection())
.with(AXIS, edge.getSecondDirection().getAxis())
.with(WATERLOGGED, current_state.get(WATERLOGGED)); .with(WATERLOGGED, current_state.get(WATERLOGGED));
if (!block.matchesShape(
hit, pos, else if (matchesShape(hit, pos,
state, current_state.with(EDGE, edge.getOpposite(edge.getSecondDirection()))
edge.getOtherDirection(dir).getDirection() == Direction.AxisDirection.POSITIVE ? 1 : 2 )) return ReFramed.STEPS_SLAB.getDefaultState()
)) { .with(FACING, edge.getFirstDirection())
dir = edge.getSecondDirection(); .with(AXIS, edge.getSecondDirection().getAxis())
state = state .with(WATERLOGGED, current_state.get(WATERLOGGED));
.with(FACING, dir)
.with(AXIS, edge.getOtherDirection(dir).getAxis()); // Steps Cross
} return null; // TODO STEP cross
return state; } else if (current_state.isOf(ReFramed.SLAB)) {
Direction facing = current_state.get(FACING);
Edge edge;
// Slabs Stair
if (ctx.getSide() == facing || ctx.getSide() == facing.getOpposite())
edge = BlockHelper.getPlacementEdge(ctx);
else
edge = Edge.getByDirections(facing, ctx.getSide().getOpposite());
return ReFramed.SLABS_STAIR.getDefaultState()
.with(EDGE, edge)
.with(EDGE_FACE, edge.getDirectionIndex(facing));
} }
return super.getPlacementState(ctx).with(EDGE, BlockHelper.getPlacementEdge(ctx)); return super.getPlacementState(ctx).with(EDGE, BlockHelper.getPlacementEdge(ctx));