SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local ms = require("movescript") |
| 1 | + | local ms = require("movescript")
|
| 2 | - | local robot = require("robot") |
| 2 | + | local robot = require("robot")
|
| 3 | - | local component = require("component") |
| 3 | + | local component = require("component")
|
| 4 | - | local ic = component.inventory_controller |
| 4 | + | local ic = component.inventory_controller |
| 5 | - | |
| 5 | + | |
| 6 | - | local RECHARGE_THRESHOLD = 0.55 |
| 6 | + | local RECHARGE_THRESHOLD = 0.1 |
| 7 | - | local ENERGY_SLOT = 1 |
| 7 | + | local ENERGY_SLOT = 1 |
| 8 | - | local ENERGY_ITEM = "thermalexpansion:cell" |
| 8 | + | local ENERGY_ITEM = "thermalexpansion:cell" |
| 9 | - | local CHARGER_SLOT = 2 |
| 9 | + | local CHARGER_SLOT = 2 |
| 10 | - | local CHARGER_ITEM = "opencomputers:charger" |
| 10 | + | local CHARGER_ITEM = "opencomputers:charger" |
| 11 | - | local RS_BLOCK_SLOT = 3 |
| 11 | + | local RS_BLOCK_SLOT = 3 |
| 12 | - | local RS_BLOCK_ITEM = "minecraft:redstone_block" |
| 12 | + | local RS_BLOCK_ITEM = "minecraft:redstone_block" |
| 13 | - | |
| 13 | + | |
| 14 | - | local args = {...} |
| 14 | + | local args = {...}
|
| 15 | - | local WIDTH = tonumber(args[1]) |
| 15 | + | local WIDTH = tonumber(args[1]) |
| 16 | - | local LENGTH = tonumber(args[2]) |
| 16 | + | local LENGTH = tonumber(args[2]) |
| 17 | - | |
| 17 | + | |
| 18 | - | if WIDTH == nil then error("Invalid width") end |
| 18 | + | if WIDTH == nil then error("Invalid width") end
|
| 19 | - | if LENGTH == nil then error("Invalid length") end |
| 19 | + | if LENGTH == nil then error("Invalid length") end
|
| 20 | - | |
| 20 | + | |
| 21 | - | local energyStack = ic.getStackInInternalSlot(ENERGY_SLOT) |
| 21 | + | local energyStack = ic.getStackInInternalSlot(ENERGY_SLOT) |
| 22 | - | local chargerStack = ic.getStackInInternalSlot(CHARGER_SLOT) |
| 22 | + | local chargerStack = ic.getStackInInternalSlot(CHARGER_SLOT) |
| 23 | - | local rsBlockStack = ic.getStackInInternalSlot(RS_BLOCK_SLOT) |
| 23 | + | local rsBlockStack = ic.getStackInInternalSlot(RS_BLOCK_SLOT) |
| 24 | - | |
| 24 | + | |
| 25 | - | if energyStack == nil or energyStack.name ~= ENERGY_ITEM then |
| 25 | + | if energyStack == nil or energyStack.name ~= ENERGY_ITEM then |
| 26 | - | error("Energy cell required in slot "..ENERGY_SLOT) |
| 26 | + | error("Energy cell required in slot "..ENERGY_SLOT)
|
| 27 | end | |
| 28 | - | if chargerStack == nil or chargerStack.name ~= CHARGER_ITEM then |
| 28 | + | if chargerStack == nil or chargerStack.name ~= CHARGER_ITEM then |
| 29 | - | error("Charger required in slot "..CHARGER_SLOT) |
| 29 | + | error("Charger required in slot "..CHARGER_SLOT)
|
| 30 | end | |
| 31 | - | if rsBlockStack == nil or rsBlockStack.name ~= RS_BLOCK_ITEM then |
| 31 | + | if rsBlockStack == nil or rsBlockStack.name ~= RS_BLOCK_ITEM then |
| 32 | - | error("RS block required in slot "..RS_BLOCK_SLOT) |
| 32 | + | error("RS block required in slot "..RS_BLOCK_SLOT)
|
| 33 | end | |
| 34 | - | |
| 34 | + | |
| 35 | - | local function digRow(startLeft) |
| 35 | + | local function safeForward() |
| 36 | - | local dir = "L" |
| 36 | + | robot.swing() |
| 37 | - | local antiDir = "R" |
| 37 | + | while not robot.forward() do |
| 38 | - | if startLeft then dir = "R" antiDir = "L" end |
| 38 | + | robot.swing() |
| 39 | - | ms.exec("d_SF"..dir.."SuSd") |
| 39 | + | end |
| 40 | - | for i=1, WIDTH - 1 do |
| 40 | + | end |
| 41 | - | ms.exec("d_SFSuSd") |
| 41 | + | |
| 42 | - | end |
| 42 | + | local function digAllUp() |
| 43 | - | ms.exec("d_"..antiDir) |
| 43 | + | robot.swingUp() |
| 44 | while robot.detectUp() do | |
| 45 | - | |
| 45 | + | robot.swingUp() |
| 46 | - | local function rechargeIfNeeded() |
| 46 | + | end |
| 47 | - | if ms.getEnergyRatio() < RECHARGE_THRESHOLD then |
| 47 | + | end |
| 48 | - | robot.select(ENERGY_SLOT) |
| 48 | + | |
| 49 | - | ms.exec("d_RRUPD") |
| 49 | + | local function digRow(startLeft) |
| 50 | - | robot.select(CHARGER_SLOT) |
| 50 | + | local dir = "L" |
| 51 | - | ms.exec("d_PD") |
| 51 | + | local antiDir = "R" |
| 52 | - | robot.select(RS_BLOCK_SLOT) |
| 52 | + | if startLeft then dir = "R" antiDir = "L" end |
| 53 | - | ms.exec("d_PU") |
| 53 | + | safeForward() |
| 54 | - | ms.waitUntilEnergyRatio(0.95) |
| 54 | + | if dir == "R" then |
| 55 | - | robot.select(ENERGY_SLOT) |
| 55 | + | robot.turnRight() |
| 56 | - | ms.exec("d_USD") |
| 56 | + | else |
| 57 | - | robot.select(CHARGER_SLOT) |
| 57 | + | robot.turnLeft() |
| 58 | - | ms.exec("d_SD") |
| 58 | + | end |
| 59 | - | robot.select(RS_BLOCK_SLOT) |
| 59 | + | digAllUp() |
| 60 | - | ms.exec("d_SURR") |
| 60 | + | robot.swingDown() |
| 61 | - | end |
| 61 | + | for i=1, WIDTH - 1 do |
| 62 | safeForward() | |
| 63 | - | |
| 63 | + | digAllUp() |
| 64 | - | -- assume to start on right. |
| 64 | + | robot.swingDown() |
| 65 | - | local startLeft = false |
| 65 | + | end |
| 66 | - | for i = 1, LENGTH do |
| 66 | + | if antiDir == "R" then |
| 67 | - | digRow(startLeft) |
| 67 | + | robot.turnRight() |
| 68 | - | startLeft = not startLeft |
| 68 | + | else |
| 69 | - | rechargeIfNeeded() |
| 69 | + | robot.turnLeft() |
| 70 | end | |
| 71 | end | |
| 72 | ||
| 73 | local function rechargeIfNeeded() | |
| 74 | if ms.getEnergyRatio() < RECHARGE_THRESHOLD then | |
| 75 | robot.select(ENERGY_SLOT) | |
| 76 | ms.exec("d_RRUPD")
| |
| 77 | robot.select(CHARGER_SLOT) | |
| 78 | ms.exec("d_PD")
| |
| 79 | robot.select(RS_BLOCK_SLOT) | |
| 80 | ms.exec("d_PU")
| |
| 81 | ms.waitUntilEnergyRatio(0.95) | |
| 82 | robot.select(ENERGY_SLOT) | |
| 83 | ms.exec("d_USD")
| |
| 84 | robot.select(CHARGER_SLOT) | |
| 85 | ms.exec("d_SD")
| |
| 86 | robot.select(RS_BLOCK_SLOT) | |
| 87 | ms.exec("d_SURR")
| |
| 88 | end | |
| 89 | end | |
| 90 | ||
| 91 | -- assume to start on right. | |
| 92 | local startLeft = false | |
| 93 | for i = 1, LENGTH do | |
| 94 | digRow(startLeft) | |
| 95 | startLeft = not startLeft | |
| 96 | rechargeIfNeeded() | |
| 97 | end |