Make sides and front of projector non "solid" to avoid torch placement and such.
This commit is contained in:
@@ -54,7 +54,7 @@ import static li.cil.oc2.common.util.RegistryUtils.key;
|
||||
import static li.cil.oc2.common.util.TranslationUtils.text;
|
||||
|
||||
public final class ComputerBlock extends ImmutableHorizontalBlock implements EntityBlock {
|
||||
// We bake the "screen" indent on the front into the collision shape to prevent stuff being
|
||||
// We bake the "screen" indent on the front into the collision shape, to prevent stuff being
|
||||
// placeable on that side, such as network connectors, torches, etc.
|
||||
private static final VoxelShape NEG_Z_SHAPE = Shapes.or(
|
||||
Block.box(0, 0, 1, 16, 16, 16), // main body
|
||||
|
||||
@@ -2,9 +2,11 @@ package li.cil.oc2.common.block;
|
||||
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.blockentity.TickableBlockEntity;
|
||||
import li.cil.oc2.common.util.VoxelShapeUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
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.EntityBlock;
|
||||
@@ -16,10 +18,24 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class ProjectorBlock extends HorizontalDirectionalBlock implements EntityBlock {
|
||||
// We bake the visual indents on the front and sides into the collision shape, to prevent stuff being
|
||||
// placeable on those sides, such as network connectors, torches, etc.
|
||||
private static final VoxelShape NEG_Z_SHAPE = Shapes.join(Shapes.block(), Shapes.or(
|
||||
Shapes.box(0 / 16f, 2 / 16f, 2 / 16f, 1 / 16f, 6 / 16f, 14 / 16f),
|
||||
Shapes.box(15 / 16f, 2 / 16f, 2 / 16f, 16 / 16f, 6 / 16f, 14 / 16f),
|
||||
Shapes.box(4 / 16f, 4 / 16f, 0 / 16f, 12 / 16f, 12 / 16f, 2 / 16f)
|
||||
), (a, b) -> a && !b);
|
||||
private static final VoxelShape NEG_X_SHAPE = VoxelShapeUtils.rotateHorizontalClockwise(NEG_Z_SHAPE);
|
||||
private static final VoxelShape POS_Z_SHAPE = VoxelShapeUtils.rotateHorizontalClockwise(NEG_X_SHAPE);
|
||||
private static final VoxelShape POS_X_SHAPE = VoxelShapeUtils.rotateHorizontalClockwise(POS_Z_SHAPE);
|
||||
|
||||
public ProjectorBlock() {
|
||||
super(Properties
|
||||
.of(Material.METAL)
|
||||
@@ -42,6 +58,17 @@ public final class ProjectorBlock extends HorizontalDirectionalBlock implements
|
||||
return TickableBlockEntity.createServerTicker(level, type, BlockEntities.PROJECTOR.get());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos blockPos, final CollisionContext context) {
|
||||
return switch (state.getValue(FACING)) {
|
||||
case NORTH -> NEG_Z_SHAPE;
|
||||
case SOUTH -> POS_Z_SHAPE;
|
||||
case WEST -> NEG_X_SHAPE;
|
||||
default -> POS_X_SHAPE;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
||||
return super.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
|
||||
|
||||
Reference in New Issue
Block a user