diff --git a/src/main/java/mcjty/rftools/blocks/elevator/ElevatorTileEntity.java b/src/main/java/mcjty/rftools/blocks/elevator/ElevatorTileEntity.java index 2ac4603cd..6a1cc3bf2 100644 --- a/src/main/java/mcjty/rftools/blocks/elevator/ElevatorTileEntity.java +++ b/src/main/java/mcjty/rftools/blocks/elevator/ElevatorTileEntity.java @@ -636,7 +636,7 @@ public boolean isPlatformHere() { } // Can be called on any elevator block. Not only the contoller (bottom one) - private void movePlatformHere() { + public void movePlatformHere() { // Try to find a platform and move it to this elevator. // What about TE blocks in front of platform? diff --git a/src/main/java/mcjty/rftools/compat/computers/ElevatorDriver.java b/src/main/java/mcjty/rftools/compat/computers/ElevatorDriver.java new file mode 100644 index 000000000..cca57fb90 --- /dev/null +++ b/src/main/java/mcjty/rftools/compat/computers/ElevatorDriver.java @@ -0,0 +1,97 @@ +package mcjty.rftools.compat.computers; + +import li.cil.oc.api.machine.Arguments; +import li.cil.oc.api.machine.Callback; +import li.cil.oc.api.machine.Context; +import li.cil.oc.api.prefab.AbstractManagedEnvironment; +import mcjty.lib.integration.computers.AbstractOCDriver; +import mcjty.rftools.blocks.elevator.ElevatorTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.List; + +public class ElevatorDriver { + + public static class OCDriver extends AbstractOCDriver { + + public OCDriver() { + super("rftools_elevator", ElevatorTileEntity.class); + } + + public static class InternalManagedEnvironment extends AbstractOCDriver.InternalManagedEnvironment { + + public InternalManagedEnvironment(ElevatorTileEntity tile) { + super(tile, "rftools_elevator"); + } + + @Callback(doc = "function():number; Get the currently stored energy") + public Object[] getEnergy(Context c, Arguments a) { + BlockPos controllerPos = tile.findBottomElevator(); + ElevatorTileEntity controller = (ElevatorTileEntity) tile.getWorld().getTileEntity(controllerPos); + if(controller == null) { + throw new IllegalStateException("no valid elevator found"); + } + return new Object[] { controller.getStoredPower() }; + } + + @Callback(doc = "function():number; Get the maximum stored energy") + public Object[] getMaxEnergy(Context c, Arguments a) { + BlockPos controllerPos = tile.findBottomElevator(); + ElevatorTileEntity controller = (ElevatorTileEntity) tile.getWorld().getTileEntity(controllerPos); + if(controller == null) { + throw new IllegalStateException("no valid elevator found"); + } + return new Object[] { controller.getCapacity() }; + } + + @Callback(doc = "function():number; Returns the level the elevator is currently at") + public Object[] getCurrentLevel(Context c, Arguments a) { + List heights = new ArrayList<>(); + tile.findElevatorBlocks(heights); + return new Object[] { tile.getCurrentLevel(heights) }; + } + + @Callback(doc = "function():number; Returns the number of levels") + public Object[] getLevelCount(Context c, Arguments a) { + List heights = new ArrayList<>(); + tile.findElevatorBlocks(heights); + return new Object[] { tile.getLevelCount(heights) }; + } + + @Callback(doc = "function():boolean; Returns whether the elevator is currently in motion") + public Object[] isMoving(Context c, Arguments a) { + BlockPos controllerPos = tile.findBottomElevator(); + ElevatorTileEntity controller = (ElevatorTileEntity) tile.getWorld().getTileEntity(controllerPos); + if(controller == null) { + throw new IllegalStateException("no valid elevator found"); + } + return new Object[] { controller.isMoving() }; + } + + @Callback(doc = "function(); Make the elevator go to the level of this controller, if possible") + public Object[] movePlatformHere(Context c, Arguments a) { + tile.movePlatformHere(); + return new Object[] {}; + } + + @Callback(doc = "function():boolean; Returns whether the elevator is at the level of this controller") + public Object[] isPlatformHere(Context c, Arguments a) { + return new Object[] { tile.isPlatformHere() }; + } + + @Override + public int priority() { + return 4; + } + } + + @Override + public AbstractManagedEnvironment createEnvironment(World world, BlockPos pos, EnumFacing side, TileEntity tile) { + return new InternalManagedEnvironment((ElevatorTileEntity) tile); + } + } +} diff --git a/src/main/java/mcjty/rftools/compat/computers/OpenComputersIntegration.java b/src/main/java/mcjty/rftools/compat/computers/OpenComputersIntegration.java index c10c8c7b3..7edd2c8b4 100644 --- a/src/main/java/mcjty/rftools/compat/computers/OpenComputersIntegration.java +++ b/src/main/java/mcjty/rftools/compat/computers/OpenComputersIntegration.java @@ -21,5 +21,6 @@ public static void init() { Driver.add(new EndergenicDriver.OCDriver()); if(CrafterConfiguration.enabled.get()) Driver.add(new CrafterDriver.OCDriver()); + Driver.add(new ElevatorDriver.OCDriver()); } }