Skip to content

Commit

Permalink
Merge pull request #183 from copycats-plus/feature/panes
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine authored Jan 19, 2025
2 parents 05ec83a + 9579e9d commit d450968
Show file tree
Hide file tree
Showing 51 changed files with 1,384 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public class CCBlockEntityTypes {
CCBlocks.COPYCAT_VERTICAL_SLOPE,
CCBlocks.COPYCAT_SLOPE_LAYER,
CCBlocks.COPYCAT_DOOR,
CCBlocks.COPYCAT_IRON_DOOR
CCBlocks.COPYCAT_IRON_DOOR,
CCBlocks.COPYCAT_PANE,
CCBlocks.COPYCAT_FLAT_PANE
)
.register();

Expand Down
31 changes: 30 additions & 1 deletion common/src/main/java/com/copycatsplus/copycats/CCBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import com.copycatsplus.copycats.config.FeatureToggle;
import com.copycatsplus.copycats.content.copycat.cogwheel.CopycatCogWheelModelCore;
import com.copycatsplus.copycats.content.copycat.cogwheel.CopycatLargeCogWheelModelCore;
import com.copycatsplus.copycats.content.copycat.flat_pane.CopycatFlatPaneBlock;
import com.copycatsplus.copycats.content.copycat.flat_pane.CopycatFlatPaneModelCore;
import com.copycatsplus.copycats.content.copycat.shaft.CopycatShaftModelCore;
import com.copycatsplus.copycats.content.copycat.sliding_door.CopycatFoldingDoorModelCore;
import com.copycatsplus.copycats.content.copycat.sliding_door.CopycatSlidingDoorBlock;
import com.copycatsplus.copycats.content.copycat.sliding_door.CopycatSlidingDoorModelCore;
import com.copycatsplus.copycats.content.copycat.pane.CopycatPaneBlock;
import com.copycatsplus.copycats.content.copycat.pane.CopycatPaneModelCore;
import com.copycatsplus.copycats.content.copycat.sliding_door.CopycatSlidingDoorMovementBehaviour;
import com.copycatsplus.copycats.foundation.copycat.CopycatBaseBlock;
import com.copycatsplus.copycats.foundation.copycat.WrappedCopycatBlock;
Expand Down Expand Up @@ -76,7 +80,6 @@
import com.copycatsplus.copycats.foundation.tooltip.CopycatDescription;
import com.copycatsplus.copycats.utility.Platform;
import com.simibubi.create.AllTags;
import com.simibubi.create.content.contraptions.BlockMovementChecks;
import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction;
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorMovementBehaviour;
import com.simibubi.create.content.kinetics.BlockStressDefaults;
Expand Down Expand Up @@ -683,6 +686,19 @@ public class CCBlocks {
.transform(customItemModel("copycat_base", "door"))
.register();

public static final BlockEntry<CopycatPaneBlock> COPYCAT_PANE =
REGISTRATE.block("copycat_pane", CopycatPaneBlock::new)
.transform(CCBuilderTransformers.copycat())
.transform(FeatureToggle.register())
.onRegister(onClient(() -> createBlockModel(CopycatPaneModelCore::new)))
.item()
.onRegister(CopycatDescription.register(
CopycatCharacteristics.COPYCAT,
CopycatCharacteristics.CT_TOGGLE
))
.transform(customItemModel("copycat_base", "pane"))
.register();

public static final BlockEntry<CopycatSlidingDoorBlock> COPYCAT_SLIDING_DOOR =
REGISTRATE.block("copycat_sliding_door", p -> CopycatSlidingDoorBlock.metal(p, false))
.transform(CCBuilderTransformers.copycat())
Expand Down Expand Up @@ -729,6 +745,19 @@ public class CCBlocks {
.transform(customItemModel("copycat_base", "folding_door"))
.register();

public static final BlockEntry<CopycatFlatPaneBlock> COPYCAT_FLAT_PANE =
REGISTRATE.block("copycat_flat_pane", CopycatFlatPaneBlock::new)
.transform(CCBuilderTransformers.copycat())
.transform(FeatureToggle.register())
.onRegister(onClient(() -> createBlockModel(CopycatFlatPaneModelCore::new)))
.item()
.onRegister(CopycatDescription.register(
CopycatCharacteristics.COPYCAT,
CopycatCharacteristics.CT_TOGGLE
))
.transform(customItemModel("copycat_base", "flat_pane"))
.register();

@ExpectPlatform
public static void getWrappedBlockState(DataGenContext<Block, ? extends Block> c, RegistrateBlockstateProvider p, String name) {
throw new AssertionError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class CCCreativeTabs {
CCBlocks.COPYCAT_GHOST_BLOCK,
CCBlocks.COPYCAT_LAYER,
CCBlocks.COPYCAT_HALF_PANEL,
CCBlocks.COPYCAT_PANE,
CCBlocks.COPYCAT_FLAT_PANE,
/* Multi-states */
CCBlocks.COPYCAT_BYTE,
CCBlocks.COPYCAT_BOARD,
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/com/copycatsplus/copycats/CCShapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class CCShapes {
aabb(16, layer * 2, 8).move(0, 0, 8)
)
)));
public static final Map<Axis, MutableShape> HORIZONTAL_PANE = forAxes(shape(
aabb(16, 16, 2).move(0, 0, 7)
));
public static final Map<Direction, Map<Side, Map<VerticalStairShape, MutableShape>>> VERTICAL_STAIR =
forHorizontalDirections(forAll(CopycatVerticalStairBlock.SIDE, CopycatVerticalStairBlock.SHAPE,
(side, shape) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.copycatsplus.copycats.content.copycat.flat_pane;

import com.copycatsplus.copycats.CCBlocks;
import com.copycatsplus.copycats.CCShapes;
import com.copycatsplus.copycats.foundation.copycat.CCWaterloggedCopycatBlock;
import com.copycatsplus.copycats.foundation.copycat.ICopycatBlock;
import com.copycatsplus.copycats.foundation.copycat.ICustomCTBlocking;
import com.copycatsplus.copycats.foundation.copycat.IStateType;
import com.copycatsplus.copycats.utility.InteractionUtils;
import com.simibubi.create.content.contraptions.StructureTransform;
import com.simibubi.create.foundation.placement.IPlacementHelper;
import com.simibubi.create.foundation.placement.PlacementHelpers;
import com.simibubi.create.foundation.placement.PlacementOffset;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.IronBarsBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

@SuppressWarnings("deprecation")
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class CopycatFlatPaneBlock extends CCWaterloggedCopycatBlock implements IStateType, ICustomCTBlocking {

public static final EnumProperty<Axis> AXIS = BlockStateProperties.AXIS;

private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());

public CopycatFlatPaneBlock(Properties pProperties) {
super(pProperties);
registerDefaultState(defaultBlockState().setValue(AXIS, Axis.Y));
}

@Override
public @NotNull InteractionResult use(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand hand,
@NotNull BlockHitResult ray) {
return InteractionUtils.sequential(
() -> InteractionUtils.usePlacementHelper(placementHelperId, state, world, pos, player, hand, ray),
() -> super.use(state, world, pos, player, hand, ray)
);
}

@Override
public boolean isPathfindable(@NotNull BlockState pState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos, @NotNull PathComputationType pType) {
return switch (pType) {
case LAND -> pState.getValue(AXIS).isHorizontal();
default -> false;
};
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
BlockState stateForPlacement = super.getStateForPlacement(context);
if (stateForPlacement == null) return null;
Axis axis = context.getNearestLookingDirection().getAxis();
return stateForPlacement.setValue(AXIS, axis);
}

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

@SuppressWarnings("deprecation")
@Override
public @NotNull VoxelShape getShape(BlockState pState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos, @NotNull CollisionContext pContext) {
return CCShapes.HORIZONTAL_PANE.get(pState.getValue(AXIS)).toShape();
}

@Override
public BlockState transform(BlockState state, StructureTransform transform) {
if (transform.rotationAxis != null) {
state = state.setValue(AXIS, transform.rotateAxis(state.getValue(AXIS)));
}
return state;
}

@Override
public boolean isIgnoredConnectivitySide(BlockAndTintGetter reader, BlockState fromState, Direction face, BlockPos fromPos, BlockPos toPos, BlockState toState) {
return (toState.getBlock() instanceof IronBarsBlock && face.getAxis().isVertical());
}

@Override
public Optional<Boolean> blockCTTowards(BlockAndTintGetter reader, BlockState state, BlockPos pos, BlockPos ctPos, BlockPos connectingPos, Direction face) {
return Optional.of(false);
}

@Override
public Optional<Boolean> isCTBlocked(BlockAndTintGetter reader, BlockState state, BlockPos pos, BlockPos connectingPos, BlockPos blockingPos, Direction face) {
return Optional.of(false);
}

public boolean supportsExternalFaceHiding(BlockState state) {
return true;
}

public boolean hidesNeighborFace(BlockGetter level,
BlockPos pos,
BlockState state,
BlockState neighborState,
Direction dir) {
return ICopycatBlock.hidesNeighborFace(level, pos, state, neighborState, dir);
}

@MethodsReturnNonnullByDefault
private static class PlacementHelper implements IPlacementHelper {
@Override
public Predicate<ItemStack> getItemPredicate() {
return CCBlocks.COPYCAT_FLAT_PANE::isIn;
}

@Override
public Predicate<BlockState> getStatePredicate() {
return CCBlocks.COPYCAT_FLAT_PANE::has;
}

@Override
public PlacementOffset getOffset(Player player, Level world, BlockState state, BlockPos pos,
BlockHitResult ray) {
List<Direction> directions = IPlacementHelper.orderedByDistanceExceptAxis(pos, ray.getLocation(),
state.getValue(AXIS),
dir -> world.getBlockState(pos.relative(dir)).canBeReplaced());

if (directions.isEmpty())
return PlacementOffset.fail();
else {
return PlacementOffset.success(pos.relative(directions.get(0)), s -> s.setValue(AXIS, state.getValue(AXIS)));
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.copycatsplus.copycats.content.copycat.flat_pane;

import com.copycatsplus.copycats.foundation.copycat.model.CopycatModelCore;
import com.copycatsplus.copycats.foundation.copycat.model.assembly.AssemblyTransform;
import com.copycatsplus.copycats.foundation.copycat.model.assembly.CopycatRenderContext;
import net.minecraft.core.Direction.Axis;
import net.minecraft.world.level.block.state.BlockState;

import static com.copycatsplus.copycats.content.copycat.flat_pane.CopycatFlatPaneBlock.AXIS;
import static com.copycatsplus.copycats.foundation.copycat.model.assembly.CopycatRenderContext.*;
import static com.copycatsplus.copycats.foundation.copycat.model.assembly.MutableCullFace.DOWN;
import static com.copycatsplus.copycats.foundation.copycat.model.assembly.MutableCullFace.UP;

public class CopycatFlatPaneModelCore extends CopycatModelCore {

@Override
public void emitCopycatQuads(String key, BlockState state, CopycatRenderContext context, BlockState material) {
Axis axis = state.getValue(AXIS);
int xRot = axis == Axis.Z ? 90 : 0;
int zRot = axis == Axis.X ? 90 : 0;
AssemblyTransform transform = t -> t.rotateX(xRot).rotateZ(zRot);
context.assemblePiece(transform,
vec3(0, 7, 0),
aabb(16, 1, 16),
cull(UP));
context.assemblePiece(transform,
vec3(0, 8, 0),
aabb(16, 1, 16),
cull(DOWN));
}
}
Loading

0 comments on commit d450968

Please sign in to comment.