FaceInCake

ComputerCraft Turtle Stone Stripper

Feb 12th, 2021 (edited)
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.82 KB | None | 0 0
  1. --                  Name : Stone Stripper
  2. --                Author : Matthew (FaceInCake) Eppel
  3. --                  Date : Feb 18, 2020
  4. --               Version : 0.5.5
  5. -- ComputerCraft Version : 1.80
  6. --                 Build : Works for most situations, needs some look-ahead
  7. --                  Desc : Clears a specified area of all non-ores
  8.  
  9.  
  10. -- How To Use:
  11. -- This help can also be accessed by typing 'StoneStripper help', or whatever you named the file
  12. -- It will ask you for the dimensions using standard input
  13. -- or, you can specify the dimensions using the args: 'w=123', 'h=123', or 'd=123'
  14. -- w : width, h : height, d : depth of area relative to turtle's forward face direction
  15. -- The turtle starts facing forwards, towards the first bottom-left block
  16.  
  17. -- TOOD: Turtle won't mine an area that it doesn't have the fuel for
  18. -- TODO: Turtle will place torches such that no block has a light level <= 7
  19. -- TODO: Turtle will dump it's inventory when full
  20. -- TODO: Will check if can fit flint in inventory when mining gravel
  21. -- TODO: Turtle will remember blocks it failed to reach and try again later
  22.  
  23. local args = {...}
  24. local area = {width=0, height=0, depth=0} -- Dimensions of the area to clear out
  25. local knownOres = {} -- Table for remembering encountered ores: "x,y,z" -> true
  26. local toComeBackTo = {} -- Table for remembering blocks we failed to reach before "x,y,z"->true
  27. local curTarget = {x=0, y=0, z=0} -- To keep track how much of the area we've cleared
  28. -- Macros for directions
  29. local NORTH = 1 -- +Z, forwards, starting direction
  30. local EAST = 2  -- +X, right
  31. local SOUTH = 3 -- -Z, backwards
  32. local WEST = 4  -- -X, left
  33. local UP = 5    -- +Y
  34. local DOWN = 6  -- -Y
  35. local DIRS = { "NORTH", "EAST", "SOUTH", "WEST", "UP", "DOWN" }
  36. -- To keep track of turtle's position, relative to start
  37. local turtlePos = {x=0, y=0, z=-1}
  38. local face = NORTH    -- The current direction the turtle is facing
  39.  
  40. --------------------------------------------------------
  41. --  Code to validate area dimensions from user input  --
  42. --------------------------------------------------------
  43.  
  44. -- Parse each arg
  45. for i, v in ipairs(args) do
  46.     if v == "-h" or v == "--help" or v == "help" then
  47.         textutils.slowPrint([[
  48. How To Use:
  49. It will ask you for the dimensions using standard input
  50. or, you can specify the dimensions using the args: 'w=123', 'h=123', or 'd=123'
  51. w is width, h is height, and d is depth of area relative to turtle's forward face direction
  52. The turtle starts facing forwards, towards the first bottom-left block
  53. ]]      )
  54.        return
  55.    end
  56.    if string.sub(v, 2, 2) == "=" then
  57.        local num = tonumber(string.sub(v, 3, -1))
  58.        if num or num <= 0 then
  59.            if     string.sub(v,1,1) == "w" then
  60.                area.width = num
  61.            elseif string.sub(v,1,1) == "h" then
  62.                area.height = num
  63.            elseif string.sub(v,1,1) == "d" then
  64.                area.depth = num
  65.            else
  66.                printError("Invalid parameter: '"..v.."'")
  67.                printError("Usage: 'w=123', 'h=123', or 'd=123'")
  68.            end
  69.        else
  70.            printError("Invalid value: '"..v.."'")
  71.            printError("Usage: 'w=123', 'h=123', or 'd=123'")
  72.        end
  73.    end
  74. end
  75.  
  76. -- Ask user for dimensions if not already supplied
  77. for key, v in pairs(area) do
  78.    while v <= 0 do
  79.        print("Please input the "..key.." of the area to mine")
  80.        io.write("> ")
  81.        local s = io.read()
  82.        local n = tonumber(s)
  83.        if n and n>0 then
  84.            area[key] = n
  85.            break
  86.        else
  87.            printError("Nan or negative value given")
  88.        end
  89.    end
  90. end
  91.  
  92. ----------------------------------------------------------------
  93. --  Functions for detecting whether a block is an ore or not  --
  94. ----------------------------------------------------------------
  95.  
  96. local BLOCK_WHITELIST = {
  97.    ["minecraft:stone"]=true,
  98.    ["minecraft:cobblestone"]=true,
  99.    ["minecraft:dirt"]=true,
  100.    ["minecraft:gravel"]=true,
  101.    ["chisel:basalt2"]=true,
  102.    ["chisel:marble2"]=true
  103. }
  104.  
  105. local function __isNonOre (inspectF)
  106.    success, data = inspectF()
  107.    if success==false then return "air" end
  108.    if BLOCK_WHITELIST[data.name] then
  109.        if data.state.variant == "stone" then
  110.            return "minecraft:cobblestone"
  111.        end
  112.        return data.name
  113.    end
  114.    return "ore"
  115. end
  116.  
  117. -- Inspects a block in front/above/below to see if it's a non-ore
  118. -- Returns the block name if the block is a non-ore
  119. -- Returns "ore" if the block is NOT a non-ore
  120. -- Returns "air" if there's no block
  121. local function isNonOre () return __isNonOre(turtle.inspect) end
  122. local function isNonOreUp () return __isNonOre(turtle.inspectUp) end
  123. local function isNonOreDown () return __isNonOre(turtle.inspectDown) end
  124.  
  125. ---------------------------------------------------------------------------
  126. --  Function for detecting whether a block will fit in inventory or not  --
  127. ---------------------------------------------------------------------------
  128.  
  129. -- Checks if the given block will fit in inventory if mined
  130. -- `blockName`:string is the game name of the block, (ex. minecraft:stone)
  131. -- Returns true if the block will fit into inventory if mined, false on error
  132. local function willFit (blockName)
  133.     if blockName==nil then return error("No blockName given") end
  134.     if blockName=="air" then return true end
  135.     if blockName=="ore" then return false end
  136.     for i=1, 16 do
  137.         if  turtle.getItemCount(i) == 0
  138.         or  turtle.getItemDetail(i).name == blockName
  139.         and turtle.getItemSpace(i) > 0
  140.         then return true end
  141.     end
  142.     return false
  143. end
  144.  
  145. -------------------------------------------------------------
  146. --  Functions for attempting to a mine block if it should  --
  147. -------------------------------------------------------------
  148.  
  149. local function __strip (isNonOreF, digF, detectF)
  150.     repeat -- Loop in case of sand/gravel
  151.         local blockName = isNonOreF()
  152.         if blockName == "ore" then return "ore" end
  153.         if blockName == "air" then return "air" end
  154.         if not willFit(blockName) then return "full" end
  155.         while not digF() do end
  156.     until not detectF()
  157.     return "dug"
  158. end
  159.  
  160. -- Attempt to mine a block, as long as it will fit in inventory and it's a non-ore
  161. -- Returns `msg`:string, which can be: "ore", "air", "dug", "full"
  162. local function strip () return __strip(isNonOre, turtle.dig, turtle.detect) end
  163. local function stripUp () return __strip(isNonOreUp, turtle.digUp, turtle.detectUp) end
  164. local function stripDown () return __strip(isNonOreDown, turtle.digDown, turtle.detectDown) end
  165.  
  166. ----------------------------------------------------
  167. --  Personalized functions for moving the turtle  --
  168. ----------------------------------------------------
  169.  
  170. -- Helper LUT for `increment()`
  171. local dirLUT = {
  172.     function(p,d) return { x = p.x, y = p.y, z = p.z + d } end, -- NORTH
  173.     function(p,d) return { x = p.x + d, y = p.y, z = p.z } end, -- EAST
  174.     function(p,d) return { x = p.x, y = p.y, z = p.z - d } end, -- SOUTH
  175.     function(p,d) return { x = p.x - d, y = p.y, z = p.z } end, -- WEST
  176.     function(p,d) return { x = p.x, y = p.y + d, z = p.z } end, -- UP
  177.     function(p,d) return { x = p.x, y = p.y - d, z = p.z } end  -- DOWN
  178. }
  179.  
  180. -- Returns a new coord incremented with respect to a given direction
  181. -- `pos` is the starting coordinate
  182. -- `dir` is the direction macro
  183. -- `dist` is the amount to increment by, defaults to 1
  184. -- Returns a the new resultant coord
  185. function increment (pos, dir, dist)
  186.     if dir<=0 or dir>6 then return error("Given dir is out of range: ("..dir..")") end
  187.     if dist==nil then dist=1 end
  188.     return dirLUT[dir](pos,dist)
  189. end
  190.  
  191. -- Turns right and updates the current face
  192. local function turnRight ()
  193.     while not turtle.turnRight() do end
  194.     if face==4 then face = 1
  195.     else face = face + 1 end
  196. end
  197.  
  198. -- Turns left and updates the current face
  199. local function turnLeft ()
  200.     while not turtle.turnLeft() do end
  201.     if face==1 then face = 4
  202.     else face = face - 1 end
  203. end
  204.  
  205. -- Does a 180 and updates the current face
  206. local function turn180 ()
  207.     while not turtle.turnRight() do end
  208.     while not turtle.turnRight() do end
  209.     face = face + 2
  210.     if face > 4 then face = face - 4 end
  211. end
  212.  
  213. -- Moves forward and updates location
  214. -- Returns true if successfully moved
  215. -- Returns false if there's a block in the way
  216. local function moveForward()
  217.     while not turtle.forward() do
  218.         if turtle.detect() then
  219.             return false
  220.         end
  221.     end
  222.     turtlePos = increment(turtlePos, face, 1)
  223.     return true
  224. end
  225.  
  226. -- Moves upwards and updates location
  227. -- Returns true if successfully moved
  228. -- Returns false if there's a block in the way
  229. local function moveUp ()
  230.     while not turtle.up() do
  231.         if turtle.detectUp() then
  232.             return false
  233.         end
  234.     end
  235.     turtlePos.y = turtlePos.y + 1
  236.     return true
  237. end
  238.  
  239. -- Moves downwards and updates location
  240. -- Returns true if successfully moved
  241. -- Returns false if there's a block in the way
  242. local function moveDown ()
  243.     while not turtle.down() do
  244.         if turtle.detectDown() then
  245.             return false
  246.         end
  247.     end
  248.     turtlePos.y = turtlePos.y - 1
  249.     return true
  250. end
  251.  
  252. -- Function that returns
  253. local function voidFunc () return end
  254.  
  255. -- Turns to face `to` from current face
  256. local function turnTo (to)
  257.     if to==nil then return error("No direction given") end
  258.     if to<=0 or to>4 then return error("Given direction is out of range: ("..to..")") end
  259.     local case = face + (to-1)*4
  260.     local TurnLUT = {
  261.         voidFunc, -- facing north, need to face north
  262.         turnLeft, -- facing east,  need to face north
  263.         turn180,  -- facing south, need to face north
  264.         turnRight,-- facing west,  need to face north
  265.         turnRight,-- facing north, need to face east
  266.         voidFunc, -- facing east,  need to face east
  267.         turnLeft, -- facing south, need to face east
  268.         turn180,  -- facing west,  need to face east
  269.         turn180,  -- facing north, need to face south
  270.         turnRight,-- facing east,  need to face south
  271.         voidFunc, -- facing south, need to face south
  272.         turnLeft, -- facing west,  need to face south
  273.         turnLeft, -- facing north, need to face west
  274.         turn180,  -- facing east,  need to face west
  275.         turnRight,-- facing south, need to face west
  276.         voidFunc  -- facing west,  need to face west
  277.     }
  278.     TurnLUT[case]()
  279.     return true
  280. end
  281.  
  282. ------------------------------------
  283. --        A Star algorithm        --
  284. ------------------------------------
  285.  
  286. -- String representation a coordinate
  287. local function str (pos) return (""..pos.x..","..pos.y..","..pos.z) end
  288.  
  289. -- Takes a coord string "x,y,z" and returns the numbers x, y, z
  290. local function str2coord (coordStr)
  291.     local ar = {}
  292.     local i = 1
  293.     for s in string.gmatch(coordStr, "-?%d+") do
  294.         ar[i] = tonumber(s)
  295.         i = i + 1
  296.     end
  297.     return {x=ar[1], y=ar[2], z=ar[3]}
  298. end
  299.  
  300. -- Returns the directional difference, or 0 if there's no difference
  301. local function getDifference (p0, p1)
  302.     if p1.x > p0.x then return EAST  end
  303.     if p1.x < p0.x then return WEST  end
  304.     if p1.y > p0.y then return UP    end
  305.     if p1.y < p0.y then return DOWN  end
  306.     if p1.z > p0.z then return NORTH end
  307.     if p1.z < p0.z then return SOUTH end
  308.     return 0
  309. end
  310.  
  311. -- Returns an array of all neighbor coords to coord string `coordStr`
  312. local function getNeighbors (p)
  313.     if type(p)=="string" then
  314.         p = str2coord(p)
  315.     end
  316.     local ar = {}
  317.     ar[1] = {x=p.x, y=p.y, z=p.z+1} -- NORTH
  318.     ar[2] = {x=p.x+1, y=p.y, z=p.z} -- EAST
  319.     ar[3] = {x=p.x, y=p.y, z=p.z-1} -- SOUTH
  320.     ar[4] = {x=p.x-1, y=p.y, z=p.z} -- WEST
  321.     ar[5] = {x=p.x, y=p.y+1, z=p.z} -- UP
  322.     ar[6] = {x=p.x, y=p.y-1, z=p.z} -- DOWN
  323.     return ar
  324. end
  325.  
  326. -- Checks if coord is in cleared mining area
  327. local function isInRange(p)
  328.     if p.x<0 or p.y<0 or p.z<0 then return false end
  329.     if p.x<area.width and p.y<area.height and p.z<area.depth then
  330.         return true
  331.     end
  332.     return false
  333. end
  334.  
  335. -- Returns an array of actions from a sort of backwards induction table and end goal
  336. -- `cameFrom` is a table where a coord key results in the coord that was previous to that coord, ["x1,y1,z1"] -> "x0,y0,z0"
  337. -- `goalS` is the string repr. of the end coord to start the induction with
  338. -- Returns an array of actions, represented as string, { "east", "forward", "up", north" }
  339. local function reconstructPath (cameFrom, goalS)
  340.     -- Compile the path taken, though it's backwards
  341.     local coords = {} -- backwards array of coords, coords[1]=goal, coords[#]=start
  342.     local i = 1
  343.     coords[i] = goalS
  344.     local node = cameFrom[goalS]
  345.     while node ~= nil do
  346.         i = i + 1
  347.         coords[i] = node
  348.         node = cameFrom[node]
  349.     end
  350. --    for j=i, 1, -1 do
  351. --        print("@"..(i-j+1), coords[j])
  352. --    end
  353.     -- Turn our coord path into actions
  354.     local actions = {}
  355.     local curFace = face
  356.     local k = 1
  357.     -- Helper function for the loop, checks to turn and moves
  358.     local function moveDir (dir)
  359.         if curFace ~= dir then
  360.             actions[k] = DIRS[dir]
  361.             curFace = dir
  362.             k = k + 1
  363.         end
  364.         actions[k] = "FORWARD"
  365.         k = k + 1
  366.     end
  367.     -- Helper function-LUT for the loop, calls the appropriate function
  368.     local ActLUT = {
  369.         moveDir, moveDir,-- N E
  370.         moveDir, moveDir,-- S W
  371.         function()
  372.             actions[k] = "UP"
  373.             k = k + 1
  374.         end,
  375.         function()
  376.             actions[k] = "DOWN"
  377.             k = k + 1
  378.         end
  379.     }  
  380.     -- go throughout the coords and turn'em into actions, from start-to-goal
  381.     for j=i, 2, -1 do
  382.         local case = getDifference(
  383.             str2coord(coords[j]),
  384.             str2coord(coords[j-1])
  385.         )
  386.         ActLUT[case](case)
  387.     end
  388.     return actions
  389. end
  390.  
  391. -- Shortest-path finding algorithm
  392. -- `goals` is an array of coords to be considered the goal
  393. -- `goalF` is the optional direction to end facing
  394. -- Returns `success`:boolean, `result`:string/array
  395. -- On success, `success` is true, believe it or not, and `result` is an array of actions to take in order
  396. -- On failure, `success` is false, surprise, and `result` is a string, telling what went wrong
  397. -- On success, `result`:array can be { "EAST", "FORWARD", "WEST", "UP" }, where a cardinal-direction is a direction to turn to
  398. -- Logic taken mostly from the 'A*_search_algorithm' wiki page pseudo code
  399. local function A_Star (goals)
  400.  
  401.     local startS = str(turtlePos)
  402.     local goalsS = {} -- ["x,y,z"]=true, our goals
  403.     for i,g in ipairs(goals) do
  404.         goalsS[str(g)] = true
  405.     end
  406.    
  407.     -- h is the heuristic function. h estimates the cost to reach the closest goal
  408.     local function __h (p0, p1) return math.abs(p1.x - p0.x) + math.abs(p1.y - p0.y) + math.abs(p1.z - p0.z) end
  409.     local function h (pos)
  410.         local m = math.huge
  411.         for i, v in pairs(goals) do
  412.             local n = __h(pos, v)
  413.             if n < m then m = n end
  414.         end
  415.         return m
  416.     end
  417.    
  418.     -- Coords yet to explore, but discovered
  419.     local openSet = {[startS]=true}
  420.    
  421.     -- Stores the coord immediately preceding another, on the cheapest path
  422.     -- cameFrom["x,y,z"] -> "x,y,z"
  423.     local cameFrom  = {}
  424.    
  425.     -- Resultant facing direction at this coord
  426.     -- So if turtle moved from cameFrom[key] to key, it would be facing resFace[key]
  427.     -- resFace["x,y,z"] -> NORTH/EAST/SOUTH/WEST
  428.     local resFace = {[startS]=face}
  429.    
  430.     -- gScore["x,y,z"] is the cost of the cheapest path from start to "x,y,z" currently known.
  431.     local gScore = {[startS]=0}
  432.  
  433.     -- fScore["x,y,z"] = gScore["x,y,z"] + h("x,y,z"). fScore["x,y,z"] represents our current best guess as to
  434.     -- how short a path from start to finish can be if it goes through "x,y,z"
  435.     local fScore = {[startS] = h(turtlePos)}
  436.    
  437.     local startTime = os.clock()
  438.  
  439.     local next = next -- Local binding
  440.     local currentS = startS -- Current coord working on as a string key (ie. "x,y,z")
  441.     while currentS ~= nil do
  442.         -- current = coord with the lowest fScore in openSet
  443.         for k, _ in pairs(openSet) do
  444.             if fScore[k] < fScore[currentS] then
  445.                 currentS = k
  446.             end
  447.         end
  448.         -- Are we there yet!?
  449.         if goalsS[currentS] then
  450.             return true, reconstructPath(cameFrom, currentS)
  451.         end
  452.         -- We have now explored this coord
  453.         openSet[currentS] = nil
  454.         -- Check each neighbor
  455.         for dir, neighbor in ipairs(getNeighbors(currentS)) do
  456.             local neighborS = str(neighbor)
  457.             if knownOres[neighborS] == nil      -- Make sure it's air there
  458.             and neighborS ~= cameFrom[currentS] -- Make sure were not going backwards
  459.             and isInRange(neighbor) then        -- Make sure we dont leave the area
  460.                 local newDir = (dir<5) and dir or resFace[currentS]
  461.                 -- n_gScore is the distance from start to the neighbor through current
  462.                 local n_gScore = gScore[currentS] + 1 + ((resFace[currentS]==newDir) and 0 or 1)
  463.                 if gScore[neighborS]==nil or n_gScore < gScore[neighborS] then
  464.                     -- This path to neighbor is better than any previous one. Record it!
  465.                     resFace[neighborS] = newDir
  466.                     cameFrom[neighborS] = currentS
  467.                     gScore[neighborS] = n_gScore
  468.                     fScore[neighborS] = gScore[neighborS] + h(neighbor)
  469.                     if openSet[neighborS] == nil then
  470.                         openSet[neighborS] = true
  471.                     end
  472.                 end
  473.             end
  474.         end
  475.         if os.clock() > startTime + 5.0 then
  476.             return false, "Timed out, unable to find the goal"
  477.         end
  478.         -- Check if openSet is empty
  479.         currentS = next(openSet)
  480.     end
  481.     -- Open set is empty but goal was never reached
  482.     return false, "Exhausted all options trying to find the goal"
  483. end
  484.  
  485. ---------------------------------------------------
  486. --  Functions for navigating to a certain coord  --
  487. ---------------------------------------------------
  488.  
  489. -- Paths to a given coordinate and ends, facing a given direction
  490. -- `p` is the coordinate to go to, origin is the first bottom-left block in our area to mine
  491. -- `f` is an optional direction to face when finished
  492. -- Returns true on success, false on failure
  493. local function navigate(tar)
  494.     -- LUT actions
  495.     local NavLUT = {
  496.         ["FORWARD"] = moveForward,
  497.         ["UP"] = moveUp,
  498.         ["DOWN"] = moveDown,
  499.         ["NORTH"] = function () return turnTo(NORTH) end,
  500.         ["EAST"]  = function () return turnTo(EAST)  end,
  501.         ["SOUTH"] = function () return turnTo(SOUTH) end,
  502.         ["WEST"]  = function () return turnTo(WEST)  end
  503.     }
  504.     -- LUT for direction of movement, has to be a function because `face` can change
  505.     local DirLUT = {
  506.         ["FORWARD"] = function() return face end,
  507.         ["UP"] = function() return UP end,
  508.         ["DOWN"] = function() return DOWN end
  509.     }
  510.     local coords = getNeighbors(tar) -- Goals
  511.     -- helper function, returns true if should loop, false on success, string on failure
  512.     local function attemptNav()
  513.         -- Call upon the mighty
  514.         local success, result = A_Star(coords, f)
  515.         if success then
  516.             -- Carry out the instructions
  517.             for _, act in ipairs(result) do
  518.                 local success = NavLUT[act]()
  519.                 --print("+",act,"=",success)
  520.                 if success == false then
  521.                     local dir = DirLUT[act]()
  522.                     knownOres[str(increment(turtlePos,dir,1))] = true
  523.                     return true
  524.                 end
  525.             end
  526.             return false
  527.         else
  528.             return result
  529.         end
  530.     end
  531.     -- loop the nav function until success
  532.     local result = attemptNav()
  533.     while result ~= false do
  534.         if result ~= true then
  535.             printError(result)
  536.             return false
  537.         end
  538.         result = attemptNav()
  539.     end
  540.     -- Final turn to face the block
  541.     local dir = getDifference(turtlePos, tar)
  542.     if dir < 5 then
  543.         NavLUT[DIRS[dir]]()
  544.         return "FORWARD"
  545.     elseif dir==5 then
  546.         return "UP"
  547.     elseif dir==6 then
  548.         return "DOWN"
  549.     end
  550.     return error("Unable to get direction to target")
  551. end
  552.  
  553. ------------------------------------------------------
  554. --  Function for going to and mining a given block  --
  555. ------------------------------------------------------
  556.  
  557. -- Navigates towards given coordinate and mines the block there
  558. -- (x, y, z) is the width/height/depth coord where the origin is the first bottom-left block
  559. -- Returns false if error occurred, true if execution ended normally
  560. local function seekAndDestroy (tar)
  561.     local tarS = str(tar)
  562.     -- Navigate to any block beside the target block
  563.     local result = navigate(tar)
  564.     if result==false then
  565.         printError("Failed to navigate to block.")
  566.         return false
  567.     end
  568.     -- Dig the block using the appropriate function
  569.     local DigLUT = {
  570.         ["FORWARD"] = strip,
  571.         ["UP"] = stripUp,
  572.         ["DOWN"] = stripDown
  573.     }
  574.     local msg = DigLUT[result]() -- "ore", "air", "dug", "full", or "failed"
  575.     if msg == "full" then
  576.         return error("Turtle would dump inv at this point")
  577.     elseif msg == "ore" then
  578.         knownOres[tarS] = true
  579.     elseif msg == "failed" then
  580.         return error("Failed to strip block")
  581.     end
  582.     -- else msg == dug/air
  583.     knownOres[tarS] = nil
  584.     return true
  585. end
  586.  
  587. -----------------------------
  588. --    Main digging loop    --
  589. -----------------------------
  590.  
  591. function declareWall (z)
  592.     local pos = {x=0, y=0, ["z"]=z}
  593.     while pos.x < area.width do
  594.         while pos.y < area.height do
  595.             knownOres[str(pos)] = true
  596.             pos.y = pos.y + 1
  597.         end
  598.         pos.x = pos.x + 1
  599.     end
  600. end
  601.  
  602. local function main ()
  603.     local xStep = 1
  604.     local yStep = 1
  605.     declareWall(0)
  606.     while curTarget.z < area.depth do
  607.         declareWall(curTarget.z+1)
  608.         while curTarget.x >= 0 and curTarget.x < area.width do
  609.             while curTarget.y >= 0 and curTarget.y < area.height do
  610.                 print("Targeting:", str(curTarget))
  611.                 if seekAndDestroy(curTarget)==false then
  612.                     printError("Failed to seekAndDestroy block")
  613.                 end
  614.                 curTarget.y = curTarget.y + yStep
  615.             end
  616.             yStep = - yStep
  617.             curTarget.y = curTarget.y + yStep
  618.             curTarget.x = curTarget.x + xStep
  619.         end
  620.         xStep = - xStep
  621.         curTarget.x = curTarget.x + xStep
  622.         curTarget.z = curTarget.z + 1
  623.     end
  624. end
  625.  
  626. print("Mining an area of:",area.width,",",area.height,",",area.depth)
  627. main()
  628. print("Finished execution :D")
  629.  
  630.  
  631.  
Advertisement
Add Comment
Please, Sign In to add comment