diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java index 33d255002..39e5fd323 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java @@ -3,16 +3,16 @@ import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import javax.annotation.Nullable; - import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; +import net.minecraft.core.GlobalPos; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import org.apiguardian.api.API; +import static java.util.Objects.requireNonNull; + @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.2") public abstract class AbstractNetworkNodeContainerBlockEntity extends BlockEntity implements PlatformNetworkNodeContainer { @@ -63,12 +63,14 @@ public T getNode() { } @Override - public boolean canPerformOutgoingConnection(final Direction direction) { - return true; + public void addOutgoingConnections(final ConnectionSink sink) { + for (final Direction direction : Direction.values()) { + sink.tryConnectInSameDimension(worldPosition.relative(direction), direction.getOpposite()); + } } @Override - public boolean canAcceptIncomingConnection(final Direction direction, final BlockState other) { + public boolean canAcceptIncomingConnection(final Direction incomingDirection, final BlockState connectingState) { return true; } @@ -77,15 +79,9 @@ public BlockState getContainerBlockState() { return getBlockState(); } - @Nullable - @Override - public Level getContainerLevel() { - return getLevel(); - } - @Override - public BlockPos getContainerPosition() { - return getBlockPos(); + public GlobalPos getContainerPosition() { + return GlobalPos.of(requireNonNull(level).dimension(), worldPosition); } @Override diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/ConnectionSink.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/ConnectionSink.java new file mode 100644 index 000000000..e7baa0690 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/ConnectionSink.java @@ -0,0 +1,11 @@ +package com.refinedmods.refinedstorage2.platform.api.support.network; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.2") +@FunctionalInterface +public interface ConnectionSink { + void tryConnectInSameDimension(BlockPos pos, Direction incomingDirection); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/PlatformNetworkNodeContainer.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/PlatformNetworkNodeContainer.java index aa1f9f806..5ce90b0b2 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/PlatformNetworkNodeContainer.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/PlatformNetworkNodeContainer.java @@ -2,10 +2,8 @@ import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.GlobalPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import org.apiguardian.api.API; @@ -13,32 +11,28 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.1") public interface PlatformNetworkNodeContainer extends NetworkNodeContainer { /** - * Returns whether the already discovered node can perform an outgoing connection. - * Changes to this return value won't cause a rebuild of the network state. - * If the return value ever changes, call {@link + * Called when a node is about to be added into the network graph. + * Add outgoing connections here. + * If the outgoing connections ever change, call {@link * com.refinedmods.refinedstorage2.platform.api.PlatformApi#requestNetworkNodeUpdate(NetworkNodeContainer, Level)}. * - * @param direction the outgoing direction - * @return whether the node can perform an outgoing connection + * @param sink the sink that accepts outgoing connections */ - boolean canPerformOutgoingConnection(Direction direction); + void addOutgoingConnections(ConnectionSink sink); /** - * Returns whether the not yet discovered node can accept an incoming connection. + * Returns whether the (not yet discovered) node can accept an incoming connection. * Changes to this return value won't cause a rebuild of the network state. * If the return value ever changes, call {@link * com.refinedmods.refinedstorage2.platform.api.PlatformApi#requestNetworkNodeUpdate(NetworkNodeContainer, Level)}. * - * @param direction the incoming direction - * @param other the state wanting to connect + * @param incomingDirection the incoming direction + * @param connectingState the state wanting to connect * @return whether the node can accept an incoming connection */ - boolean canAcceptIncomingConnection(Direction direction, BlockState other); + boolean canAcceptIncomingConnection(Direction incomingDirection, BlockState connectingState); BlockState getContainerBlockState(); - @Nullable - Level getContainerLevel(); - - BlockPos getContainerPosition(); + GlobalPos getContainerPosition(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index e20fbd662..442204f50 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -61,7 +61,7 @@ import com.refinedmods.refinedstorage2.platform.common.storagemonitor.CompositeStorageMonitorInsertionStrategy; import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.support.energy.ItemEnergyStorage; -import com.refinedmods.refinedstorage2.platform.common.support.network.LevelConnectionProvider; +import com.refinedmods.refinedstorage2.platform.common.support.network.ConnectionProviderImpl; import com.refinedmods.refinedstorage2.platform.common.support.network.bounditem.CompositeSlotReferenceProvider; import com.refinedmods.refinedstorage2.platform.common.support.network.bounditem.InventorySlotReference; import com.refinedmods.refinedstorage2.platform.common.support.network.bounditem.InventorySlotReferenceFactory; @@ -291,7 +291,7 @@ public BuiltinUpgradeDestinations getBuiltinUpgradeDestinations() { public void requestNetworkNodeInitialization(final NetworkNodeContainer container, final Level level, final Runnable callback) { - final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(level); ServerEventQueue.queue(() -> { networkBuilder.initialize(container, connectionProvider); callback.run(); @@ -300,13 +300,13 @@ public void requestNetworkNodeInitialization(final NetworkNodeContainer containe @Override public void requestNetworkNodeRemoval(final NetworkNodeContainer container, final Level level) { - final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(level); networkBuilder.remove(container, connectionProvider); } @Override public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final Level level) { - final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(level); networkBuilder.update(container, connectionProvider); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java index ccaf24ae2..657415381 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorAmountStrategyImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorMode; import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorNetworkNode; +import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.common.Platform; @@ -152,23 +153,28 @@ public void updateActiveness(final BlockState state, @Nullable final BooleanProp } @Override - public boolean canAcceptIncomingConnection(final Direction direction, final BlockState other) { - if (!colorsAllowConnecting(other)) { - return false; - } + public void addOutgoingConnections(final ConnectionSink sink) { final Direction myDirection = getDirection(); - if (myDirection != null) { - return myDirection != direction; + if (myDirection == null) { + return; + } + for (final Direction direction : Direction.values()) { + if (direction == myDirection.getOpposite()) { + continue; + } + sink.tryConnectInSameDimension(worldPosition.relative(direction), direction.getOpposite()); } - return true; } @Override - public boolean canPerformOutgoingConnection(final Direction direction) { + public boolean canAcceptIncomingConnection(final Direction incomingDirection, final BlockState connectingState) { + if (!colorsAllowConnecting(connectingState)) { + return false; + } final Direction myDirection = getDirection(); - if (myDirection == null) { - return true; + if (myDirection != null) { + return myDirection != incomingDirection.getOpposite(); } - return myDirection != direction.getOpposite(); + return true; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/CableBlockSupport.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/CableBlockSupport.java index 987b285f6..94a10fe4d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/CableBlockSupport.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/CableBlockSupport.java @@ -117,6 +117,6 @@ private static boolean hasVisualConnection( if (!(world.getBlockEntity(offsetPos) instanceof PlatformNetworkNodeContainer neighboringContainer)) { return false; } - return neighboringContainer.canAcceptIncomingConnection(direction, blockState); + return neighboringContainer.canAcceptIncomingConnection(direction.getOpposite(), blockState); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/LevelConnectionProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionProviderImpl.java similarity index 64% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/LevelConnectionProvider.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionProviderImpl.java index 6b8ef307e..d8238dfa0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/LevelConnectionProvider.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionProviderImpl.java @@ -6,19 +6,17 @@ import com.refinedmods.refinedstorage2.platform.api.support.network.PlatformNetworkNodeContainer; import java.util.ArrayDeque; -import java.util.Collections; +import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Queue; import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceKey; +import net.minecraft.core.GlobalPos; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -26,12 +24,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class LevelConnectionProvider implements ConnectionProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(LevelConnectionProvider.class); +public class ConnectionProviderImpl implements ConnectionProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionProviderImpl.class); private final Level originLevel; - public LevelConnectionProvider(final Level originLevel) { + public ConnectionProviderImpl(final Level originLevel) { this.originLevel = originLevel; } @@ -44,11 +42,11 @@ public Connections findConnections(final NetworkNodeContainer pivot, .collect(Collectors.toSet()); LOGGER.info("Finding connections for pivot {} with {} existing connections", pivot, existingConnections.size()); final ScanState scanState = new ScanState(existingPlatformConnections); - addInitialRequest(pivot, scanState); - ScanRequest currentRequest; + addStartContainer(pivot, scanState); + PlatformNetworkNodeContainer currentContainer; int requests = 0; - while ((currentRequest = scanState.toCheck.poll()) != null) { - visit(scanState, currentRequest); + while ((currentContainer = scanState.toCheck.poll()) != null) { + visit(scanState, new ScanEntry(currentContainer)); requests++; } LOGGER.info( @@ -62,25 +60,11 @@ public Connections findConnections(final NetworkNodeContainer pivot, return scanState.toConnections(); } - private void addInitialRequest(final NetworkNodeContainer pivot, final ScanState scanState) { + private void addStartContainer(final NetworkNodeContainer pivot, final ScanState scanState) { if (!(pivot instanceof PlatformNetworkNodeContainer platformPivot)) { return; } - final Level pivotLevel = platformPivot.getContainerLevel(); - if (pivotLevel == null) { - LOGGER.warn("Pivot level was null for {}", pivot); - return; - } - scanState.toCheck.add(new ScanRequest( - pivotLevel.dimension(), - platformPivot.getContainerPosition() - )); - } - - private void visit(final ScanState state, final ScanRequest request) { - if (getBlockEntity(request.dimension, request.position) instanceof PlatformNetworkNodeContainer container) { - visit(state, new ScanEntry(container, originLevel, request.position)); - } + scanState.toCheck.add(platformPivot); } private void visit(final ScanState state, final ScanEntry entry) { @@ -92,27 +76,38 @@ private void visit(final ScanState state, final ScanEntry entry) { state.newEntries.add(entry); } state.removedEntries.remove(entry); - final Set connections = findConnectionsAt(entry.getContainer()); + final List connections = findConnectionsAt(entry.getContainer()); state.toCheck.addAll(connections); } - private Set findConnectionsAt(final PlatformNetworkNodeContainer from) { - final Level level = from.getContainerLevel(); - if (level == null) { - return Collections.emptySet(); - } - final Set requests = new HashSet<>(); - for (final Direction direction : Direction.values()) { - if (!from.canPerformOutgoingConnection(direction)) { - continue; - } - final BlockPos offsetPos = from.getContainerPosition().relative(direction); - if (getBlockEntity(level, offsetPos) instanceof PlatformNetworkNodeContainer neighborContainer - && neighborContainer.canAcceptIncomingConnection(direction, from.getContainerBlockState())) { - requests.add(new ScanRequest(level.dimension(), offsetPos)); + private List findConnectionsAt(final PlatformNetworkNodeContainer from) { + final ConnectionSinkImpl sink = new ConnectionSinkImpl(from.getContainerPosition()); + from.addOutgoingConnections(sink); + final List connections = new ArrayList<>(); + for (final ConnectionSinkImpl.Connection connection : sink.getConnections()) { + final PlatformNetworkNodeContainer connectionContainer = getConnection(from, connection); + if (connectionContainer != null) { + connections.add(connectionContainer); } } - return requests; + return connections; + } + + @Nullable + private PlatformNetworkNodeContainer getConnection(final PlatformNetworkNodeContainer from, + final ConnectionSinkImpl.Connection connection) { + final BlockEntity connectionBlockEntity = getBlockEntitySafely(connection.pos()); + if (!(connectionBlockEntity instanceof PlatformNetworkNodeContainer connectionContainer)) { + return null; + } + final boolean acceptsIncomingDirection = connectionContainer.canAcceptIncomingConnection( + connection.incomingDirection(), + from.getContainerBlockState() + ); + if (!acceptsIncomingDirection) { + return null; + } + return connectionContainer; } @Override @@ -124,20 +119,20 @@ public List sortDeterministically(final Set dimension, final BlockPos pos) { + private BlockEntity getBlockEntitySafely(final GlobalPos pos) { final MinecraftServer server = originLevel.getServer(); if (server == null) { return null; } - final Level level = server.getLevel(dimension); + final Level level = server.getLevel(pos.dimension()); if (level == null) { return null; } - return getBlockEntity(level, pos); + return getBlockEntitySafely(level, pos.pos()); } @Nullable - private BlockEntity getBlockEntity(final Level level, final BlockPos pos) { + private BlockEntity getBlockEntitySafely(final Level level, final BlockPos pos) { if (!level.isLoaded(pos)) { return null; } @@ -159,7 +154,7 @@ private static class ScanState { private final Set foundEntries = new HashSet<>(); private final Set newEntries = new HashSet<>(); private final Set removedEntries; - private final Queue toCheck = new ArrayDeque<>(); + private final Queue toCheck = new ArrayDeque<>(); ScanState(final Set existingConnections) { this.currentEntries = toScanEntries(existingConnections); @@ -179,23 +174,17 @@ private Set toContainers(final Set entries) { } private static Set toScanEntries(final Set existingConnections) { - return existingConnections.stream().map(container -> new ScanEntry( - container, - Objects.requireNonNull(container.getContainerLevel()), - Objects.requireNonNull(container.getContainerPosition()) - )).collect(Collectors.toSet()); + return existingConnections.stream().map(ScanEntry::new).collect(Collectors.toSet()); } } private static class ScanEntry { private final PlatformNetworkNodeContainer container; - private final ResourceKey dimension; - private final BlockPos position; + private final GlobalPos pos; - ScanEntry(final PlatformNetworkNodeContainer container, final Level dimension, final BlockPos position) { + ScanEntry(final PlatformNetworkNodeContainer container) { this.container = container; - this.dimension = dimension.dimension(); - this.position = position; + this.pos = container.getContainerPosition(); } public PlatformNetworkNodeContainer getContainer() { @@ -211,15 +200,12 @@ public boolean equals(final Object o) { return false; } final ScanEntry that = (ScanEntry) o; - return Objects.equals(dimension, that.dimension) && Objects.equals(position, that.position); + return pos.equals(that.pos); } @Override public int hashCode() { - return Objects.hash(dimension, position); + return pos.hashCode(); } } - - private record ScanRequest(ResourceKey dimension, BlockPos position) { - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionSinkImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionSinkImpl.java new file mode 100644 index 000000000..36024462d --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionSinkImpl.java @@ -0,0 +1,32 @@ +package com.refinedmods.refinedstorage2.platform.common.support.network; + +import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; + +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.GlobalPos; + +class ConnectionSinkImpl implements ConnectionSink { + private final GlobalPos source; + private final Set connections = new HashSet<>(); + + ConnectionSinkImpl(final GlobalPos source) { + this.source = source; + } + + Set getConnections() { + return connections; + } + + @Override + public void tryConnectInSameDimension(final BlockPos pos, final Direction incomingDirection) { + final GlobalPos globalPos = GlobalPos.of(source.dimension(), pos); + connections.add(new Connection(globalPos, incomingDirection)); + } + + record Connection(GlobalPos pos, Direction incomingDirection) { + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java index 40f3dbe1d..a5074ac22 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.support.network.AbstractNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; import com.refinedmods.refinedstorage2.platform.common.support.AbstractDirectionalBlock; import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; @@ -77,28 +78,34 @@ public void doWork() { } @Override - public boolean canPerformOutgoingConnection(final Direction direction) { + public void addOutgoingConnections(final ConnectionSink sink) { final Direction myDirection = getDirection(); if (myDirection == null) { - return true; + super.addOutgoingConnections(sink); + return; + } + for (final Direction direction : Direction.values()) { + if (direction == myDirection) { + continue; + } + sink.tryConnectInSameDimension(worldPosition.relative(direction), direction.getOpposite()); } - return myDirection != direction; } @Override - public boolean canAcceptIncomingConnection(final Direction direction, final BlockState other) { - if (!colorsAllowConnecting(other)) { + public boolean canAcceptIncomingConnection(final Direction incomingDirection, final BlockState connectingState) { + if (!colorsAllowConnecting(connectingState)) { return false; } final Direction myDirection = getDirection(); if (myDirection != null) { - return myDirection != direction.getOpposite(); + return myDirection != incomingDirection; } return true; } - protected final boolean colorsAllowConnecting(final BlockState other) { - if (!(other.getBlock() instanceof ColorableBlock otherColorableBlock)) { + protected final boolean colorsAllowConnecting(final BlockState connectingState) { + if (!(connectingState.getBlock() instanceof ColorableBlock otherColorableBlock)) { return true; } final ColorableBlock colorableBlock = getColor(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlockEntity.java index 085a57029..ca0f9cfc2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlockEntity.java @@ -2,6 +2,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; import com.refinedmods.refinedstorage2.platform.api.wirelesstransmitter.WirelessTransmitter; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -61,13 +62,21 @@ public void load(final CompoundTag tag) { } @Override - public boolean canPerformOutgoingConnection(final Direction direction) { - return direction == getDirection(); + public void addOutgoingConnections(final ConnectionSink sink) { + final Direction myDirection = getDirection(); + if (myDirection == null) { + return; + } + sink.tryConnectInSameDimension(worldPosition.relative(myDirection), myDirection.getOpposite()); } @Override - public boolean canAcceptIncomingConnection(final Direction direction, final BlockState other) { - return colorsAllowConnecting(other) && direction.getOpposite() == getDirection(); + public boolean canAcceptIncomingConnection(final Direction incomingDirection, final BlockState connectingState) { + if (!colorsAllowConnecting(connectingState)) { + return false; + } + final Direction myDirection = getDirection(); + return incomingDirection == myDirection; } @Override