Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---Loads a locally saved table and returns it
- ---@param path string a valid filepath
- ---@return table params or empty table
- local function loadParams(path)
- local file = fs.open(path, "r")
- if file ~= nil then
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- else
- return {}
- end
- end
- ---Saves the table at the defined path
- ---@param path string a valid filepath
- ---@param table table paramtable to save
- local function saveParams(path, table)
- local file = fs.open(path, "w")
- file.write(textutils.serialize(table))
- file.close()
- end
- local STEPSIZE = 5
- local FIELDSIZE = 7
- local SECONDSWAITINGONDRILL = 260
- local PARAMPATH = "files/quarry"
- local params = loadParams(PARAMPATH)
- local function setRedstoneOutput(side, active)
- if active == nil or active then
- redstone.setOutput(side, true)
- else
- redstone.setOutput(side, false)
- end
- end
- local function stopRotation()
- setRedstoneOutput("right", true)
- setRedstoneOutput("top", true)
- end
- local function slowerSpeed(active)
- setRedstoneOutput("top", active)
- setRedstoneOutput("right", not active)
- end
- local function reverseRotation(active)
- setRedstoneOutput("bottom", active)
- end
- local function activateFirstCarriage(active)
- setRedstoneOutput("left", active)
- end
- local function activateSecondCarriage(active)
- stopRotation()
- setRedstoneOutput("back", active)
- sleep(0.5)
- end
- local function writeText(text)
- term.clear()
- term.setCursorPos(1, 1)
- print(text)
- end
- local function skipCurrent()
- params = loadParams(PARAMPATH)
- if params.skip ~= nil then
- if params.skip == true then
- params.skip = false
- reverseRotation(false)
- saveParams(PARAMPATH, params)
- writeText("skipping current")
- return true
- end
- end
- return false
- end
- local function skipRow()
- params = loadParams(PARAMPATH)
- if params.skiprow ~= nil then
- if params.skiprow == true then
- params.skiprow = false
- saveParams(PARAMPATH, params)
- writeText("skipping row")
- return true
- end
- end
- return false
- end
- local function drill()
- activateFirstCarriage()
- activateSecondCarriage()
- reverseRotation()
- slowerSpeed(false)
- if not skipCurrent() then
- for i = 1, SECONDSWAITINGONDRILL, 1 do
- sleep(1)
- writeText(tostring(i) .. " seconds passed from " .. tostring(SECONDSWAITINGONDRILL))
- if skipCurrent() then
- break
- end
- end
- reverseRotation(false)
- for i = 1, math.ceil(SECONDSWAITINGONDRILL / 15), 1 do
- sleep(1)
- end
- end
- end
- local function moveFirstCarriage()
- activateFirstCarriage(false)
- activateSecondCarriage(false)
- slowerSpeed(true)
- reverseRotation(true)
- for i = 1, STEPSIZE, 1 do
- sleep(0.85)
- end
- end
- local function callbackFirstCarriage()
- activateFirstCarriage(false)
- activateSecondCarriage(false)
- slowerSpeed(false)
- sleep(0.5)
- reverseRotation(false)
- for i = 1, FIELDSIZE, 1 do
- sleep(1)
- end
- end
- local function moveSecondCarriage()
- activateFirstCarriage(true)
- activateSecondCarriage(false)
- slowerSpeed(true)
- sleep(0.5)
- reverseRotation(true)
- for i = 1, STEPSIZE, 1 do
- sleep(0.85)
- end
- end
- local function callbackSecondCarriage()
- activateFirstCarriage(true)
- activateSecondCarriage(false)
- slowerSpeed(false)
- sleep(0.5)
- reverseRotation(false)
- for i = 1, FIELDSIZE, 1 do
- sleep(1)
- end
- end
- local function executeAll()
- callbackFirstCarriage()
- for rows = 1, FIELDSIZE, 1 do
- for columns = 1, FIELDSIZE, 1 do
- while params.stop do
- stopRotation()
- sleep(1)
- writeText("waiting to proceed")
- params = loadParams(PARAMPATH)
- end
- if skipRow() then
- break
- end
- drill()
- moveSecondCarriage()
- end
- callbackSecondCarriage()
- moveFirstCarriage()
- end
- end
- local function test()
- callbackFirstCarriage()
- moveSecondCarriage()
- callbackSecondCarriage()
- moveFirstCarriage()
- end
- executeAll()
- -- test()
Advertisement
Add Comment
Please, Sign In to add comment