Skip to content

Commit

Permalink
Railcraft anchors driver
Browse files Browse the repository at this point in the history
API:
    "getFuel():int -- Get remaining anchor time in ticks."
    "getOwner():string -- Get the  anchor owner name."
    "getType():string -- Get the anchor type."
    "getFuelSlotContents():table -- Get the anchor input slot contents."
    "isDisabled():boolean -- If the anchor is disabled with redstone."

GTNewHorizons/GT-New-Horizons-Modpack#8994
  • Loading branch information
repo-alt authored and asiekierka committed Jun 4, 2023
1 parent a4a3b77 commit c7ebcca
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/scala/li/cil/oc/integration/railcraft/DriverAnchor.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package li.cil.oc.integration.railcraft


import li.cil.oc.api.driver.NamedBlock
import li.cil.oc.api.machine.{Arguments, Callback, Context}
import li.cil.oc.api.network.ManagedEnvironment
import li.cil.oc.api.prefab.DriverSidedTileEntity
import li.cil.oc.integration.ManagedTileEntityEnvironment
import li.cil.oc.util.ResultWrapper.result
import mods.railcraft.common.blocks.machine.alpha.{EnumMachineAlpha, TileAnchorWorld}
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection

object DriverAnchor extends DriverSidedTileEntity {
def getTileEntityClass: Class[_] = classOf[TileAnchorWorld]

def createEnvironment(world: World, x: Int, y: Int, z: Int, side: ForgeDirection): ManagedEnvironment =
new Environment(world.getTileEntity(x, y, z).asInstanceOf[TileAnchorWorld])

final class Environment(val tile: TileAnchorWorld) extends ManagedTileEntityEnvironment[TileAnchorWorld](tile, "anchor") with NamedBlock {
override def preferredName = "anchor"
override def priority = 5

@Callback(doc = "function():int -- Get remaining anchor time in ticks.")
def getFuel(context: Context, args: Arguments): Array[AnyRef] = result(tile.getAnchorFuel)

@Callback(doc = "function():string -- Get the anchor owner name.")
def getOwner(context: Context, args: Arguments): Array[AnyRef] = result(tile.getOwner.getName)

@Callback(doc = "function():string -- Get the anchor type.")
def getType(context: Context, args: Arguments): Array[AnyRef] = tile.getMachineType match {
case EnumMachineAlpha.WORLD_ANCHOR => result("world")
case EnumMachineAlpha.ADMIN_ANCHOR => result("admin")
case EnumMachineAlpha.PERSONAL_ANCHOR => result("personal")
case _ => result("passive")
}

@Callback(doc = "function():table -- Get the anchor input slot contents.")
def getFuelSlotContents(context: Context, args: Arguments): Array[AnyRef] = result(tile.getStackInSlot(0))

@Callback(doc = "function():boolean -- If the anchor is disabled with redstone.")
def isDisabled(context: Context, args: Arguments): Array[AnyRef] = result(tile.isPowered)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ object ModRailcraft extends ModProxy {

Driver.add(new DriverBoilerFirebox)
Driver.add(new DriverSteamTurbine)
Driver.add(DriverAnchor)
}
}

0 comments on commit c7ebcca

Please sign in to comment.