1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-10 01:10:30 +00:00

Deprecate WiredNetwork

We don't actually need this to be in the public API.
This commit is contained in:
Jonathan Coates 2024-02-24 14:55:22 +00:00
parent 2d11b51c62
commit 31aaf46d09
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
3 changed files with 17 additions and 8 deletions

View File

@ -5,6 +5,7 @@
package dan200.computercraft.api.network.wired; package dan200.computercraft.api.network.wired;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import org.jetbrains.annotations.ApiStatus;
import java.util.Map; import java.util.Map;
@ -22,6 +23,7 @@ import java.util.Map;
* *
* @see WiredNode#getNetwork() * @see WiredNode#getNetwork()
*/ */
@ApiStatus.NonExtendable
public interface WiredNetwork { public interface WiredNetwork {
/** /**
* Create a connection between two nodes. * Create a connection between two nodes.
@ -35,7 +37,9 @@ public interface WiredNetwork {
* @throws IllegalArgumentException If {@code left} and {@code right} are equal. * @throws IllegalArgumentException If {@code left} and {@code right} are equal.
* @see WiredNode#connectTo(WiredNode) * @see WiredNode#connectTo(WiredNode)
* @see WiredNetwork#connect(WiredNode, WiredNode) * @see WiredNetwork#connect(WiredNode, WiredNode)
* @deprecated Use {@link WiredNode#connectTo(WiredNode)}
*/ */
@Deprecated
boolean connect(WiredNode left, WiredNode right); boolean connect(WiredNode left, WiredNode right);
/** /**
@ -50,7 +54,9 @@ public interface WiredNetwork {
* @throws IllegalArgumentException If {@code left} and {@code right} are equal. * @throws IllegalArgumentException If {@code left} and {@code right} are equal.
* @see WiredNode#disconnectFrom(WiredNode) * @see WiredNode#disconnectFrom(WiredNode)
* @see WiredNetwork#connect(WiredNode, WiredNode) * @see WiredNetwork#connect(WiredNode, WiredNode)
* @deprecated Use {@link WiredNode#disconnectFrom(WiredNode)}
*/ */
@Deprecated
boolean disconnect(WiredNode left, WiredNode right); boolean disconnect(WiredNode left, WiredNode right);
/** /**
@ -64,7 +70,9 @@ public interface WiredNetwork {
* only element. * only element.
* @throws IllegalArgumentException If the node is not in the network. * @throws IllegalArgumentException If the node is not in the network.
* @see WiredNode#remove() * @see WiredNode#remove()
* @deprecated Use {@link WiredNode#remove()}
*/ */
@Deprecated
boolean remove(WiredNode node); boolean remove(WiredNode node);
/** /**
@ -77,6 +85,8 @@ public interface WiredNetwork {
* @param peripherals The new peripherals for this node. * @param peripherals The new peripherals for this node.
* @throws IllegalArgumentException If the node is not in the network. * @throws IllegalArgumentException If the node is not in the network.
* @see WiredNode#updatePeripherals(Map) * @see WiredNode#updatePeripherals(Map)
* @deprecated Use {@link WiredNode#updatePeripherals(Map)}
*/ */
@Deprecated
void updatePeripherals(WiredNode node, Map<String, IPeripheral> peripherals); void updatePeripherals(WiredNode node, Map<String, IPeripheral> peripherals);
} }

View File

@ -6,6 +6,7 @@ package dan200.computercraft.api.network.wired;
import dan200.computercraft.api.network.PacketNetwork; import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import org.jetbrains.annotations.ApiStatus;
import java.util.Map; import java.util.Map;
@ -22,6 +23,7 @@ import java.util.Map;
* Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever * Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever
* be used on the main server thread. * be used on the main server thread.
*/ */
@ApiStatus.NonExtendable
public interface WiredNode extends PacketNetwork { public interface WiredNode extends PacketNetwork {
/** /**
* The associated element for this network node. * The associated element for this network node.
@ -37,7 +39,9 @@ public interface WiredNode extends PacketNetwork {
* This should only be used on the server thread. * This should only be used on the server thread.
* *
* @return This node's network. * @return This node's network.
* @deprecated Use the connect/disconnect/remove methods on {@link WiredNode}.
*/ */
@Deprecated
WiredNetwork getNetwork(); WiredNetwork getNetwork();
/** /**
@ -47,7 +51,6 @@ public interface WiredNode extends PacketNetwork {
* *
* @param node The other node to connect to. * @param node The other node to connect to.
* @return {@code true} if a connection was created or {@code false} if the connection already exists. * @return {@code true} if a connection was created or {@code false} if the connection already exists.
* @see WiredNetwork#connect(WiredNode, WiredNode)
* @see WiredNode#disconnectFrom(WiredNode) * @see WiredNode#disconnectFrom(WiredNode)
*/ */
default boolean connectTo(WiredNode node) { default boolean connectTo(WiredNode node) {
@ -61,12 +64,10 @@ public interface WiredNode extends PacketNetwork {
* *
* @param node The other node to disconnect from. * @param node The other node to disconnect from.
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists. * @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
* @throws IllegalArgumentException If {@code node} is not on the same network.
* @see WiredNetwork#disconnect(WiredNode, WiredNode)
* @see WiredNode#connectTo(WiredNode) * @see WiredNode#connectTo(WiredNode)
*/ */
default boolean disconnectFrom(WiredNode node) { default boolean disconnectFrom(WiredNode node) {
return getNetwork().disconnect(this, node); return getNetwork() == node.getNetwork() && getNetwork().disconnect(this, node);
} }
/** /**
@ -78,7 +79,6 @@ public interface WiredNode extends PacketNetwork {
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the * @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
* only element. * only element.
* @throws IllegalArgumentException If the node is not in the network. * @throws IllegalArgumentException If the node is not in the network.
* @see WiredNetwork#remove(WiredNode)
*/ */
default boolean remove() { default boolean remove() {
return getNetwork().remove(this); return getNetwork().remove(this);
@ -91,7 +91,6 @@ public interface WiredNode extends PacketNetwork {
* that your network element owns. * that your network element owns.
* *
* @param peripherals The new peripherals for this node. * @param peripherals The new peripherals for this node.
* @see WiredNetwork#updatePeripherals(WiredNode, Map)
*/ */
default void updatePeripherals(Map<String, IPeripheral> peripherals) { default void updatePeripherals(Map<String, IPeripheral> peripherals) {
getNetwork().updatePeripherals(this, peripherals); getNetwork().updatePeripherals(this, peripherals);

View File

@ -264,8 +264,8 @@ public class CableBlockEntity extends BlockEntity {
if (CableBlock.canConnectIn(state, facing)) { if (CableBlock.canConnectIn(state, facing)) {
// If we can connect to it then do so // If we can connect to it then do so
this.node.connectTo(node); this.node.connectTo(node);
} else if (this.node.getNetwork() == node.getNetwork()) { } else {
// Otherwise if we're on the same network then attempt to void it. // Otherwise break the connectoin.
this.node.disconnectFrom(node); this.node.disconnectFrom(node);
} }
} }