From f448b4e850a5dcac48d2f6173ad2dd1994115368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 1 Jan 2014 22:56:02 +0100 Subject: [PATCH] added support for project red bundled redwire, closes #2 --- li/cil/oc/OpenComputers.scala | 2 +- .../tileentity/BundledRedstoneAware.scala | 25 ++++++++++++-- mrtjp/projectred/api/IBundledEmitter.java | 26 ++++++++++++++ mrtjp/projectred/api/IBundledTile.java | 13 +++++++ mrtjp/projectred/api/IConnectable.java | 34 +++++++++++++++++++ mrtjp/projectred/api/IScrewdriver.java | 10 ++++++ mrtjp/projectred/api/ISpecialLinkState.java | 30 ++++++++++++++++ mrtjp/projectred/api/ITransmissionAPI.java | 19 +++++++++++ mrtjp/projectred/api/ITransportationAPI.java | 12 +++++++ mrtjp/projectred/api/ProjectRedAPI.java | 24 +++++++++++++ 10 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 mrtjp/projectred/api/IBundledEmitter.java create mode 100644 mrtjp/projectred/api/IBundledTile.java create mode 100644 mrtjp/projectred/api/IConnectable.java create mode 100644 mrtjp/projectred/api/IScrewdriver.java create mode 100644 mrtjp/projectred/api/ISpecialLinkState.java create mode 100644 mrtjp/projectred/api/ITransmissionAPI.java create mode 100644 mrtjp/projectred/api/ITransportationAPI.java create mode 100644 mrtjp/projectred/api/ProjectRedAPI.java diff --git a/li/cil/oc/OpenComputers.scala b/li/cil/oc/OpenComputers.scala index d68ad00c5f..1c69938192 100644 --- a/li/cil/oc/OpenComputers.scala +++ b/li/cil/oc/OpenComputers.scala @@ -14,7 +14,7 @@ import li.cil.oc.common.Proxy import li.cil.oc.server.{PacketHandler => ServerPacketHandler} @Mod(modid = "OpenComputers", name = "OpenComputers", version = "1.1.0", - dependencies = "required-after:Forge@[9.11.1.940,);after:BuildCraft|Energy;after:ComputerCraft;after:IC2;after:MineFactoryReloaded;after:RedLogic;after:ThermalExpansion", + dependencies = "required-after:Forge@[9.11.1.940,);after:BuildCraft|Energy;after:ComputerCraft;after:IC2;after:MineFactoryReloaded;after:ProjRed|Transmission;after:RedLogic;after:ThermalExpansion", modLanguage = "scala") @NetworkMod(clientSideRequired = true, serverSideRequired = false, clientPacketHandlerSpec = new SidedPacketHandler( diff --git a/li/cil/oc/common/tileentity/BundledRedstoneAware.scala b/li/cil/oc/common/tileentity/BundledRedstoneAware.scala index 0d8321bb3c..dfcf75dcf8 100644 --- a/li/cil/oc/common/tileentity/BundledRedstoneAware.scala +++ b/li/cil/oc/common/tileentity/BundledRedstoneAware.scala @@ -5,6 +5,7 @@ import cpw.mods.fml.common.{Optional, Loader} import li.cil.oc.Settings import li.cil.oc.util.ExtendedNBT._ import mods.immibis.redlogic.api.wiring.{IInsulatedRedstoneWire, IBundledUpdatable, IBundledEmitter} +import mrtjp.projectred.api.{ProjectRedAPI, IBundledTile} import net.minecraft.block.Block import net.minecraft.nbt.{NBTTagIntArray, NBTTagCompound} import net.minecraftforge.common.ForgeDirection @@ -13,9 +14,10 @@ import scala.Array @Optional.InterfaceList(Array( new Interface(iface = "mods.immibis.redlogic.api.wiring.IBundledEmitter", modid = "RedLogic"), - new Interface(iface = "mods.immibis.redlogic.api.wiring.IBundledUpdatable", modid = "RedLogic") + new Interface(iface = "mods.immibis.redlogic.api.wiring.IBundledUpdatable", modid = "RedLogic"), + new Interface(iface = "mrtjp.projectred.api.IBundledTile", modid = "ProjRed|Transmission") )) -trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBundledUpdatable { +trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBundledUpdatable with IBundledTile { private val _bundledInput = Array.fill(6)(Array.fill(16)(-1)) @@ -115,7 +117,7 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund // ----------------------------------------------------------------------- // protected def computeBundledInput(side: ForgeDirection): Array[Int] = { - if (Loader.isModLoaded("RedLogic")) { + val redLogic = if (Loader.isModLoaded("RedLogic")) { world.getBlockTileEntity( x + side.offsetX, y + side.offsetY, @@ -136,6 +138,15 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund case _ => null } } else null + val projectRed = if (Loader.isModLoaded("ProjRed|Transmission")) { + Option(ProjectRedAPI.transmissionAPI.getBundledInput(world, x, y, z, side.ordinal)).fold(null: Array[Int])(_.map(_ & 0xFF)) + } else null + (redLogic, projectRed) match { + case (a: Array[Int], b: Array[Int]) => (a, b).zipped.map((r1, r2) => math.max(r1, r2)) + case (a: Array[Int], _) => a + case (_, b: Array[Int]) => b + case _ => null + } } override protected def onRedstoneOutputChanged(side: ForgeDirection) { @@ -173,4 +184,12 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund @Optional.Method(modid = "RedLogic") def onBundledInputChanged() = checkRedstoneInputChanged() + + // ----------------------------------------------------------------------- // + + @Optional.Method(modid = "ProjRed|Transmission") + def canConnectBundled(side: Int) = isOutputEnabled + + @Optional.Method(modid = "ProjRed|Transmission") + def getBundledSignal(side: Int) = getBundledCableStrength(-1, side) } diff --git a/mrtjp/projectred/api/IBundledEmitter.java b/mrtjp/projectred/api/IBundledEmitter.java new file mode 100644 index 0000000000..c785fbfe40 --- /dev/null +++ b/mrtjp/projectred/api/IBundledEmitter.java @@ -0,0 +1,26 @@ +package mrtjp.projectred.api; + +/** + * Implemented by entities that can emit bundled cable signals. If you are a + * tile entity, see {@link IBundledTile} + */ +public interface IBundledEmitter +{ + /** + * Returns the current emitted bundled cable strength for each colour. The + * bytes are treated as having unsigned values from 0 to 255 - when + * extracting a value from the array, you need to convert it (value & 255). + * + * May return null, which is equivalent to returning an array with all + * values 0. + * + * Array indices are the same as the corresponding wool damage values. + * + * For face parts, side is a rotation. For center parts or tile entities, it + * is a forge direction. + * + * The return value will be used immediately, so the returned array may be + * overwritten by the next call to getBundledSignal. + */ + public byte[] getBundledSignal(int side); +} diff --git a/mrtjp/projectred/api/IBundledTile.java b/mrtjp/projectred/api/IBundledTile.java new file mode 100644 index 0000000000..b19f971c39 --- /dev/null +++ b/mrtjp/projectred/api/IBundledTile.java @@ -0,0 +1,13 @@ +package mrtjp.projectred.api; + +/** + * Interface for tile entities that emit/receive bundled signal. + */ +public interface IBundledTile extends IBundledEmitter +{ + /** + * @param side The side of this tile for which connection is being tested (forge direction ordering) + * @return True if a bundled cable of some form can connect to this side. + */ + public boolean canConnectBundled(int side); +} \ No newline at end of file diff --git a/mrtjp/projectred/api/IConnectable.java b/mrtjp/projectred/api/IConnectable.java new file mode 100644 index 0000000000..03b0c741b0 --- /dev/null +++ b/mrtjp/projectred/api/IConnectable.java @@ -0,0 +1,34 @@ +package mrtjp.projectred.api; + +/** + * Interface implemented by face parts to connect to various types of wires. + */ +public interface IConnectable +{ + /** + * Called to check whether a wire/logic part can connect to this. If a part + * returns true it is expected to immediately reflect the fact that it is + * now connected to wire. + * + * @param part The part asking for connection. + * @param r The clockwise rotation about the attached face to + * @return True to allow the wire connection. + */ + public boolean connectStraight(IConnectable part, int r); + + /** + * Connect for internals. If r is -1 for a face part. Return true for a + * connection to the center part of the block. + */ + public boolean connectInternal(IConnectable part, int r); + + /** + * Connect for corners + */ + public boolean connectCorner(IConnectable part, int r); + + /** + * @return True if this part can reach around a corner to another part. + */ + public boolean canConnectCorner(int r); +} diff --git a/mrtjp/projectred/api/IScrewdriver.java b/mrtjp/projectred/api/IScrewdriver.java new file mode 100644 index 0000000000..7f8dd0678d --- /dev/null +++ b/mrtjp/projectred/api/IScrewdriver.java @@ -0,0 +1,10 @@ +package mrtjp.projectred.api; + +/** + * Marker interface for a screwdriver. Things like gates check if the item used + * to right-click is an instance of this. + */ +public interface IScrewdriver +{ + +} diff --git a/mrtjp/projectred/api/ISpecialLinkState.java b/mrtjp/projectred/api/ISpecialLinkState.java new file mode 100644 index 0000000000..fd7110f3b6 --- /dev/null +++ b/mrtjp/projectred/api/ISpecialLinkState.java @@ -0,0 +1,30 @@ +package mrtjp.projectred.api; + +import java.util.List; + +import net.minecraft.tileentity.TileEntity; + +/** + * Allows adding of special tile entities that point to other BasicPipeParts. + * Used for allowing things such as TE Tesseracts to be used as via points for + * Link-State path finding, which is used to establish a connection from one + * routed pipe to another. This is registered through the ProjectRedAPI. + */ +public interface ISpecialLinkState +{ + /** + * This method should utilize the given tile to find all other tiles that + * connects back and forth. For example, if we have TesseractA (param tile) + * connected to TesseractB, which connects to a few pipes, this method + * should return the tile of all pipes connected to TesseractB. + * + * The given tile is what the pipes found, the returned list is what the + * pipe should consider as found. + * + * @param te The tile in question. + * @return A list of all connected pipes (as tiles, should be + * TileMultipart). This MUST be null if there are no connections of + * this special type. + */ + public List getLinks(TileEntity te); +} diff --git a/mrtjp/projectred/api/ITransmissionAPI.java b/mrtjp/projectred/api/ITransmissionAPI.java new file mode 100644 index 0000000000..70fbacbc8f --- /dev/null +++ b/mrtjp/projectred/api/ITransmissionAPI.java @@ -0,0 +1,19 @@ +package mrtjp.projectred.api; + +import net.minecraft.world.World; + +public interface ITransmissionAPI +{ + /** + * Queries the block on side of this block for the bundled signal being + * emitted to this block. + * + * @param world The world containing the block + * @param x The x coordinate of the block/tile querying signal + * @param y The y coordinate of the block/tile querying signal + * @param z The z coordinate of the block/tile querying signal + * @param side The side of the block + * @return A bundled signal {@link IBundledEmitter} + */ + public byte[] getBundledInput(World world, int x, int y, int z, int side); +} diff --git a/mrtjp/projectred/api/ITransportationAPI.java b/mrtjp/projectred/api/ITransportationAPI.java new file mode 100644 index 0000000000..96a39beca7 --- /dev/null +++ b/mrtjp/projectred/api/ITransportationAPI.java @@ -0,0 +1,12 @@ +package mrtjp.projectred.api; + +public interface ITransportationAPI +{ + /** + * Used to register a special link-state for routed pipes such as TE + * Tesseracts. + * + * @param link + */ + public void registerSpecialLinkState(ISpecialLinkState link); +} diff --git a/mrtjp/projectred/api/ProjectRedAPI.java b/mrtjp/projectred/api/ProjectRedAPI.java new file mode 100644 index 0000000000..27f03fd274 --- /dev/null +++ b/mrtjp/projectred/api/ProjectRedAPI.java @@ -0,0 +1,24 @@ +package mrtjp.projectred.api; + +import net.minecraft.world.World; + +/** + * Central API class for ProjectRed If ProjectRed is installed, the appropriate + * field will contain an implementor of these methods.
+ *
+ * It is recommended that mods access this class within a soft dependency class. + */ +public final class ProjectRedAPI +{ + public static ProjectRedAPI instance; + + /** + * API used for interacting with wires + */ + public static ITransmissionAPI transmissionAPI; + + /** + * API used for interacting with pipes + */ + public static ITransportationAPI transportationAPI; +}