Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ms = require("movescript")
- local robot = require("robot")
- local component = require("component")
- local ic = component.inventory_controller
- local RECHARGE_THRESHOLD = 0.1
- local ENERGY_SLOT = 1
- local ENERGY_ITEM = "thermalexpansion:cell"
- local CHARGER_SLOT = 2
- local CHARGER_ITEM = "opencomputers:charger"
- local RS_BLOCK_SLOT = 3
- local RS_BLOCK_ITEM = "minecraft:redstone_block"
- local args = {...}
- local WIDTH = tonumber(args[1])
- local LENGTH = tonumber(args[2])
- if WIDTH == nil then error("Invalid width") end
- if LENGTH == nil then error("Invalid length") end
- local energyStack = ic.getStackInInternalSlot(ENERGY_SLOT)
- local chargerStack = ic.getStackInInternalSlot(CHARGER_SLOT)
- local rsBlockStack = ic.getStackInInternalSlot(RS_BLOCK_SLOT)
- if energyStack == nil or energyStack.name ~= ENERGY_ITEM then
- error("Energy cell required in slot "..ENERGY_SLOT)
- end
- if chargerStack == nil or chargerStack.name ~= CHARGER_ITEM then
- error("Charger required in slot "..CHARGER_SLOT)
- end
- if rsBlockStack == nil or rsBlockStack.name ~= RS_BLOCK_ITEM then
- error("RS block required in slot "..RS_BLOCK_SLOT)
- end
- local function safeForward()
- robot.swing()
- while not robot.forward() do
- robot.swing()
- end
- end
- local function digAllUp()
- robot.swingUp()
- while robot.detectUp() do
- robot.swingUp()
- end
- end
- local function digRow(startLeft)
- local dir = "L"
- local antiDir = "R"
- if startLeft then dir = "R" antiDir = "L" end
- safeForward()
- if dir == "R" then
- robot.turnRight()
- else
- robot.turnLeft()
- end
- digAllUp()
- robot.swingDown()
- for i=1, WIDTH - 1 do
- safeForward()
- digAllUp()
- robot.swingDown()
- end
- if antiDir == "R" then
- robot.turnRight()
- else
- robot.turnLeft()
- end
- end
- local function rechargeIfNeeded()
- if ms.getEnergyRatio() < RECHARGE_THRESHOLD then
- robot.select(ENERGY_SLOT)
- ms.exec("d_RRUPD")
- robot.select(CHARGER_SLOT)
- ms.exec("d_PD")
- robot.select(RS_BLOCK_SLOT)
- ms.exec("d_PU")
- ms.waitUntilEnergyRatio(0.95)
- robot.select(ENERGY_SLOT)
- ms.exec("d_USD")
- robot.select(CHARGER_SLOT)
- ms.exec("d_SD")
- robot.select(RS_BLOCK_SLOT)
- ms.exec("d_SURR")
- end
- end
- -- assume to start on right.
- local startLeft = false
- for i = 1, LENGTH do
- digRow(startLeft)
- startLeft = not startLeft
- rechargeIfNeeded()
- end
Add Comment
Please, Sign In to add comment