mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-09 08:50:29 +00:00
Move can-place modem logic to one place
This should make future changes easier. Closes #1769.
This commit is contained in:
parent
b9ba2534a4
commit
0f623c2cca
@ -4,7 +4,10 @@
|
||||
|
||||
package dan200.computercraft.shared.peripheral.modem;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
@ -22,4 +25,17 @@ public final class ModemShapes {
|
||||
var direction = facing.ordinal();
|
||||
return direction < BOXES.length ? BOXES[direction] : Shapes.block();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a block can support a modem.
|
||||
*
|
||||
* @param level The current level.
|
||||
* @param pos The position of the adjacent block.
|
||||
* @param side The side the modem will be placed against.
|
||||
* @return Whether this block can support a modem.
|
||||
*/
|
||||
public static boolean canSupport(LevelReader level, BlockPos pos, Direction side) {
|
||||
// TODO(1.20.4): Check the side is a full-block instead.
|
||||
return Block.canSupportCenter(level, pos, side);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package dan200.computercraft.shared.peripheral.modem.wired;
|
||||
|
||||
import dan200.computercraft.annotations.ForgeOverride;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemShapes;
|
||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||
import dan200.computercraft.shared.util.WaterloggableHelpers;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
@ -183,7 +184,7 @@ public class CableBlock extends Block implements SimpleWaterloggedBlock, EntityB
|
||||
|
||||
// Pop our modem if needed.
|
||||
var dir = state.getValue(MODEM).getFacing();
|
||||
if (dir != null && dir.equals(side) && !canSupportCenter(level, otherPos, side.getOpposite())) {
|
||||
if (dir != null && dir.equals(side) && !ModemShapes.canSupport(level, otherPos, side.getOpposite())) {
|
||||
// If we've no cable, follow normal Minecraft logic and just remove the block.
|
||||
if (!state.getValue(CABLE)) return getFluidState(state).createLegacyBlock();
|
||||
|
||||
@ -212,7 +213,7 @@ public class CableBlock extends Block implements SimpleWaterloggedBlock, EntityB
|
||||
var facing = state.getValue(MODEM).getFacing();
|
||||
if (facing == null) return true;
|
||||
|
||||
return canSupportCenter(world, pos.relative(facing), facing.getOpposite());
|
||||
return ModemShapes.canSupport(world, pos.relative(facing), facing.getOpposite());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -75,7 +75,7 @@ public class WirelessModemBlock extends DirectionalBlock implements SimpleWaterl
|
||||
@Deprecated
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
var facing = state.getValue(FACING);
|
||||
return canSupportCenter(world, pos.relative(facing), facing.getOpposite());
|
||||
return ModemShapes.canSupport(world, pos.relative(facing), facing.getOpposite());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
Loading…
Reference in New Issue
Block a user