Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 47 additions & 37 deletions common/src/main/java/com/copycatsplus/copycats/CCShapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Direction, Map<Half, Map<Integer, MutableShape>>> 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<Direction, Map<Half, Map<Boolean, Map<Integer, MutableShape>>>> SLOPE_LAYER =
forHorizontalDirections(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ public class CopycatSlopeLayerBlock extends CCWaterloggedCopycatBlock implements

public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final EnumProperty<Half> HALF = BlockStateProperties.HALF;
public static final BooleanProperty IN_WALL = BlockStateProperties.IN_WALL;
public static final IntegerProperty LAYERS = BlockStateProperties.LAYERS;

public CopycatSlopeLayerBlock(Properties pProperties) {
super(pProperties);
registerDefaultState(defaultBlockState()
.setValue(FACING, Direction.NORTH)
.setValue(HALF, Half.BOTTOM)
.setValue(IN_WALL, false)
.setValue(LAYERS, 1)
);
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
super.createBlockStateDefinition(pBuilder.add(FACING, HALF, LAYERS));
super.createBlockStateDefinition(pBuilder.add(FACING, HALF, IN_WALL, LAYERS));
}

@Override
Expand All @@ -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);
}
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -155,9 +173,10 @@ public boolean isPathfindable(@NotNull BlockState pState, @NotNull PathComputati
};
}

@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();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down