Merge pull request #38 from repo-alt/feature/AnchorDriver

Railcraft anchors driver
This commit is contained in:
Martin Robertz 2021-12-05 19:47:22 +01:00 committed by GitHub
commit 470421b965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -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)
}
}

View File

@ -14,5 +14,6 @@ object ModRailcraft extends ModProxy {
Driver.add(new DriverBoilerFirebox)
Driver.add(new DriverSteamTurbine)
Driver.add(DriverAnchor)
}
}