mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Added interface to allow controlling on which sides SimpleComponent
s can be connected. Closes #844.
This commit is contained in:
parent
068159cdf5
commit
6156ccc1ef
@ -11,7 +11,7 @@ import li.cil.oc.api.detail.*;
|
||||
*/
|
||||
public class API {
|
||||
public static final String ID_OWNER = "OpenComputers|Core";
|
||||
public static final String VERSION = "4.2.2";
|
||||
public static final String VERSION = "4.2.3";
|
||||
|
||||
public static DriverAPI driver = null;
|
||||
public static FileSystemAPI fileSystem = null;
|
||||
|
@ -6,7 +6,7 @@ import li.cil.oc.api.machine.Context;
|
||||
/**
|
||||
* This interface can be used with an {@link li.cil.oc.api.network.Environment}
|
||||
* and is intended to be used for environments wrapping a ComputerCraft
|
||||
* peripheral. Tt could be used for other purposes as well, though. It allows
|
||||
* peripheral. It could be used for other purposes as well, though. It allows
|
||||
* providing method names in addition to those defined via the
|
||||
* {@link li.cil.oc.api.machine.Callback} annotation, and invoking said methods.
|
||||
*/
|
||||
|
26
src/main/java/li/cil/oc/api/network/SidedComponent.java
Normal file
26
src/main/java/li/cil/oc/api/network/SidedComponent.java
Normal file
@ -0,0 +1,26 @@
|
||||
package li.cil.oc.api.network;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* This is an extended version of {@link li.cil.oc.api.network.SimpleComponent}
|
||||
* which allows controlling connectivity on a side-by-side basis.
|
||||
* <p/>
|
||||
* Like the <tt>SimpleComponent</tt> interface, this is intended to be used
|
||||
* with tile entities that should act as OC components. Please see the
|
||||
* <tt>SimpleComponent</tt> interface for more information.
|
||||
*/
|
||||
public interface SidedComponent {
|
||||
/**
|
||||
* Whether this component can connect to a node on the specified side.
|
||||
* <p/>
|
||||
* The provided side is relative to the component, i.e. when the tile
|
||||
* entity sits at (0, 0, 0) and is asked for its southern node (positive
|
||||
* Z axis) it has to return the connectivity for the face between it and
|
||||
* the block at (0, 0, 1).
|
||||
*
|
||||
* @param side the side to check for.
|
||||
* @return whether the component may be connected to from the specified side.
|
||||
*/
|
||||
boolean canConnectNode(ForgeDirection side);
|
||||
}
|
@ -9,6 +9,7 @@ import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api.network.Environment
|
||||
import li.cil.oc.api.network.SidedComponent
|
||||
import li.cil.oc.api.network.SidedEnvironment
|
||||
import li.cil.oc.client.Textures
|
||||
import li.cil.oc.common.tileentity
|
||||
@ -124,6 +125,8 @@ object Cable {
|
||||
case host: SidedEnvironment =>
|
||||
if (host.getWorldObj.isRemote) host.canConnect(side)
|
||||
else host.sidedNode(side) != null
|
||||
case host: Environment with SidedComponent =>
|
||||
host.canConnectNode(side)
|
||||
case host: Environment => true
|
||||
case host if Mods.ForgeMultipart.isAvailable => hasMultiPartNode(tileEntity)
|
||||
case _ => false
|
||||
|
@ -9,11 +9,7 @@ import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.network
|
||||
import li.cil.oc.api.network.Environment
|
||||
import li.cil.oc.api.network.SidedEnvironment
|
||||
import li.cil.oc.api.network.Visibility
|
||||
import li.cil.oc.api.network.WirelessEndpoint
|
||||
import li.cil.oc.api.network.{Node => ImmutableNode}
|
||||
import li.cil.oc.api.network.{Node => ImmutableNode, _}
|
||||
import li.cil.oc.common.block.Cable
|
||||
import li.cil.oc.common.tileentity
|
||||
import li.cil.oc.integration.Mods
|
||||
@ -439,7 +435,10 @@ object Network extends api.detail.NetworkAPI {
|
||||
private def getNetworkNode(tileEntity: TileEntity, side: ForgeDirection) =
|
||||
tileEntity match {
|
||||
case host: SidedEnvironment => Option(host.sidedNode(side))
|
||||
case host: Environment => Some(host.node)
|
||||
case host: Environment with SidedComponent =>
|
||||
if (host.canConnectNode(side)) Option(host.node)
|
||||
else None
|
||||
case host: Environment => Option(host.node)
|
||||
case host if Mods.ForgeMultipart.isAvailable => getMultiPartNode(host)
|
||||
case _ => None
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user