Skip to content

Commit

Permalink
added support for project red bundled redwire, closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuecke committed Jan 1, 2014
1 parent d5978a9 commit f448b4e
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 4 deletions.
2 changes: 1 addition & 1 deletion li/cil/oc/OpenComputers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 22 additions & 3 deletions li/cil/oc/common/tileentity/BundledRedstoneAware.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
26 changes: 26 additions & 0 deletions mrtjp/projectred/api/IBundledEmitter.java
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 13 additions & 0 deletions mrtjp/projectred/api/IBundledTile.java
Original file line number Diff line number Diff line change
@@ -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);
}
34 changes: 34 additions & 0 deletions mrtjp/projectred/api/IConnectable.java
Original file line number Diff line number Diff line change
@@ -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);
}
10 changes: 10 additions & 0 deletions mrtjp/projectred/api/IScrewdriver.java
Original file line number Diff line number Diff line change
@@ -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
{

}
30 changes: 30 additions & 0 deletions mrtjp/projectred/api/ISpecialLinkState.java
Original file line number Diff line number Diff line change
@@ -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<TileEntity> getLinks(TileEntity te);
}
19 changes: 19 additions & 0 deletions mrtjp/projectred/api/ITransmissionAPI.java
Original file line number Diff line number Diff line change
@@ -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);
}
12 changes: 12 additions & 0 deletions mrtjp/projectred/api/ITransportationAPI.java
Original file line number Diff line number Diff line change
@@ -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);
}
24 changes: 24 additions & 0 deletions mrtjp/projectred/api/ProjectRedAPI.java
Original file line number Diff line number Diff line change
@@ -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. <br>
* <br>
* 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;
}

0 comments on commit f448b4e

Please sign in to comment.