mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
Added overload to add world position to a network (still goes through the TE).
Mainly for more comfortable delayed adding when previous TE at that location may now be invalid/replaced.
This commit is contained in:
parent
e90c9ade09
commit
0d45083c43
@ -8,6 +8,8 @@ import li.cil.oc.api.network.Visibility;
|
|||||||
import li.cil.oc.api.network.WirelessEndpoint;
|
import li.cil.oc.api.network.WirelessEndpoint;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides factories for networks and nodes.
|
* This class provides factories for networks and nodes.
|
||||||
@ -29,8 +31,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
*/
|
*/
|
||||||
public final class Network {
|
public final class Network {
|
||||||
/**
|
/**
|
||||||
* Tries to add a tile entity's network node(s) at the specified coordinates
|
* Convenience overload for {@link #joinOrCreateNetwork(IBlockAccess, BlockPos)}.
|
||||||
* to adjacent networks.
|
|
||||||
* <p/>
|
* <p/>
|
||||||
* If the tile entity implements {@link Environment} its one node will be
|
* If the tile entity implements {@link Environment} its one node will be
|
||||||
* connected to any existing adjacent tile entity nodes. If none exist a
|
* connected to any existing adjacent tile entity nodes. If none exist a
|
||||||
@ -48,6 +49,18 @@ public final class Network {
|
|||||||
API.network.joinOrCreateNetwork(tileEntity);
|
API.network.joinOrCreateNetwork(tileEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to add network node(s) at the specified coordinates to adjacent
|
||||||
|
* networks.
|
||||||
|
*
|
||||||
|
* @param world the world containing the location to connect.
|
||||||
|
* @param pos the position at which to update the network.
|
||||||
|
*/
|
||||||
|
public static void joinOrCreateNetwork(final IBlockAccess world, final BlockPos pos) {
|
||||||
|
if (API.network != null)
|
||||||
|
API.network.joinOrCreateNetwork(world, pos);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new network with the specified node as its initial node.
|
* Creates a new network with the specified node as its initial node.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
@ -7,11 +7,12 @@ import li.cil.oc.api.network.Visibility;
|
|||||||
import li.cil.oc.api.network.WirelessEndpoint;
|
import li.cil.oc.api.network.WirelessEndpoint;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
|
||||||
public interface NetworkAPI {
|
public interface NetworkAPI {
|
||||||
/**
|
/**
|
||||||
* Tries to add a tile entity's network node(s) at the specified coordinates
|
* Convenience overload for {@link #joinOrCreateNetwork(IBlockAccess, BlockPos)}.
|
||||||
* to adjacent networks.
|
|
||||||
* <p/>
|
* <p/>
|
||||||
* If the tile entity implements {@link Environment} its one node will be
|
* If the tile entity implements {@link Environment} its one node will be
|
||||||
* connected to any existing adjacent tile entity nodes. If none exist a
|
* connected to any existing adjacent tile entity nodes. If none exist a
|
||||||
@ -26,6 +27,15 @@ public interface NetworkAPI {
|
|||||||
*/
|
*/
|
||||||
void joinOrCreateNetwork(TileEntity tileEntity);
|
void joinOrCreateNetwork(TileEntity tileEntity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to add network node(s) at the specified coordinates to adjacent
|
||||||
|
* networks.
|
||||||
|
*
|
||||||
|
* @param world the world containing the location to connect.
|
||||||
|
* @param pos the position at which to update the network.
|
||||||
|
*/
|
||||||
|
void joinOrCreateNetwork(IBlockAccess world, BlockPos pos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new network with the specified node as its initial node.
|
* Creates a new network with the specified node as its initial node.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
@ -15,6 +15,8 @@ import net.minecraft.item.EnumDyeColor
|
|||||||
import net.minecraft.nbt._
|
import net.minecraft.nbt._
|
||||||
import net.minecraft.tileentity.TileEntity
|
import net.minecraft.tileentity.TileEntity
|
||||||
import net.minecraft.util.EnumFacing
|
import net.minecraft.util.EnumFacing
|
||||||
|
import net.minecraft.util.BlockPos
|
||||||
|
import net.minecraft.world.IBlockAccess
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
@ -421,8 +423,9 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
|||||||
}
|
}
|
||||||
|
|
||||||
object Network extends api.detail.NetworkAPI {
|
object Network extends api.detail.NetworkAPI {
|
||||||
override def joinOrCreateNetwork(tileEntity: TileEntity): Unit =
|
override def joinOrCreateNetwork(world: IBlockAccess, pos: BlockPos): Unit = {
|
||||||
if (!tileEntity.isInvalid && tileEntity.getWorld != null && !tileEntity.getWorld.isRemote) {
|
val tileEntity = world.getTileEntity(pos)
|
||||||
|
if (tileEntity != null && !tileEntity.isInvalid && tileEntity.getWorld != null && !tileEntity.getWorld.isRemote) {
|
||||||
for (side <- EnumFacing.values) {
|
for (side <- EnumFacing.values) {
|
||||||
val npos = tileEntity.getPos.offset(side)
|
val npos = tileEntity.getPos.offset(side)
|
||||||
if (tileEntity.getWorld.isBlockLoaded(npos)) {
|
if (tileEntity.getWorld.isBlockLoaded(npos)) {
|
||||||
@ -447,6 +450,17 @@ object Network extends api.detail.NetworkAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def joinOrCreateNetwork(tileEntity: TileEntity): Unit = {
|
||||||
|
if (tileEntity != null) {
|
||||||
|
val world = tileEntity.getWorld
|
||||||
|
val pos = tileEntity.getPos
|
||||||
|
if (world != null && pos != null) {
|
||||||
|
joinOrCreateNetwork(world, pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def joinNewNetwork(node: ImmutableNode): Unit = node match {
|
def joinNewNetwork(node: ImmutableNode): Unit = node match {
|
||||||
case mutableNode: MutableNode if mutableNode.network == null =>
|
case mutableNode: MutableNode if mutableNode.network == null =>
|
||||||
@ -472,8 +486,8 @@ object Network extends api.detail.NetworkAPI {
|
|||||||
|
|
||||||
private def getConnectionColor(tileEntity: TileEntity): Int = {
|
private def getConnectionColor(tileEntity: TileEntity): Int = {
|
||||||
if (tileEntity != null) {
|
if (tileEntity != null) {
|
||||||
if (tileEntity.hasCapability(Capabilities.ColoredCapability, EnumFacing.DOWN)) {
|
if (tileEntity.hasCapability(Capabilities.ColoredCapability, null)) {
|
||||||
val colored = tileEntity.getCapability(Capabilities.ColoredCapability, EnumFacing.DOWN)
|
val colored = tileEntity.getCapability(Capabilities.ColoredCapability, null)
|
||||||
if (colored != null && colored.controlsConnectivity) return colored.getColor
|
if (colored != null && colored.controlsConnectivity) return colored.getColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user