-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from SquidDev-CC/feature/network-api
Well, how badly can this go?
- Loading branch information
Showing
45 changed files
with
3,133 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/dan200/computercraft/api/network/wired/IWiredElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dan200.computercraft.api.network.wired; | ||
|
||
import dan200.computercraft.api.ComputerCraftAPI; | ||
import dan200.computercraft.api.peripheral.IPeripheral; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* An object which may be part of a wired network. | ||
* | ||
* Elements should construct a node using {@link ComputerCraftAPI#createWiredNodeForElement(IWiredElement)}. This acts | ||
* as a proxy for all network objects. Whilst the node may change networks, an element's node should remain constant | ||
* for its lifespan. | ||
* | ||
* Elements are generally tied to a block or tile entity in world. One should either register an {@link IWiredProvider} | ||
* or implement {@link IWiredElementTile} on your tile entity. | ||
* | ||
* @see IWiredProvider | ||
* @see ComputerCraftAPI#registerWiredProvider(IWiredProvider) | ||
* @see IWiredElementTile | ||
*/ | ||
public interface IWiredElement extends IWiredSender | ||
{ | ||
/** | ||
* Fetch the peripherals this network element provides. | ||
* | ||
* This is only called when initially attaching to a network and after a call to {@link IWiredNode#invalidate()}}, so | ||
* one does not <em>need</em> to cache the return value. | ||
* | ||
* @return The peripherals this node provides. | ||
* @see IWiredNode#invalidate() | ||
*/ | ||
@Nonnull | ||
default Map<String, IPeripheral> getPeripherals() | ||
{ | ||
return Collections.emptyMap(); | ||
} | ||
|
||
/** | ||
* Called when objects on the network change. This may occur when network nodes are added or removed, or when | ||
* peripherals change. | ||
* | ||
* @param change The change which occurred. | ||
* @see IWiredNetworkChange | ||
*/ | ||
default void networkChanged( @Nonnull IWiredNetworkChange change ) | ||
{ | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/dan200/computercraft/api/network/wired/IWiredElementTile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dan200.computercraft.api.network.wired; | ||
|
||
import net.minecraft.util.EnumFacing; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* A {@link net.minecraft.tileentity.TileEntity} which provides a {@link IWiredElement}. This acts | ||
* as a simpler alternative to a full-blown {@link IWiredProvider}. | ||
*/ | ||
public interface IWiredElementTile | ||
{ | ||
/** | ||
* Get the wired element of this tile for a given side. | ||
* | ||
* @param side The side to get the network element from. | ||
* @return A network element, or {@code null} if there is no element here. | ||
*/ | ||
@Nullable | ||
IWiredElement getWiredElement( @Nonnull EnumFacing side ); | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/dan200/computercraft/api/network/wired/IWiredNetwork.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package dan200.computercraft.api.network.wired; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* A wired network is composed of one of more {@link IWiredNode}s, a set of connections between them, and a series | ||
* of peripherals. | ||
* | ||
* Networks from a connected graph. This means there is some path between all nodes on the network. Further more, if | ||
* there is some path between two nodes then they must be on the same network. {@link IWiredNetwork} will automatically | ||
* handle the merging and splitting of networks (and thus changing of available nodes and peripherals) as connections | ||
* change. | ||
* | ||
* This does mean one can not rely on the network remaining consistent between subsequent operations. Consequently, | ||
* it is generally preferred to use the methods provided by {@link IWiredNode}. | ||
* | ||
* @see IWiredNode#getNetwork() | ||
*/ | ||
public interface IWiredNetwork | ||
{ | ||
/** | ||
* Create a connection between two nodes. | ||
* | ||
* This should only be used on the server thread. | ||
* | ||
* @param left The first node to connect | ||
* @param right The second node to connect | ||
* @return {@code true} if a connection was created or {@code false} if the connection already exists. | ||
* @throws IllegalStateException If neither node is on the network. | ||
* @throws IllegalArgumentException If {@code left} and {@code right} are equal. | ||
* @see IWiredNode#connectTo(IWiredNode) | ||
* @see IWiredNetwork#connect(IWiredNode, IWiredNode) | ||
*/ | ||
boolean connect( @Nonnull IWiredNode left, @Nonnull IWiredNode right ); | ||
|
||
/** | ||
* Destroy a connection between this node and another. | ||
* | ||
* This should only be used on the server thread. | ||
* | ||
* @param left The first node in the connection. | ||
* @param right The second node in the connection. | ||
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists. | ||
* @throws IllegalArgumentException If either node is not on the network. | ||
* @throws IllegalArgumentException If {@code left} and {@code right} are equal. | ||
* @see IWiredNode#disconnectFrom(IWiredNode) | ||
* @see IWiredNetwork#connect(IWiredNode, IWiredNode) | ||
*/ | ||
boolean disconnect( @Nonnull IWiredNode left, @Nonnull IWiredNode right ); | ||
|
||
/** | ||
* Sever all connections this node has, removing it from this network. | ||
* | ||
* This should only be used on the server thread. | ||
* | ||
* @param node The node to remove | ||
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the | ||
* only element. | ||
* @throws IllegalArgumentException If the node is not in the network. | ||
* @see IWiredNode#remove() | ||
*/ | ||
boolean remove( @Nonnull IWiredNode node ); | ||
|
||
/** | ||
* Mark this node's peripherals as having changed. | ||
* | ||
* This should only be used on the server thread. | ||
* | ||
* @param node The node to mark as invalid. | ||
* @throws IllegalArgumentException If the node is not in the network. | ||
* @see IWiredElement#getPeripherals() | ||
*/ | ||
void invalidate( @Nonnull IWiredNode node ); | ||
} |
Oops, something went wrong.