Make cables only directly connect to other cables, but allow bus interface to connect to other bus elements.
This commit is contained in:
@@ -157,7 +157,7 @@ public final class BusCableBlock extends Block {
|
||||
}
|
||||
|
||||
final BlockPos neighborPos = pos.offset(side);
|
||||
if (canConnectTo(world, side, world.getBlockState(neighborPos), neighborPos)) {
|
||||
if (isCableBlock(world.getBlockState(neighborPos))) {
|
||||
world.setBlockState(pos, state.with(property, ConnectionType.LINK));
|
||||
} else {
|
||||
world.setBlockState(pos, state.with(property, ConnectionType.NONE));
|
||||
@@ -205,7 +205,7 @@ public final class BusCableBlock extends Block {
|
||||
for (final Map.Entry<Direction, EnumProperty<ConnectionType>> entry : FACING_TO_CONNECTION_MAP.entrySet()) {
|
||||
final Direction facing = entry.getKey();
|
||||
final BlockPos facingPos = position.offset(facing);
|
||||
if (canConnectTo(world, facing, world.getBlockState(facingPos), facingPos)) {
|
||||
if (isCableBlock(world.getBlockState(facingPos))) {
|
||||
state = state.with(entry.getValue(), ConnectionType.LINK);
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ public final class BusCableBlock extends Block {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState state, final Direction facing, final BlockState facingState, final IWorld world, final BlockPos currentPos, final BlockPos facingPos) {
|
||||
if (canConnectTo(world, facing, facingState, facingPos)) {
|
||||
if (isCableBlock(facingState)) {
|
||||
state = state.with(FACING_TO_CONNECTION_MAP.get(facing), ConnectionType.LINK);
|
||||
} else if (state.get(FACING_TO_CONNECTION_MAP.get(facing)) != ConnectionType.PLUG) {
|
||||
state = state.with(FACING_TO_CONNECTION_MAP.get(facing), ConnectionType.NONE);
|
||||
@@ -284,17 +284,8 @@ public final class BusCableBlock extends Block {
|
||||
return index;
|
||||
}
|
||||
|
||||
private boolean canConnectTo(final IWorld world, final Direction facing, final BlockState facingState, final BlockPos facingPos) {
|
||||
if (facingState.getBlock() == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final TileEntity tileEntity = WorldUtils.getTileEntityIfChunkExists(world, facingPos);
|
||||
if (tileEntity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return tileEntity.getCapability(Capabilities.DEVICE_BUS_ELEMENT, facing.getOpposite()).isPresent();
|
||||
private boolean isCableBlock(final BlockState state) {
|
||||
return state.getBlock() == this;
|
||||
}
|
||||
|
||||
private void onConnectionTypeChanged(final IWorld world, final BlockPos pos, final Direction face) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
|
||||
final ArrayList<LazyOptional<DeviceBusElement>> neighbors = new ArrayList<>();
|
||||
for (final Direction neighborDirection : NEIGHBOR_DIRECTIONS) {
|
||||
if (!canConnectToSide(neighborDirection)) {
|
||||
if (!canScanContinueTowards(neighborDirection)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
final int index = direction.getIndex();
|
||||
|
||||
final HashSet<BlockDeviceInfo> newDevices = new HashSet<>();
|
||||
if (hasInterfaceOnSide(direction)) {
|
||||
if (canDetectDevicesTowards(direction)) {
|
||||
for (final LazyOptional<BlockDeviceInfo> deviceInfo : Devices.getDevices(world, pos, direction)) {
|
||||
deviceInfo.ifPresent(newDevices::add);
|
||||
deviceInfo.addListener(unused -> handleNeighborChanged(pos));
|
||||
@@ -126,12 +126,12 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected boolean canConnectToSide(@Nullable final Direction direction) {
|
||||
protected boolean canScanContinueTowards(@Nullable final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean hasInterfaceOnSide(@Nullable final Direction direction) {
|
||||
return canConnectToSide(direction);
|
||||
protected boolean canDetectDevicesTowards(@Nullable final Direction direction) {
|
||||
return canScanContinueTowards(direction);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -84,13 +84,16 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectToSide(@Nullable final Direction direction) {
|
||||
return BusCableBlock.getConnectionType(getBlockState(), direction) == BusCableBlock.ConnectionType.LINK;
|
||||
public boolean canScanContinueTowards(@Nullable final Direction direction) {
|
||||
final BusCableBlock.ConnectionType connectionType = BusCableBlock.getConnectionType(getBlockState(), direction);
|
||||
return connectionType == BusCableBlock.ConnectionType.LINK ||
|
||||
connectionType == BusCableBlock.ConnectionType.PLUG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasInterfaceOnSide(@Nullable final Direction direction) {
|
||||
return BusCableBlock.getConnectionType(getBlockState(), direction) == BusCableBlock.ConnectionType.PLUG;
|
||||
public boolean canDetectDevicesTowards(@Nullable final Direction direction) {
|
||||
final BusCableBlock.ConnectionType connectionType = BusCableBlock.getConnectionType(getBlockState(), direction);
|
||||
return connectionType == BusCableBlock.ConnectionType.PLUG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,11 +275,6 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectCapabilities(final CapabilityCollector collector, @Nullable final Direction direction) {
|
||||
collector.offer(Capabilities.ITEM_HANDLER, itemHandlers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
final World world = getWorld();
|
||||
@@ -489,6 +484,12 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void collectCapabilities(final CapabilityCollector collector, @Nullable final Direction direction) {
|
||||
collector.offer(Capabilities.ITEM_HANDLER, itemHandlers);
|
||||
collector.offer(Capabilities.DEVICE_BUS_ELEMENT, busElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClient() {
|
||||
super.loadClient();
|
||||
@@ -667,7 +668,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectToSide(@Nullable final Direction direction) {
|
||||
public boolean canScanContinueTowards(@Nullable final Direction direction) {
|
||||
return getBlockState().get(ComputerBlock.HORIZONTAL_FACING) != direction;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user