Savage_Me55iah

CC OREQUARRY V0.1

Dec 5th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.44 KB | None | 0 0
  1. -- Script by Savage_Me55iah of CraftAU.com.au and Nuqube.co --
  2. local version, pastebinCode = "v0.2", "Htf7LraY"
  3.  
  4. --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
  5.  
  6. -- INSTRUCTIONS ON USE --
  7. -- Instruction video on http://youtube.com/savagemessiah5
  8. -- Confirmed working turtle chunk loader mod: chunkyperipherals
  9.  
  10. -- Contact Savage_Me55iah @ CraftAU.com.au or Nuqube.co or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
  11.  
  12. -- CHANGELOG --
  13. -- V 0.1 - Working
  14. -- V 0.2 - Mining between non flat bedrock
  15. -- V 0.2 - Auto creating and removing startup script
  16.  
  17. -- YET TO BE IMPLEMENTED --
  18. -- Dumping of non whitelist materials
  19. -- Running into indestructible blocks horizontally
  20. -- Pausing & restarting on storage chest full
  21. -- Improving emergency return to surface situations
  22. -- Rednet broadcast positioning data if available
  23. -- Faster refueling and storage coding
  24. -- GUI on script start
  25. -- Rednet remote return/pause/resume
  26.  
  27. -- UPDATER --
  28.  
  29. local tArgs = {...}
  30. local update = tostring(tArgs[1]) or nil
  31. if update == "update" then
  32.     print("UPDATING")
  33.     shell.run("pastebin get "..pastebinCode.." update")
  34.     if fs.exists("update") then
  35.         fs.delete(shell.getRunningProgram())
  36.         fs.copy("update", shell.getRunningProgram())
  37.         fs.delete("update")
  38.         print("UPDATE SUCCESS")
  39.     else
  40.         print("UPDATE FAILED")
  41.     end
  42.     sleep(2)
  43.     os.reboot()
  44. end
  45.  
  46. -- SETUP --
  47.  
  48. label = os.getComputerLabel() or false
  49. if label == false then
  50.     print("Please Type label here: ")
  51.     os.setComputerLabel(tostring(read()))
  52. end
  53.  
  54. function boolean_check(params)
  55.     local answer = nil
  56.     if tostring(params) == "true" then
  57.         answer = true
  58.     else
  59.         answer = false
  60.     end
  61.     return answer
  62. end
  63.  
  64. local settings_file = "config"
  65.  
  66. local settings_template = [[-- adjust these configuration options as necessary.
  67. -- IMPORTANT!, API won't load if there are spaces in the values
  68. COMPUTER_LABEL = "${label}"
  69. COMPUTER_ID = ${id}
  70.  
  71. USE_WHITELIST = "${use_whitelist}"
  72. DUMP_NON_WHITELIST = "${dump_non_whitelist}"
  73. ENDERCHEST_STORAGE = "${enderchest_storage}"
  74. ENDERCHEST_FUEL = "${enderchest_fuel}"
  75. FLAT_BEDROCK = "${flat_bedrock}"
  76. SIZE_X = ${size_x}
  77. SIZE_Z = ${size_z}
  78. RESTART_TIME = ${restart_time}
  79. RESTART_TIME_INT = ${restart_time_int}
  80. ]]
  81.  
  82. local function interpolate(s, params)
  83.     return s:gsub('($%b{})', function(w) return params[w:sub(3, -2)] or w end)
  84. end
  85.  
  86. do
  87.     save_settings = function()
  88.         local filehandler = fs.open(tostring(settings_file), "w")
  89.  
  90.         if tostring(CONFIG) == "nil" then
  91.             settings = {
  92.             label = os.getComputerLabel(),
  93.             id = os.getComputerID(),
  94.             use_whitelist = "true",
  95.             dump_non_whitelist = "false",
  96.             enderchest_storage = "true",
  97.             enderchest_fuel = "true",
  98.             flat_bedrock = "true",
  99.             size_x = 16,
  100.             size_z = 15,
  101.             restart_time = 60,
  102.             restart_time_int = 5
  103.             }
  104.         else
  105.             settings = {
  106.             label = CONFIG.COMPUTER_LABEL or os.getComputerLabel(),
  107.             id = os.getComputerID(),
  108.             use_whitelist = CONFIG.USE_WHITELIST or "true",
  109.             dump_non_whitelist = CONFIG.DUMP_NON_WHITELIST or "false",
  110.             enderchest_storage = CONFIG.ENDERCHEST_STORAGE or "true",
  111.             enderchest_fuel = CONFIG.ENDERCHEST_FUEL or "true",
  112.             flat_bedrock = CONFIG.FLAT_BEDROCK or "false",
  113.             size_x = CONFIG.SIZE_X or 16,
  114.             size_z = CONFIG.SIZE_Z or 15,
  115.             restart_time = CONFIG.RESTART_TIME or 60,
  116.             restart_time_int = CONFIG.RESTART_TIME_INT or 5
  117.             }
  118.         end
  119.  
  120.         filehandler.write(interpolate(settings_template, settings))
  121.         filehandler.close()
  122.     end
  123. end
  124.  
  125. if fs.exists(settings_file) == false then
  126.     save_settings()
  127.     return
  128. else
  129.     os.unloadAPI(settings_file)
  130.     if os.loadAPI(settings_file) == false then print("ERROR: Could not load the settings file!") end
  131.     CONFIG = nil
  132.     for k, v in pairs(_G) do if k == settings_file then CONFIG = v break end end
  133.     if CONFIG == nil then print("CONFIG came up nil") end
  134. end
  135.  
  136. -- SLOTS --
  137.  
  138. local slots = {["fuel"] = 1, ["enderchest_fuel"] = nil, ["enderchest_storage"] = nil, ["cobble"] = 2}
  139. if boolean_check(tostring(CONFIG.ENDERCHEST_FUEL)) then slots["enderchest_fuel"] = 2 slots["cobble"] = 3 end
  140. if boolean_check(tostring(CONFIG.ENDERCHEST_STORAGE)) then
  141.     if tostring(slots["enderchest_fuel"]) ~= "nil" then slots["enderchest_storage"] = 3 slots["cobble"] = 4
  142.     else slots["enderchest_storage"] = 2 slots["cobble"] = 3 end
  143. end
  144. local open_slot = slots["cobble"] + 1
  145.  
  146. -- TABLES SETUP --
  147.  
  148. whitelist, direction, curr_coords, home_coords = {}, {[1] = "north", [2] = "east", [3] = "south", [4] = "west"}, {["x"] = 0, ["z"] = 0, ["y"] = 0, ["dir"] = 1, ["operation"] = nil, ["operating"] = false, ["layer"] = 1}, {["x"] = 0, ["z"] = 0, ["y"] = 0, ["dir"] = 1}
  149.  
  150. do whitelist_add = function(...) local params = {...} for k,v in pairs(params) do table.insert(whitelist, v) end end end
  151.  
  152. whitelist_add("gold", "iron", "coal", "lapis", "diamond", "redstone", "emerald", "soul_sand", "glowstone", "quartz", "end", "mossy", "obsidian", "clay", "essence", "crystal", "amethyst", "ruby", "peridot", "topaz", "tanzanite", "malachite", "sapphire", "amber", "copper", "tin", "apatite", "ore", "iridium", "searedbrick", "biomeblock", "moonblock", "asteriodsblock", "mars", "uran", "lead", "mariculture:rocks", "forestry:resources")
  153.  
  154. -- MOVEMENT FUNCTIONS --
  155.  
  156. local store = nil
  157.  
  158. do
  159.  
  160.     inspect = function(params_dir, params_check)
  161.         local answer, detail = false, {}
  162.         if params_dir == "down" then detail = {turtle.inspectDown()}
  163.         elseif params_dir == "up" then detail = {turtle.inspectUp()}
  164.         elseif params_dir == "forward" then detail = {turtle.inspect()}
  165.         end
  166.         if tostring(detail[2]["name"]) ~= "nil" then
  167.             if tostring(string.find(detail[2]["name"]:lower(), tostring(params_check))) ~= "nil" then answer = true end
  168.         end
  169.         return answer
  170.     end
  171.  
  172.     coord = function(params)
  173.         if params == "save" then local fh = fs.open("coords", 'w') fh.write(textutils.serialize(curr_coords)) fh.close()
  174.         elseif params == "load" and boolean_check(fs.exists("coords")) then local fh = fs.open("coords", 'r') curr_coords = textutils.unserialize(fh.readAll()) fh.close() end
  175.     end
  176.  
  177.     coord_update = function(params_dir)
  178.         if params_dir == "forward" then
  179.             if curr_coords["dir"] == 1 then curr_coords["z"] = curr_coords["z"] + 1
  180.             elseif curr_coords["dir"] == 3 then curr_coords["z"] = curr_coords["z"] - 1
  181.             elseif curr_coords["dir"] == 2 then curr_coords["x"] = curr_coords["x"] + 1
  182.             elseif curr_coords["dir"] == 4 then curr_coords["x"] = curr_coords["x"] - 1
  183.             end
  184.         elseif params_dir == "back" then
  185.             if curr_coords["dir"] == 1 then curr_coords["z"] = curr_coords["z"] - 1
  186.             elseif curr_coords["dir"] == 3 then curr_coords["z"] = curr_coords["z"] + 1
  187.             elseif curr_coords["dir"] == 2 then curr_coords["x"] = curr_coords["x"] - 1
  188.             elseif curr_coords["dir"] == 4 then curr_coords["x"] = curr_coords["x"] + 1
  189.             end
  190.         elseif params_dir == "up" then
  191.             curr_coords["y"] = curr_coords["y"] + 1
  192.         elseif params_dir == "down" then
  193.             curr_coords["y"] = curr_coords["y"] - 1
  194.         end
  195.         if params_dir ~= "forward" and params_dir ~= "back" and params_dir ~= "up" and params_dir ~= "down" and tostring(params_dir) ~= "nil" then
  196.             curr_coords["operation"] = params_dir
  197.         end
  198.         term.clear() term.setCursorPos(1,1)
  199.         print("OPERATION: "..tostring(curr_coords["operation"])) print("SUBOPERATION: "..(curr_coords["sub_op"] or "nil")) print("FUEL: "..(turtle.getFuelLevel() or nil).."/"..((tonumber(CONFIG.SIZE_X) + tonumber(CONFIG.SIZE_Z) + 256) * 2)) print("LAYERS: "..tostring(curr_coords["layer"] or nil).."/"..tostring(curr_coords["top_layer"] or nil)) print("X: "..curr_coords["x"]) print("Z: "..curr_coords["z"]) print("Y: "..curr_coords["y"]) print("DIRECTION: "..curr_coords["dir"])
  200.         coord("save")
  201.     end
  202.  
  203.     dig = function(params_dir, params_scan)
  204. --      curr_coords["sub_op"] = "dig" coord_update()
  205.         local params_inspect, params_dig, params_slot = nil, nil, tonumber(turtle.getSelectedSlot())
  206.         turtle.select(1)
  207.  
  208.         if tostring(params_dir) == "forward" then
  209.             if boolean_check(params_scan) and turtle.detect() then
  210.                 params_inspect = {turtle.inspect()}
  211.                 for k,v in pairs(whitelist) do if  tostring(string.find(params_inspect[2]["name"]:lower(), v)) ~= "nil" then params_dig = true end end
  212.             else
  213.                 params_dig = true
  214.             end
  215.             if boolean_check(params_dig) then params_dig = turtle.dig() end
  216.  
  217.         elseif tostring(params_dir) == "up" then
  218.             if boolean_check(params_scan) and turtle.detectUp() then
  219.                 params_inspect = {turtle.inspectUp()}
  220.                 for k,v in pairs(whitelist) do if tostring(string.find(params_inspect[2]["name"]:lower(), v)) ~= "nil" then params_dig = true end end
  221.             else
  222.                 params_dig = true
  223.             end
  224.             if boolean_check(params_dig) then params_dig = turtle.digUp() end
  225.  
  226.         elseif tostring(params_dir) == "down" then
  227.             if boolean_check(params_scan) and turtle.detectDown() then
  228.                 params_inspect = {turtle.inspectDown()}
  229.                 for k,v in pairs(whitelist) do if tostring(string.find(params_inspect[2]["name"]:lower(), v)) ~= "nil" then params_dig = true end end
  230.             else
  231.                 params_dig = true
  232.             end
  233.             if boolean_check(params_dig) then params_dig = turtle.digDown() end
  234.         end
  235.  
  236.         if turtle.getItemCount(15) >= 1 then store = true else store = false end
  237.         turtle.select(params_slot)
  238.         return params_dig
  239.     end
  240.  
  241.     drop = function(params_dir)
  242.         if tostring(params_dir) == "up" then turtle.dropUp()
  243.         elseif tostring(params_dir) == "down" then turtle.dropDown()
  244.         elseif tostring(params_dir) == "forward" then turtle.drop()
  245.         end
  246.     end
  247.    
  248.     place = function(params_dir, params_slot)
  249.         local slot = tonumber(turtle.getSelectedSlot())
  250.         turtle.select(params_slot)
  251.         dig(params_dir, false)
  252.         if params_dir == "forward" then turtle.place() elseif params_dir == "up" then turtle.placeUp() elseif params_dir == "down" then turtle.placeDown() end
  253.         turtle.select(slot)
  254.     end
  255.  
  256.     fuel = function()
  257. --      curr_coords["sub_op"] = "refueling" coord_update()
  258.         local fuel_level, fuel_min, fuel_max, fueling, slot, detail = turtle.getFuelLevel() or 1, ((tonumber(CONFIG.SIZE_X) + tonumber(CONFIG.SIZE_Z) + 256) * 2), turtle.getFuelLimit(), true, tonumber(turtle.getSelectedSlot()), {turtle.inspectDown()}
  259.         if fuel_min >= (fuel_max - 1000) then fuel_min = (fuel_max - 1000) end
  260.         while fuel_level < fuel_min and boolean_check(fueling) and tostring(fuel_level):lower() ~= "unilimited" do
  261.             if turtle.getItemCount(tonumber(slots["fuel"])) > 1 then
  262.                 turtle.select(slots["fuel"]) fueling = turtle.refuel(1)
  263.             elseif turtle.getItemCount(tonumber(slots["fuel"])) == 1 and boolean_check(CONFIG.ENDERCHEST_FUEL) then
  264.                 if tostring(detail[2]["name"]) ~= "bedrock" then
  265.                     place("down", slots["enderchest_fuel"]) turtle.select(slots["fuel"]) fueling = turtle.suckDown(turtle.getItemSpace()) turtle.select(slots["enderchest_fuel"]) turtle.digDown()
  266.                     if tostring(detail[2]["name"]) ~= "minecraft:cobblestone" then place("down", slots["cobble"]) end
  267.                     turtle.select(slot)
  268.                 else
  269.                     fueling = true
  270.                 end
  271.             elseif turtle.getItemCount(tonumber(slots["fuel"])) == 1 and not boolean_check(CONFIG.ENDERCHEST_FUEL) then
  272.                 fueling = false store = true
  273.             end
  274.             fuel_level = turtle.getFuelLevel() or 1
  275.         end
  276.         return fueling
  277.     end
  278.  
  279.     even = function(params)
  280.         local params_numA, params_numB, answer = params / 2, math.floor(params / 2), nil
  281.         if tonumber(params_numA - params_numB) == 0 then answer = true else answer = false end
  282.         return answer
  283.     end
  284.    
  285.     turn = function(params_dir)
  286.         if curr_coords["dir"] >= 5 then curr_coords["dir"] = 1 elseif curr_coords["dir"] <= 0 then curr_coords["dir"] = 4 end
  287.         if tostring(params_dir) == "right" then curr_coords["dir"] = tonumber(curr_coords["dir"]) + 1 turtle.turnRight()
  288.         elseif tostring(params_dir) == "left" then curr_coords["dir"] = tonumber(curr_coords["dir"]) - 1 turtle.turnLeft()
  289.         end
  290.         if curr_coords["dir"] >= 5 then curr_coords["dir"] = 1 elseif curr_coords["dir"] <= 0 then curr_coords["dir"] = 4 end
  291.         coord_update()
  292.     end
  293.    
  294.     move = function(params_dir, params_scan)
  295.         local params_moved, params_dug = nil, nil
  296.         fuel()
  297.         if tostring(params_dir) == "left" then turn("left") elseif tostring(params_dir) == "right" then turn("right") elseif tostring(params_dir) == "reverse" then turn("right") turn("right") end
  298.         if tostring(params_dir) == "forward" then
  299.             if boolean_check(params_scan) then params_dug = dig("up", true) while boolean_check(params_dug) do sleep(0.2) params_dug = dig("up", false) end if inspect("up", "water") or inspect("up", "lava") then place("up", slots["cobble"]) end
  300.             dig("down", true) if inspect("down", "water") or inspect("down", "lava") then place("down", slots["cobble"]) end end
  301.             while boolean_check(params_moved) ~= true do params_moved = turtle.forward() if boolean_check(params_moved) ~= true then dig("forward", false) turtle.attack() end end
  302.             if boolean_check(params_moved) then coord_update("forward") end
  303.         elseif tostring(params_dir) == "down" then while boolean_check(params_moved) ~= true do params_moved = turtle.down() if boolean_check(params_moved) ~= true then dig("down", false) turtle.attackDown() end end if boolean_check(params_moved) then coord_update("down") end
  304.         elseif tostring(params_dir) == "up" then while boolean_check(params_moved) ~= true do params_moved = turtle.up() if boolean_check(params_moved) ~= true then dig("up", false) turtle.attackUp() end end if boolean_check(params_moved) then coord_update("up") end
  305.         end
  306.     end
  307.    
  308.     coord_move = function(params_x, params_z, params_y, params_dir, params_scan)
  309.         if tostring(params_scan) ~= "memory" then curr_coords["memory"] = {["x"] = curr_coords["x"], ["z"] = curr_coords["z"], ["y"] = curr_coords["y"], ["dir"] = curr_coords["dir"]} coord() end
  310.         -- X, Z  DIRECTIONS
  311.         while tonumber(params_x) ~= tonumber(curr_coords["x"]) or tonumber(params_z) ~= tonumber(curr_coords["z"]) do
  312.             local dir = nil
  313.             if params_x < curr_coords["x"] then dir = 4
  314.                 elseif params_x > curr_coords["x"] then dir = 2
  315.                 elseif params_z > curr_coords["z"] then dir = 1
  316.                 elseif params_z < curr_coords["z"] then dir = 3
  317.             end
  318.             curr_coords["sub_op"] = "coord move "..params_x..":"..curr_coords["x"].." "..params_z..":"..curr_coords["z"].." "..dir coord_update()
  319.             while dir ~= tonumber(curr_coords["dir"]) do turn("left") end
  320.             move("forward", params_scan)
  321.         end
  322.         -- DIR
  323.         while params_dir ~= curr_coords["dir"] do curr_coords["sub_op"] = "coord move turn" coord_update() turn("right") end
  324.         -- Y DIRECTION
  325.         while params_y ~= curr_coords["y"] do
  326.             curr_coords["sub_op"] = "coord move Y" coord_update()
  327.             if params_y > curr_coords["y"] then move("up", params_scan) elseif params_y < curr_coords["y"] then move("down", params_scan) end
  328.         end
  329.     end
  330.    
  331.     finish = function(params)
  332.         curr_coords["sub_op"] = "finish" coord_update()
  333.         if not params then coord_move(home_coords["x"], home_coords["z"], home_coords["y"], home_coords["dir"]) fs.delete("coords") write_startup(true) end
  334.         curr_coords["operating"] = false fs.delete("coords") os.reboot()
  335.     end
  336.    
  337.     emergency = function()
  338.         curr_coords["emergency"] = true  curr_coords["sub_op"] = "EMERGENCY" coord_update()
  339.         if home_coords["y"] < curr_coords["y"] then coord_move(curr_coords["x"], curr_coords["z"], tonumber(home_coords["y"] + 5), home_coords["dir"]) local emerged = turtle.detectUp() while emerged do move("up") end end
  340.         curr_coords["x"], curr_coords["z"], curr_coords["y"], curr_coords["dir"] = home_coords["x"], home_coords["z"], home_coords["y"], home_coords["dir"]
  341.         coord("save") term.clear() term.setCursorPos(1,1)
  342.         print("ERROR @ "..(curr_coords["memory"]["x"] or "nil").."-"..(curr_coords["memory"]["z"] or "nil").."-"..(curr_coords["memory"]["y"] or "nil").."-"..(curr_coords["memory"]["dir"] or "nil").."-"..(curr_coords["operation"] or "nil"))
  343.         print(" ")
  344.         print("CO-ORDINATES HAVE BEEN RESET TO HOME POSITION,")
  345.         print("BREAK AND MOVE BACK TO HOME POSITION TO RESET")
  346.         print("TYPE >CONTINUE< TO RESTART OR")
  347.         print("TYPE >CLEAR< TO FINISH")
  348.         print(" ")
  349.         local result = nil
  350.         while result ~= "continue" and result ~= "clear" do result = read():lower() end
  351.         if result == "continue" then
  352.             coord_move(curr_coords["x"], curr_coords["z"], curr_coords["memory"]["y"], curr_coords["dir"], "memory")
  353.             coord_move(curr_coords["memory"]["x"], curr_coords["memory"]["z"], curr_coords["memory"]["y"], curr_coords["memory"]["dir"], "memory")
  354.             curr_coords["emergency"] = false
  355.         else
  356.             finish(true)
  357.         end
  358.     end
  359.    
  360.     storage = function(params)
  361.         curr_coords["sub_op"] = "STORAGE" coord_update()
  362.         local slot = turtle.getSelectedSlot()
  363.         if boolean_check(params) then coord_move(home_coords["x"], home_coords["z"], home_coords["y"], 3) end
  364.         if boolean_check(store) or boolean_check(params) then
  365.             local params_check, home, storage_dir, fuel_dir, dump_dir = inspect("forward", "chest"), false, "down", "down", "down"
  366.             if boolean_check(CONFIG.ENDERCHEST_STORAGE) then place("down", slots["enderchest_storage"]) storage_dir, fuel_dir, dump_dir = "down", "down", "down"
  367.             elseif params_check then home, storage_dir, fuel_dir, dump_dir = true, "forward", "up", "forward"
  368.             elseif not boolean_check(CONFIG.ENDERCHEST_STORAGE) and not params_check then emergency() end
  369.             if boolean_check(CONFIG.DUMP_NON_WHITELIST) then
  370.                 if dump_dir == "down" then dump_dir = "forward" elseif dump_dir == "forward" then dump_dir = "down" end
  371.             end
  372.             local num, detail = nil, nil
  373.             for num=open_slot,16 do
  374.                 turtle.select(num) detail = turtle.getItemDetail() local action = nil
  375.                 if tostring(detail) ~= "nil" then
  376.                     for k,v in pairs(whitelist) do
  377.                         action = nil
  378.                         if tostring(string.find(detail["name"]:lower(), tostring(v))) ~= "nil" then action = "store"
  379.                         elseif tostring(string.find(detail["name"]:lower(), "coal")) ~= "nil" then action = "fuel_store"
  380.                         end
  381.                         if tostring(action) == "store" then drop(storage_dir)
  382.                         elseif tostring(action) == "fuel_store" then drop(fuel_dir)
  383.                         elseif tostring(action) == "nil" then drop(dump_dir)
  384.                         end
  385.                     end
  386.                 end
  387.             end
  388.             if fuel_dir == "up" then turtle.select(slots["fuel"]) turtle.suckUp(turtle.getItemSpace()) end
  389.             if boolean_check(CONFIG.ENDERCHEST_STORAGE) then turtle.select(slots["enderchest_storage"]) turtle.digDown() end
  390.             turtle.select(slot)
  391.         end
  392.     end
  393.  
  394.     bedrock = function(params)
  395.         if params == "locate" or params == "down" then
  396.             curr_coords["sub_op"] = "BEDROCK" coord_update()
  397.             local level = nil
  398.             while tostring(level) == "nil" do
  399.                 move("down")
  400.                 if boolean_check(inspect("down", "bedrock")) then level = true end
  401.             end
  402.             if params == "locate" then curr_coords["bedrock"] = curr_coords["y"] end
  403.         elseif params == "up" then
  404.             curr_coords["sub_op"] = "BEDROCK UP" coord_update()
  405.             local level = false
  406.             while not boolean_check(level) do
  407.                 move("up")
  408.                 if boolean_check(inspect("up", "cobblestone")) then level = true end
  409.             end
  410.             coord_update("move")
  411.             dig("up")
  412.         end
  413.     end
  414.    
  415.     mining = function()
  416.         curr_coords["sub_op"] = "MINING" coord_update()
  417.         if tostring(curr_coords["operation"]) == "bedrock dig" and tonumber(curr_coords["layer"]) == 1 and not boolean_check(CONFIG.FLAT_BEDROCK) then coord_update("bedrock cobble") else coord_update("move") end
  418.         if tostring(curr_coords["operation"]) == "bedrock cobble" then place("up", slots["cobble"]) coord_update("bedrock dig down") end
  419.         if tostring(curr_coords["operation"]) == "bedrock dig down" then bedrock("down") coord_update("bedrock up") end
  420.         if tostring(curr_coords["operation"]) == "bedrock up" then bedrock("up") end
  421.         if tostring(curr_coords["operation"]) == "move" then move("forward", true) coord_update("memory") end
  422.         if tostring(curr_coords["operation"]) == "memory" then curr_coords["memory"] = {["x"] = curr_coords["x"], ["z"] = curr_coords["z"], ["y"] = curr_coords["y"], ["dir"] = curr_coords["dir"]} coord_update("storage") end
  423.         if tostring(curr_coords["operation"]) == "storage" and boolean_check(store) then storage((not boolean_check(CONFIG.ENDERCHEST_STORAGE))) if boolean_check(CONFIG.ENDERCHEST_STORAGE) then coord_update("bedrock dig") else coord_update("return") end else coord_update("bedrock dig") end     
  424.         if tostring(curr_coords["operation"]) == "return" then coord_move(home_coords["x"], home_coords["z"], curr_coords["memory"]["y"], home_coords["dir"], "memory") coord_move(curr_coords["memory"]["x"], curr_coords["memory"]["z"], curr_coords["y"], curr_coords["memory"]["dir"], "memory") coord_update("bedrock dig") end
  425.     end
  426.    
  427.     startup = function(params)
  428.         curr_coords["sub_op"] = "STARTUP" coord_update()
  429.         if boolean_check(inspect("down", "chest")) then for num=2,3 do turtle.select(num) turtle.digDown() end end
  430.         if boolean_check(curr_coords["emergency"]) then emergency() end
  431.         if boolean_check(params) then
  432.             coord_move(home_coords["x"], home_coords["z"], curr_coords["y"], 3)
  433.             local confirm = false
  434.             if inspect("forward", "cobble") then
  435.                 turn("right")
  436.                 if inspect("forward", "cobble") then confirm = true end
  437.             elseif inspect("forward", "chest") then
  438.                 confirm = true
  439.             end
  440.             if not confirm then emergency() else coord_move(curr_coords["memory"]["x"], curr_coords["memory"]["z"], curr_coords["memory"]["y"], curr_coords["memory"]["dir"]) end
  441.         else
  442.             coord_move(tonumber(home_coords["x"]), tonumber(home_coords["z"]), tonumber(home_coords["y"]), tonumber(home_coords["dir"]))
  443.             curr_coords["operating"] = true curr_coords["operation"] = nil
  444.         end
  445.     end
  446.    
  447.     write_startup = function(params)
  448.         local file = "startup"
  449.         if not boolean_check(params) then
  450.             if not boolean_check(fs.exists(file)) then
  451.                 outputFile = io.open(file, "w")
  452.                 outputFile:write("shell.run(\"")
  453.                 outputFile:write(shell.getRunningProgram())
  454.                 outputFile:write("\")\n")
  455.                 outputFile:close()
  456.             else
  457.                 local count, int = tonumber(CONFIG.RESTART_TIME), tonumber(CONFIG.RESTART_TIME_INT)
  458.                 while count >= 1 do
  459.                     term.clear() term.setCursorPos(1,2)
  460.                     print("QUARRY PROGRAM RESTARTING IN: "..count)
  461.                     print("BACKSPACE TO CANCEL, ANY KEY TO START")
  462.                     os.startTimer(int)
  463.                     local timer = {os.pullEvent()}
  464.                     if timer[1] == "timer" then count = count - int
  465.                     elseif timer[1] == "key" then
  466.                         if tonumber(timer[2]) == 14 then error() --backspace
  467.                         else count = -1 end
  468.                     end
  469.                 end
  470.             end
  471.         else
  472.             fs.delete(file)
  473.         end
  474.     end
  475.  
  476. end
  477.  
  478. write_startup()
  479.  
  480. if fs.exists("coords") then coord("load") else coord("save") end
  481.  
  482. startup(boolean_check(curr_coords["operating"]))
  483.  
  484. if tostring(curr_coords["operation"]) == "nil" then coord_update("start") end
  485.  
  486. while boolean_check(curr_coords["operating"]) do
  487.     if tostring(curr_coords["bedrock"]) == "nil" then bedrock("locate") end
  488.     if boolean_check(CONFIG.FLAT_BEDROCK) then layer = 1 else layer = 5 end
  489.     if tostring(curr_coords["operation"]) == "start" then coord_move(home_coords["x"], home_coords["z"], (curr_coords["bedrock"] + layer), home_coords["dir"]) coord_update("cobble") curr_coords["layer"] = 1 curr_coords["top_layer"] = (math.floor((curr_coords["bedrock"] + layer) / 3) * -1) curr_coords["columns"] = 1 curr_coords["rows"] = 1 coord("save") end
  490.     while curr_coords["layer"] < curr_coords["top_layer"] and curr_coords["y"] < (home_coords["y"] - 3) do
  491.    
  492.         if tostring(curr_coords["operation"]) == "cobble" then
  493.             while tonumber(curr_coords["dir"]) ~= 3 do turn("right") end place("forward", slots["cobble"])
  494.             while tonumber(curr_coords["dir"]) ~= 4 do turn("right") end place("forward", slots["cobble"])
  495.             while tonumber(curr_coords["dir"]) ~= 1 do turn("right") end coord_update("bedrock dig")
  496.         end
  497.        
  498.         if curr_coords["columns"] == tonumber(CONFIG.SIZE_X) then curr_coords["columns"] = 1 end
  499.        
  500.         while curr_coords["columns"] <= tonumber(CONFIG.SIZE_X) do
  501.             if curr_coords["rows"] == tonumber(CONFIG.SIZE_Z) then curr_coords["rows"] = 1 end
  502.             while curr_coords["rows"] < tonumber(CONFIG.SIZE_Z) do
  503.                 mining()
  504.                 curr_coords["rows"] = curr_coords["rows"] + 1
  505.             end
  506.            
  507.             if boolean_check(even(tonumber(curr_coords["columns"]))) and curr_coords["columns"] ~= tonumber(CONFIG.SIZE_X) then coord_update("columns shift left1") elseif not boolean_check(even(tonumber(curr_coords["columns"]))) and curr_coords["columns"] ~= tonumber(CONFIG.SIZE_X) then coord_update("columns shift right1") end
  508.             if curr_coords["operation"] == "columns shift left1" or curr_coords["operation"] == "columns shift left2" or curr_coords["operation"] == "columns shift left3" then
  509.                 if curr_coords["operation"] == "columns shift left1" then turn("left") coord_update("columns shift left2") end
  510.                 if curr_coords["operation"] == "columns shift left2" then move("forward", true) coord_update("columns shift left3") end
  511.                 if curr_coords["operation"] == "columns shift left3" then turn("left") end
  512.             elseif curr_coords["operation"] == "columns shift right1" or curr_coords["operation"] == "columns shift right2" or curr_coords["operation"] == "columns shift right3" then
  513.                 if curr_coords["operation"] == "columns shift right1" then turn("right") coord_update("columns shift right2") end
  514.                 if curr_coords["operation"] == "columns shift right2" then move("forward", true) coord_update("columns shift right3") end
  515.                 if curr_coords["operation"] == "columns shift right3" then turn("right") end
  516.             end
  517.            
  518.             coord_update("bedrock dig")
  519.             if curr_coords["rows"] == tonumber(CONFIG.SIZE_Z) then curr_coords["rows"] = 1 end
  520.             curr_coords["columns"] = curr_coords["columns"] + 1
  521.         end
  522.        
  523.         if curr_coords["columns"] >= tonumber(CONFIG.SIZE_X) then curr_coords["columns"] = 1 end
  524.         if curr_coords["operation"] == "bedrock dig" then coord_update("return to shaft") end
  525.         if curr_coords["operation"] == "return to shaft" then coord_move(home_coords["x"], home_coords["z"], curr_coords["y"], home_coords["dir"]) coord_update("next layer 1") end
  526.         if curr_coords["operation"] == "next layer 1" then curr_coords["layer"] = (curr_coords["layer"] or 1) + 1 coord_update("next layer 2") end
  527.         if curr_coords["operation"] == "next layer 2" then coord_move(home_coords["x"], home_coords["z"], (curr_coords["bedrock"] + layer + 3 * (curr_coords["layer"] - 1)), home_coords["dir"]) coord_update("cobble") end
  528.     end
  529.     storage(true)
  530.     finish()
  531. end
Advertisement
Add Comment
Please, Sign In to add comment