public final class Network
extends java.lang.Object
API.network
may not have been initialized
at that time. Only start calling these methods in the init phase or later.Modifier and Type | Method and Description |
---|---|
static void |
joinNewNetwork(Node node)
Creates a new network with the specified node as its initial node.
|
static void |
joinOrCreateNetwork(net.minecraft.tileentity.TileEntity tileEntity)
Tries to add a tile entity's network node(s) at the specified coordinates
to adjacent networks.
|
static void |
joinWirelessNetwork(WirelessEndpoint endpoint)
Makes a wireless endpoint join the wireless network defined by the mod.
|
static void |
leaveWirelessNetwork(WirelessEndpoint endpoint)
Removes a wireless endpoint from the wireless network.
|
static void |
leaveWirelessNetwork(WirelessEndpoint endpoint,
int dimension)
Removes a wireless endpoint from the wireless network of a specific dimension.
|
static Builder.NodeBuilder |
newNode(Environment host,
Visibility reachability)
Factory function for creating new nodes.
|
static Packet |
newPacket(net.minecraft.nbt.NBTTagCompound nbt)
Re-creates a network packet from a previously stored state.
|
static Packet |
newPacket(java.lang.String source,
java.lang.String destination,
int port,
java.lang.Object[] data)
Creates a new network packet as it would be sent or received by a
network card.
|
static void |
sendWirelessPacket(WirelessEndpoint source,
double strength,
Packet packet)
Sends a packet via the wireless network.
|
static void |
updateWirelessNetwork(WirelessEndpoint endpoint)
Updates a wireless endpoint in the wireless network.
|
public static void joinOrCreateNetwork(net.minecraft.tileentity.TileEntity tileEntity)
Environment
its one node will be
connected to any existing adjacent tile entity nodes. If none exist a
new network with the specified tile entity's node as its sole entry.
If the tile entity is a SidedEnvironment
the same rules as for simple environments apply, except that the
respective for each side is used when connecting, and each side's node
is added to its own new network, if necessary.tileEntity
- the tile entity to initialize.public static void joinNewNetwork(Node node)
node
- the node to create the network for.java.lang.IllegalArgumentException
- if the node already is in a network.public static void joinWirelessNetwork(WirelessEndpoint endpoint)
sendWirelessPacket(WirelessEndpoint, double, Packet)
method. The packets will only be sent to endpoints registered
with the network.
Important: when your endpoint is removed from the world,
you must ensure it is also removed from the network!endpoint
- the endpoint to register with the network.public static void updateWirelessNetwork(WirelessEndpoint endpoint)
endpoint
- the endpoint for which to update the position.public static void leaveWirelessNetwork(WirelessEndpoint endpoint)
endpoint
- the endpoint to remove from the wireless network.public static void leaveWirelessNetwork(WirelessEndpoint endpoint, int dimension)
endpoint
- the endpoint to remove from the wireless network.dimension
- the dimension with the wireless network to remove the endpoint from.public static void sendWirelessPacket(WirelessEndpoint source, double strength, Packet packet)
source
- the endpoint that is sending the message.strength
- the signal strength with which to send the packet.packet
- the packet to send.public static Builder.NodeBuilder newNode(Environment host, Visibility reachability)
class YourThing extends TileEntity implements Environment { private ComponentConnector node_ = api.Network.newNode(this, Visibility.Network). withComponent("your_thing"). withConnector(32). create(); public Node node() { return node_; } // ... }Note that the reachability specified here is the general availability of the created node to other nodes in the network. Special rules apply to components, which have a visibility that is used to control how they can be reached from computers. For example, network cards have a reachability of Visibility.Network, to allow them to communicate with each other, but a visibility of Visibility.Neighbors to avoid other computers in the network to see the card (i.e. only the user programs running on the computer the card installed in can see interact with it).
host
- the environment the node is created for.reachability
- the reachability of the node.public static Packet newPacket(java.lang.String source, java.lang.String destination, int port, java.lang.Object[] data)
source
- the address of the sending node.destination
- the address of the destination, or null
for a broadcast.port
- the port to send the packet to.data
- the payload of the packet.public static Packet newPacket(net.minecraft.nbt.NBTTagCompound nbt)
nbt
- the tag to load the packet from.