-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add computercraft compatibility
- Loading branch information
Showing
5 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/core/scala/mrtjp/projectred/compatibility/ComputerCraftCompatibility.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mrtjp.projectred.compatibility | ||
|
||
import dan200.computercraft.api.ComputerCraftAPI | ||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider | ||
import mrtjp.projectred.api.{IBundledTileInteraction, ProjectRedAPI} | ||
import mrtjp.projectred.core.BundledCommons | ||
import net.minecraft.util.Direction | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.world.World | ||
|
||
/** | ||
* Provides bundled cable compatibility with ComputerCraft | ||
*/ | ||
object ComputerCraftCompatibility | ||
{ | ||
def init():Unit = { | ||
if (ProjectRedAPI.transmissionAPI != null) { // Check if Transmission is installed | ||
println("Loading ProjectRed compatibility: ComputerCraft") | ||
ComputerCraftAPI.registerBundledRedstoneProvider(new CCPRBundledRedstoneProvider) | ||
ProjectRedAPI.transmissionAPI.registerBundledTileInteraction(new PRCCBundledTileInteraction) | ||
} | ||
} | ||
|
||
/** | ||
* This is used by ComputerCraft to query bundled signals from third-party entities | ||
*/ | ||
class CCPRBundledRedstoneProvider extends IBundledRedstoneProvider | ||
{ | ||
override def getBundledRedstoneOutput(world:World, pos:BlockPos, side:Direction):Int = { | ||
val sig = ProjectRedAPI.transmissionAPI.getBundledInput(world, pos.relative(side), side.getOpposite) | ||
BundledCommons.packDigital(sig) | ||
} | ||
} | ||
|
||
/** | ||
* On the other side, this is used by ProjectRed to query bundled signals from third-party entities | ||
*/ | ||
class PRCCBundledTileInteraction extends IBundledTileInteraction | ||
{ | ||
override def isValidInteractionFor(world:World, pos:BlockPos, side:Direction):Boolean = | ||
ComputerCraftAPI.getBundledRedstoneOutput(world, pos, side) > -1 | ||
|
||
override def canConnectBundled(world:World, pos:BlockPos, side:Direction):Boolean = true | ||
|
||
override def getBundledSignal(world:World, pos:BlockPos, side:Direction):Array[Byte] = { | ||
val sig = ComputerCraftAPI.getBundledRedstoneOutput(world, pos, side) | ||
BundledCommons.unpackDigital(null, sig) | ||
} | ||
} | ||
} |