Michl7

botminer

Dec 6th, 2017 (edited)
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 34.18 KB | None | 0 0
  1. --pastebin get q354743w botminer
  2. --Last Update: 14.12.2025-11:00
  3.  
  4. term.clear()
  5. term.setCursorPos(1,1)
  6.  
  7. local ignore = {"minecraft:stone",
  8.                 "minecraft:dirt",
  9.                 "minecraft:andesite",
  10.                 "minecraft:granite",
  11.                 "minecraft:diorite",
  12.                 "minecraft:gravel",
  13.                 "minecraft:deepslate",
  14.                 "minecraft:cobbled_deepslate",
  15.                 "minecraft:tuff",
  16.                 "minecraft:calcite",
  17.                 "minecraft:smooth_basalt",
  18.                 "minecraft:amethyst_block",
  19.                 "xycraft_world:kivi",
  20.                 "forbidden_arcanus:darkstone",
  21.                 "create:weathered_limestone",
  22.                 "create:limestone",
  23.                 "create:dolomite",
  24.                 "create:gabbro",
  25.                 "create:crimsite",
  26.                 "create:natural_scoria",
  27.                 "create:dark_scoria",
  28.                 "create:scoria",
  29.                 "create:asurine",
  30.                 "minecraft:obsidian",
  31.                 "minecraft:sand",
  32.                 "minecraft:cobblestone",   
  33.                 "minecraft:grass_block",
  34.                 "minecraft:bedrock",
  35.                 "minecraft:oak_planks",
  36.                 "minecraft:chest",
  37.                 "minecraft:torch",
  38.                 "minecraft:ladder",
  39.                 "minecraft:netherrack",
  40.                 "computercraft:turtle_advanced",
  41.                 "computercraft:turtle_normal",
  42.                 "minecraft:polished_andesite",
  43.                 "minecraft:cyan_terrracotta",
  44.                 "minecraft:smooth_stone",
  45.                 "minecraft:mossy_cobblestone",
  46.                 "minecraft:coarse_dirt",
  47.                 "minecraft:smooth_stone_slab",
  48.                 "minecraft:polished_andesite_stairs",
  49.                 "forbidden_arcanus:stella_arcanum",
  50.                 "lootr:lootr_chest",
  51.                 "lootr:lootr_barrel"}
  52.  
  53. local backupignore = {"minecraft:stone",
  54.                     "minecraft:chest",
  55.                     "minecraft:torch",
  56.                     "minecraft:cobblestone",
  57.                     "minecraft:sand",
  58.                     "minecraft:grass_block",
  59.                     "minecraft:dirt",
  60.                     "minecraft:gravel",
  61.                     "minecraft:obsidian",
  62.                     "minecraft:andesite",
  63.                     "minecraft:granite",
  64.                     "minecraft:diorite",
  65.                     "minecraft:bedrock",
  66.                     "computercraft:turtle_advanced",
  67.                     "computercraft:turtle_normal",
  68.                     "quark:marble",
  69.                     "quark:limestone",
  70.                     "quark:slate",
  71.                     "quark:deepslate",
  72.                     "forbidden_arcanus:dark_stone",
  73.                     "forbidden_arcanus:petrified_root",
  74.                     "silentgems:hardened_netherrack",
  75.                     "silentgems:hardened_end_stone",
  76.                     "create:weathered_limestone",
  77.                     "create:limestone",
  78.                     "create:dolomite",
  79.                     "create:gabbro",
  80.                     "create:natural_scoria",
  81.                     "create:dark_scoria",
  82.                     "create:scoria",
  83.                     "astralsorcery:marble_raw",
  84.                     "chisel:basalt2",
  85.                     "rustic:slate",
  86.                     "chisel:limestone2",
  87.                     "chisel:marble2",
  88.                     "chisel:stonebrick",
  89.                     "chisel:stonebrick1",
  90.                     "chisel:stonebrick2",
  91.                     "chisel:cobblestone"}
  92.  
  93. local exclude = {"allthemodium:allthemodium_ore",
  94.                 "allthemodium:allthemodium_slate_ore",
  95.                 "irons_spellbooks:mithril_ore",
  96.                 "irons_spellbooks:deepslate_mithril_ore"}
  97.                
  98. local excludeAlways = {"forbidden_arcanus:stella_arcanum",
  99.                         "lootr:lootr_chest",
  100.                         "lootr:lootr_barrel"}
  101.  
  102. local modemFound = false
  103. local programReset = false
  104. local programInspect = false
  105. local returnedStep = false
  106. local skipShafts = false
  107. local cancelProgram = false
  108. local oreFound = false
  109. local maxOreLimitHit = false
  110.  
  111. local posDforward = 0
  112. local shaft = 0
  113. local skipShaftsNum = 0
  114. local amountOreTotal = 0
  115. local startShaft = 1
  116. local maxOres = 100 --max amount of ores in one vein; if reached bot will stop vein mining and return to shaft, at next drop off at chest bot will display message that the limit was hit.
  117.  
  118. local startTime = 0
  119. local endTime = 0
  120. local differenceTime = 0
  121. local firstDropSlot = 1
  122.  
  123. local foundOre=""
  124. local BotStatus = "Booting"
  125.  
  126. local monitorMessage =""
  127.  
  128. local posX = 0
  129. local posY = 0
  130. local posZ = 0
  131. local posD = 0
  132.  
  133. local posXhome = 0
  134. local posYhome = 0
  135. local posZhome = 0
  136. local posDhome = 0
  137.  
  138. local posXsave = {}
  139. local posYsave = {}
  140. local posZsave = {}
  141. local posDsave = {}
  142.  
  143. local posXgps = 0
  144. local posYgps = 0
  145. local posZgps = 0
  146. local posDgps = 0
  147.  
  148. local posXgps2 = 0
  149. local posYgps2 = 0
  150. local posZgps2 = 0
  151.  
  152. local posXgpshome = 0
  153. local posYgpshome = 0
  154. local posZgpshome = 0
  155. local posDgpshome = 0
  156.  
  157. --Filnames: Config,DisplayID,GPS,DisplaySave
  158. local filenames={"bmconfig","bmsave","bmgps","bmdispsave"}
  159.  
  160. local statusText = {"Running",          --1
  161.                     "Need Fuel",        --2
  162.                     "Mining Vein",      --3     +oreamount
  163.                     "Return Vein",      --4
  164.                     "Heading Home",     --5
  165.                     "Leaving Home",     --6     after heading home
  166.                     "Deposit Stuff",    --7
  167.                     "Moved GPS-Home",   --8
  168.                     "At GPS-Home",      --9
  169.                     "No GPS!",          --10
  170.                     "Chest Full",       --11
  171.                     "Max Ore Limit",    --12
  172.                     "Excluded Block",   --13
  173.                     "Need Support"}     --14
  174.                    
  175. local arg={...}
  176. local saveTable = {}
  177. local gpsTable = {}
  178.  
  179.  
  180. local DisplayHeaderTable = {"BotID : ",
  181.                             "Fuel  : ",
  182.                             "PosX  : ",
  183.                             "PosY  : ",
  184.                             "PosZ  : ",
  185.                             "PosD  : ",
  186.                             "Shaft : ",
  187.                             "Status: "}
  188. local DisplayDataTable = {}
  189. local DisplayTable = {}
  190.  
  191. local configText = {"Length of Shafts",
  192.                     "Number of Shafts",
  193.                     "Slot for checking if full",
  194.                     "Minimum amount of Fuel",
  195.                     "Direction for Shafts 1=Right 3=Left",
  196.                     "Use GPS? 1=Yes 0=No",
  197.                     "Use Ender Chest Drop? 1=Yes 0=No",
  198.                     "Use Excluded Block detection? 1=Yes 0=No"}
  199. local config={}
  200. --Default config for 5x5 chunks loaded starting in the middle of the edge chunck
  201. config[1] = 60      --length of shafts
  202. config[2] = 22      --num of shafts
  203. config[3] = 13      --checkslot for full
  204. config[4] = 500     --minFuel
  205. config[5] = 1       --Shaft direction 1=Right 3=Left
  206. config[6] = 0       --GPS
  207. config[7] = 0       --EnderChestDrop
  208. config[8] = 1       --Exclude
  209.  
  210. function useArgs()
  211.     readParams = 0
  212.     while readParams < #arg do
  213.         if string.lower(arg[readParams+1]) == "-skip" then
  214.             if not (readParams+1 < #arg) or tonumber(readParams+2) == nil  then
  215.                 print('Bad Argument! Type "botminer -help" for help!')
  216.                 return false
  217.             else
  218.                 skipShafts = true
  219.                 skipShaftsNum = tonumber(arg[readParams+2])
  220.                 readParams=readParams+2
  221.             end
  222.         elseif string.lower(arg[readParams+1]) == "-reset" then
  223.             programReset = true
  224.             readParams=readParams+1
  225.         elseif string.lower(arg[readParams+1]) == "-inspect" then
  226.             programInspect = true
  227.             readParams=readParams+1
  228.         elseif string.lower(arg[readParams+1]) == "-refuel" then
  229.             firstDropSlot = 1
  230.             while true do
  231.                 advRefuel()
  232.             end
  233.         elseif string.lower(arg[readParams+1]) == "-help" then
  234.                 print("Help-Page:")
  235.                 print("botminer -skip #  -> Amount of shafts the bot will skip.")
  236.                 print("botminer -reset   -> Will reset the config of the bot.")
  237.                 print("botminer -inspect -> Shows block name in front of bot.")
  238.                 print("botminer -refuel  -> Starts refuel mode.")
  239.                 return false
  240.         else
  241.             print('Bad Argument! Type "botminer -help" for help!')
  242.             return false
  243.         end
  244.     end
  245.     return true
  246. end
  247.  
  248. function GPSfile()
  249.     if not fs.exists(filenames[3]) then
  250.         gpsTable = {posXgps, posYgps, posZgps, posDgps}
  251.         f = fs.open(filenames[3], "w")
  252.         f.write(textutils.serialize(gpsTable))
  253.         f.close()
  254.         createStartup(true)
  255.         return false
  256.     else
  257.         f = fs.open(filenames[3], "r")
  258.         gpsTable =textutils.unserialize(f.readAll())
  259.         f.close()
  260.         posXgpshome = gpsTable[1]
  261.         posYgpshome = gpsTable[2]
  262.         posZgpshome = gpsTable[3]
  263.         posDgpshome = gpsTable[4]
  264.         return true
  265.     end
  266. end
  267.  
  268. function DisplaySavefile()
  269.     if not fs.exists(filenames[4]) then
  270.         createStartup(true)
  271.         return false
  272.     else
  273.         f = fs.open(filenames[4], "r")
  274.         DisplayDataTable = textutils.unserialize(f.readAll())
  275.         f.close()
  276.         return true
  277.     end
  278. end
  279.  
  280. function bot_getGPSpos()
  281.     posXgps, posYgps, posZgps = gps.locate()
  282.     if not posXgps then return false end
  283.     while turtle.forward() == false do
  284.         bot_dig()
  285.         turtle.attack()
  286.     end
  287.     posXgps2, posYgps2, posZgps2 = gps.locate()
  288.     if     posXgps < posXgps2 then
  289.         posDgps = 0
  290.     elseif posYgps < posYgps2 then
  291.         posDgps = 1
  292.     elseif posXgps > posXgps2 then
  293.         posDgps = 2
  294.     elseif posYgps > posYgps2 then
  295.         posDgps = 3
  296.     end
  297.     while turtle.back() == false do
  298.         bot_turnRight()
  299.         bot_turnRight()
  300.         bot_dig()
  301.         turtle.attack()
  302.         bot_turnRight()
  303.         bot_turnRight()
  304.     end
  305.     return true
  306. end
  307.  
  308. function bot_checkGPShome()
  309.     if posXgps == posXgpshome then
  310.         if posYgps == posYgpshome then
  311.             if posZgps == posZgpshome then
  312.                 if posDgps == posDgpshome then
  313.                     return true
  314.                 else
  315.                     return false
  316.                 end
  317.             else
  318.                 return false
  319.             end
  320.         else
  321.             return false
  322.         end
  323.     else
  324.         return false
  325.     end
  326. end
  327.  
  328. function bot_returnhomeGPS()
  329.    
  330.     posX = posXgps
  331.     posY = posYgps
  332.     posZ = posZgps
  333.     posD = posDgps
  334.     local calcXgps = posXgps - posXgpshome
  335.     local calcYgps = posYgps - posYgpshome
  336.  
  337.     while posZ ~= posZgpshome do
  338.         if posZ > posZgpshome then
  339.             bot_down()
  340.         elseif posZ < posZgpshome then
  341.             bot_up()
  342.         end
  343.     end
  344.     if calcXgps <= calcYgps then
  345.         if posX > posXgpshome then
  346.             while posD ~= 2 do
  347.                 bot_turnRight()
  348.             end
  349.             while posX ~= posXgpshome do
  350.                 bot_forward()
  351.             end
  352.         elseif posX < posXgpshome then
  353.             while posD ~= 0 do
  354.                 bot_turnRight()
  355.             end
  356.             while posX ~= posXgpshome do
  357.                 bot_forward()
  358.             end
  359.         end
  360.         if posY > posYgpshome then
  361.             while posD ~= 3 do
  362.                 bot_turnRight()
  363.             end
  364.             while posY ~= posYgpshome do
  365.                 bot_forward()
  366.             end
  367.         elseif posY < posYgpshome then
  368.             while posD ~= 1 do
  369.                 bot_turnRight()
  370.             end
  371.             while posY ~= posYgpshome do
  372.                 bot_forward()
  373.             end
  374.         end
  375.     elseif calcYgps <= calcXgps then
  376.         if posY > posYgpshome then
  377.             while posD ~= 3 do
  378.                 bot_turnRight()
  379.             end
  380.             while posY ~= posYgpshome do
  381.                 bot_forward()
  382.             end
  383.         elseif posY < posYgpshome then
  384.             while posD ~= 1 do
  385.                 bot_turnRight()
  386.             end
  387.             while posY ~= posYgpshome do
  388.                 bot_forward()
  389.             end
  390.         end
  391.         if posX > posXgpshome then
  392.             while posD ~= 2 do
  393.                 bot_turnRight()
  394.             end
  395.             while posX ~= posXgpshome do
  396.                 bot_forward()
  397.             end
  398.         elseif posX < posXgpshome then
  399.             while posD ~= 0 do
  400.                 bot_turnRight()
  401.             end
  402.             while posX ~= posXgpshome do
  403.                 bot_forward()
  404.             end
  405.         end
  406.     end
  407.     while posD ~= posDgpshome do
  408.         bot_turnRight()
  409.     end
  410.    
  411.     posX = 0
  412.     posY = 0
  413.     posZ = 0
  414.     posD = 0
  415. end
  416.  
  417. function configFile()
  418.     if not fs.exists(filenames[1]) then
  419.         configInput()
  420.         f = fs.open(filenames[1], "w")
  421.         f.write(textutils.serialize(config))
  422.         f.close()
  423.     else
  424.         f = fs.open(filenames[1], "r")
  425.         config = textutils.unserialize(f.readAll())
  426.         f.close()
  427.     end
  428.     for i=1, #config do
  429.         config[i] = tonumber(config[i])
  430.     end
  431. end
  432.  
  433. function configInput()
  434.     for i=1, #config do
  435.         local IOinput = ""
  436.         term.clear()
  437.         term.setCursorPos(1,1)
  438.         print("Default is for 5x5 chunks loaded;")
  439.         print("starting at middle of edge chunk.")
  440.         print(configText[i].." - Default: "..config[i])
  441.         IOinput = tonumber(io.read())
  442.         if type( IOinput ) == "number" then
  443.             config[i] = IOinput
  444.             print("Used input: "..config[i])
  445.         else
  446.             print("Used default value!")
  447.         end
  448.         sleep(0.5)
  449.     end
  450.     configCheck()
  451. end
  452.  
  453. function configCheck()
  454.     term.clear()
  455.     term.setCursorPos(1,1)
  456.     if config[1] < 1 then                                   --length
  457.         print("Wrong Input at: "..configText[1].." Press ENTER!")
  458.         io.read()
  459.         configInput()
  460.     elseif config[2] < 1 or config[2] > 99 then             --shafts
  461.         print("Wrong Input at: "..configText[2].." Press ENTER!")
  462.         io.read()
  463.         configInput()
  464.     elseif config[3] < 1 or config[3] > 16 then             --checkslot
  465.         print("Wrong Input at: "..configText[3].." Press ENTER!")
  466.         io.read()
  467.         configInput()
  468.     elseif config[4] < 1 then                               --minFuel
  469.         print("Wrong Input at: "..configText[4].." Press ENTER!")
  470.         io.read()
  471.         configInput()
  472.     elseif config[5] ~= 1 and config[5] ~= 3 then           --Shaft direction
  473.         print("Wrong Input at: "..configText[5].." Press ENTER!")
  474.         io.read()
  475.         configInput()
  476.     elseif config[6] ~= 0 and config[6] ~= 1 then           --GPS
  477.         print("Wrong Input at: "..configText[6].." Press ENTER!")
  478.         io.read()
  479.         configInput()
  480.     elseif config[7] ~= 0 and config[7] ~= 1 then           --EnderChestDrop
  481.         print("Wrong Input at: "..configText[7].." Press ENTER!")
  482.         io.read()
  483.         configInput()
  484.     elseif config[8] ~= 0 and config[8] ~= 1 then           --Exclude
  485.         print("Wrong Input at: "..configText[8].." Press ENTER!")
  486.         io.read()
  487.         configInput()
  488.     end
  489. end
  490.  
  491. function checkwlan()
  492.     for _,side in ipairs({"left", "right"}) do
  493.         if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  494.             rednet.open(side)
  495.             modemFound = true
  496.             -- if not fs.exists(filenames[2]) then
  497.                 -- print("WLAN-Display-ID?")
  498.                 -- saveTable[1] = tonumber(io.read())
  499.                 -- f = fs.open(filenames[2], "w")
  500.                 -- f.write(textutils.serialize(saveTable))
  501.                 -- f.close()
  502.             -- else
  503.                 -- f = fs.open(filenames[2], "r")
  504.                 -- saveTable =textutils.unserialize(f.readAll())
  505.                 -- f.close()
  506.             -- end
  507.             break
  508.         end
  509.     end
  510. end
  511.  
  512. function displayUpdate(reboot)
  513.    
  514.     -- DisplayHeaderTable[1] = "BotID : "
  515.     -- DisplayHeaderTable[2] = "Fuel  : "
  516.     -- DisplayHeaderTable[3] = "PosX  : "
  517.     -- DisplayHeaderTable[4] = "PosY  : "
  518.     -- DisplayHeaderTable[5] = "PosZ  : "
  519.     -- DisplayHeaderTable[6] = "PosD  : "
  520.     -- DisplayHeaderTable[7] = "Shaft : "
  521.     -- DisplayHeaderTable[8] = "Status: "
  522.    
  523.     --Prepare and save Display Data
  524.     if reboot == false then
  525.         DisplayDataTable[1] =  os.getComputerID()
  526.         DisplayDataTable[2] =  turtle.getFuelLevel()
  527.         DisplayDataTable[3] =  posX
  528.         DisplayDataTable[4] =  posY
  529.         DisplayDataTable[5] =  posZ
  530.         DisplayDataTable[6] =  posD
  531.         DisplayDataTable[7] =  shaft
  532.         DisplayDataTable[8] =  BotStatus
  533.         DisplayDataTable[9] =  turtle.getFuelLimit()
  534.         DisplayDataTable[10] = config[2] --num of shafts
  535.    
  536.         if fs.exists(filenames[4]) then fs.delete(filenames[4]) end
  537.         f = fs.open(filenames[4], "w")
  538.         f.write(textutils.serialize(DisplayDataTable))
  539.         f.close()
  540.     end
  541.    
  542.    
  543.     --Display Info in Bot Terminal
  544.     DisplayTable[1] = DisplayHeaderTable[1]..DisplayDataTable[1]
  545.     DisplayTable[2] = DisplayHeaderTable[2]..DisplayDataTable[2].." / "..DisplayDataTable[9]
  546.     DisplayTable[3] = DisplayHeaderTable[3]..DisplayDataTable[3]
  547.     DisplayTable[4] = DisplayHeaderTable[4]..DisplayDataTable[4]
  548.     DisplayTable[5] = DisplayHeaderTable[5]..DisplayDataTable[5]
  549.     DisplayTable[6] = DisplayHeaderTable[6]..DisplayDataTable[6]
  550.     DisplayTable[7] = DisplayHeaderTable[7]..DisplayDataTable[7].."/"..DisplayDataTable[10]
  551.     DisplayTable[8] = DisplayHeaderTable[8]..DisplayDataTable[8]
  552.    
  553.     term.clear()
  554.     term.setCursorPos(1,1)
  555.     for i=1, #DisplayTable do
  556.         print(DisplayTable[i])
  557.     end
  558.    
  559.     if modemFound then
  560.         modemSend()
  561.         -- modemReceive()
  562.     end
  563. end
  564.  
  565. function modemSend()
  566.     local dataTable = { tostring(DisplayDataTable[1]),
  567.                         tostring(DisplayDataTable[2]),
  568.                         tostring(DisplayDataTable[3]),
  569.                         tostring(DisplayDataTable[4]),
  570.                         tostring(DisplayDataTable[5]),
  571.                         tostring(DisplayDataTable[6]),
  572.                         tostring(DisplayDataTable[8]),
  573.                         tostring(DisplayDataTable[7]),
  574.                         tostring(DisplayDataTable[10])}
  575.    
  576.     --rednet.send(tonumber(saveTable[1]),textutils.serialize(dataTable),"BOT")
  577.     rednet.broadcast(textutils.serialize(dataTable),"BOT")
  578. end
  579.  
  580. function oldstuff()
  581. -- function modemReceive()
  582.     -- local senderId, message, protocol = rednet.receive("BOT",0.01)
  583.     -- if senderId == saveTable[1] then
  584.         -- monitorMessage = message
  585.         -- if message == "cancel" then
  586.             -- cancelProgram = true
  587.         -- end
  588.     -- else
  589.         -- monitorMessage = ""
  590.     -- end
  591. -- end
  592. end
  593.  
  594. function bot_digTunnel()
  595.     while turtle.forward() == false do
  596.         bot_dig()
  597.         turtle.attack()
  598.     end
  599.     if posD == 0 then
  600.         posX = posX+1
  601.     elseif posD == 1 then
  602.         posY = posY+1
  603.     elseif posD == 2 then
  604.         posX = posX-1
  605.     elseif posD == 3 then
  606.         posY = posY-1
  607.     end
  608.     displayUpdate(false)
  609.     bot_digUp()
  610. end
  611.  
  612. function bot_returnTunnel() --WHY!!!!!!!!!!!!!!!!!!!
  613.     while turtle.forward() == false do
  614.         bot_dig()
  615.         turtle.attack()
  616.     end
  617.     posX = posX-1
  618.     displayUpdate(false)
  619. end
  620.  
  621. function bot_forward()
  622.     while turtle.forward() == false do
  623.         bot_dig()
  624.         turtle.attack()
  625.     end
  626.     if posD == 0 then
  627.         posX = posX+1
  628.     elseif posD == 1 then
  629.         posY = posY+1
  630.     elseif posD == 2 then
  631.         posX = posX-1
  632.     elseif posD == 3 then
  633.         posY = posY-1
  634.     end
  635.     displayUpdate(false)
  636. end
  637.  
  638. function bot_back()
  639.     while turtle.back() == false do
  640.         bot_turnRight()
  641.         bot_turnRight()
  642.         bot_dig()
  643.         turtle.attack()
  644.         bot_turnRight()
  645.         bot_turnRight()
  646.     end
  647.     if posD == 0 then
  648.         posX = posX-1
  649.     elseif posD == 1 then
  650.         posY = posY-1
  651.     elseif posD == 2 then
  652.         posX = posX+1
  653.     elseif posD == 3 then
  654.         posY = posY+1
  655.     end
  656.     displayUpdate(false)
  657. end
  658.  
  659. function bot_up()
  660.     while turtle.up() == false do
  661.         bot_digUp()
  662.         turtle.attackUp()
  663.     end
  664.     posZ = posZ+1
  665.     displayUpdate(false)
  666. end
  667.  
  668. function bot_down()
  669.     while turtle.down() == false do
  670.         bot_digDown()
  671.         turtle.attackDown()
  672.     end
  673.     posZ = posZ-1
  674.     displayUpdate(false)
  675. end
  676.  
  677. function bot_turnRight()
  678.     if turtle.turnRight() then
  679.         posD = posD + 1
  680.         if posD > 3 then
  681.             posD = 0
  682.         end
  683.     end
  684. end
  685.  
  686. function bot_turnLeft()
  687.     if turtle.turnLeft() then
  688.         posD = posD - 1
  689.         if posD < 0 then
  690.             posD = 3
  691.         end
  692.     end
  693. end
  694.  
  695. function bot_checkoresUp()
  696.     if turtle.detectUp() then
  697.         local successUp, dataUp = turtle.inspectUp()
  698.         if successUp then
  699.             for i=1,#ignore do
  700.                 if dataUp.name == ignore[i] then
  701.                     if dataUp.name == exclude then
  702.                         excludeOre()
  703.                     end
  704.                     return false
  705.                 end
  706.             end
  707.             foundOre = "Up"
  708.             return true
  709.         end
  710.     end
  711. end
  712.  
  713. function bot_checkoresDown()
  714.     if turtle.detectDown() then
  715.         local successDown, dataDown = turtle.inspectDown()
  716.         if successDown then
  717.             for i=1,#ignore do
  718.                 if dataDown.name == ignore[i] then
  719.                     if dataDown.name == exclude then
  720.                         excludeOre()
  721.                     end
  722.                     return false
  723.                 end
  724.             end
  725.             foundOre = "Down"
  726.             return true
  727.         end
  728.     end
  729. end
  730.  
  731. function bot_checkoresRight()
  732.     bot_turnRight()
  733.     if turtle.detect() then
  734.         local successRight, dataRight = turtle.inspect()
  735.         if successRight then
  736.             for i=1,#ignore do
  737.                 if dataRight.name == ignore[i] then
  738.                     if dataRight.name == exclude then
  739.                         excludeOre()
  740.                     end
  741.                     bot_turnLeft()
  742.                     return false               
  743.                 end
  744.             end
  745.             foundOre = "Right"
  746.             bot_turnLeft()
  747.             return true
  748.         end
  749.     end
  750.     bot_turnLeft()
  751. end
  752.  
  753. function bot_checkoresLeft()
  754.     bot_turnLeft()
  755.     if turtle.detect() then
  756.         local successLeft, dataLeft = turtle.inspect()
  757.         if successLeft then
  758.             for i=1,#ignore do
  759.                 if dataLeft.name == ignore[i] then
  760.                     if dataLeft.name == exclude then
  761.                         excludeOre()
  762.                     end
  763.                     bot_turnRight()
  764.                     return false               
  765.                 end
  766.             end
  767.             foundOre = "Left"
  768.             bot_turnRight()
  769.             return true
  770.         end
  771.     end
  772.     bot_turnRight()
  773. end
  774.  
  775. function bot_checkoresBack()
  776.     bot_turnLeft()
  777.     bot_turnLeft()
  778.     if turtle.detect() then
  779.         local successBack, dataBack = turtle.inspect()
  780.         if successBack then
  781.             for i=1,#ignore do
  782.                 if dataBack.name == ignore[i] then
  783.                     if dataBack.name == exclude then
  784.                         excludeOre()
  785.                     end
  786.                     bot_turnRight()
  787.                     bot_turnRight()
  788.                     return false               
  789.                 end
  790.             end
  791.             foundOre = "Back"
  792.             bot_turnRight()
  793.             bot_turnRight()
  794.             return true
  795.         end
  796.     end
  797.     bot_turnRight()
  798.     bot_turnRight()
  799. end
  800.  
  801. function bot_checkoresFornt()
  802.     if turtle.detect() then
  803.         local successFront, dataFront = turtle.inspect()
  804.         if successFront then
  805.             for i=1,#ignore do
  806.                 if dataFront.name == ignore[i] then
  807.                     if dataFront.name == exclude then
  808.                         excludeOre()
  809.                     end
  810.                     return false               
  811.                 end
  812.             end
  813.             foundOre = "Front"
  814.             return true
  815.         end
  816.     end
  817. end
  818.  
  819. function bot_dig()
  820.     bot_checkExcludeFront()
  821.     turtle.dig()
  822. end
  823.  
  824. function bot_digUp()
  825.     bot_checkExcludeUp()
  826.     turtle.digUp()
  827. end
  828.  
  829. function bot_digDown()
  830.     bot_checkExcludeDown()
  831.     turtle.digDown()
  832. end
  833.  
  834. function bot_checkExcludeFront()
  835.     if turtle.detect() then
  836.         local successFront, dataFront = turtle.inspect()
  837.         if successFront then
  838.             if config[8] == 1 then
  839.                 for i=1,#exclude do
  840.                     if dataFront.name == exclude[i] then
  841.                         excludeOre()
  842.                     end
  843.                 end
  844.             end
  845.             for i=1,#excludeAlways do
  846.                 if dataFront.name == excludeAlways[i] then
  847.                     excludeAlwaysOre()
  848.                 end
  849.             end
  850.         end
  851.     end
  852. end
  853.  
  854. function bot_checkExcludeUp()
  855.     if turtle.detectUp() then
  856.         local successUp, dataUp = turtle.inspectUp()
  857.         if successUp then
  858.             if config[8] == 1 then
  859.                 for i=1,#exclude do
  860.                     if dataUp.name == exclude[i] then
  861.                         excludeOre()
  862.                     end
  863.                 end
  864.             end
  865.             for i=1,#excludeAlways do
  866.                 if dataUp.name == excludeAlways[i] then
  867.                     excludeAlwaysOre()
  868.                 end
  869.             end
  870.         end
  871.     end
  872. end
  873.  
  874. function bot_checkExcludeDown()
  875.     if turtle.detectDown() then
  876.         local successDown, dataDown = turtle.inspectDown()
  877.         if successDown then
  878.             if config[8] == 1 then
  879.                 for i=1,#exclude do
  880.                     if dataDown.name == exclude[i] then
  881.                         excludeOre()
  882.                     end
  883.                 end
  884.             end
  885.             for i=1,#excludeAlways do
  886.                 if dataDown.name == excludeAlways[i] then
  887.                     excludeAlwaysOre()
  888.                 end
  889.             end
  890.         end
  891.     end
  892. end
  893.  
  894. function excludeOre()
  895.     BotStatus = statusText[13]
  896.     displayUpdate(false)
  897.     term.clear()
  898.     term.setCursorPos(1,1)
  899.     print("Found excluded Block! Press ENTER to resume.")
  900.     io.read()
  901.     BotStatus = statusText[1]
  902. end
  903.  
  904. function excludeAlwaysOre()
  905.     BotStatus = statusText[14]
  906.     displayUpdate(false)
  907.     term.clear()
  908.     term.setCursorPos(1,1)
  909.     print("Found always excluded Block! Please Help! Press ENTER to resume.")
  910.     io.read()
  911.     BotStatus = statusText[1]
  912. end
  913.  
  914. function bot_savePos()
  915.     table.insert(posXsave,posX)
  916.     table.insert(posYsave,posY)
  917.     table.insert(posZsave,posZ)
  918.     table.insert(posDsave,posD)
  919. end
  920.  
  921. function bot_turntoOre()
  922.     if foundOre == "Right" then
  923.         bot_turnRight()
  924.     elseif foundOre == "Left" then
  925.         bot_turnLeft()
  926.     elseif foundOre == "Back" then
  927.         bot_turnLeft()
  928.         bot_turnLeft()
  929.     end
  930. end
  931.  
  932. function bot_digOre()
  933.     if foundOre == "Up" then
  934.         bot_up()
  935.     elseif foundOre == "Down" then
  936.         bot_down()
  937.     elseif foundOre == "Right" then
  938.         bot_forward()
  939.     elseif foundOre == "Left" then
  940.         bot_forward()
  941.     elseif foundOre == "Front" then
  942.         bot_forward()      
  943.     end
  944. end
  945.  
  946. function mineOresCheck()
  947.     if returnedStep then
  948.         returnedStep = false
  949.         if bot_checkoresUp() or bot_checkoresDown() or bot_checkoresFornt() or bot_checkoresRight() or bot_checkoresLeft() or bot_checkoresBack() then
  950.             oreFound = true
  951.             return true
  952.         else
  953.             oreFound = false
  954.             return false   
  955.         end
  956.     else
  957.         if bot_checkoresUp() or bot_checkoresDown() or bot_checkoresFornt() or bot_checkoresRight() or bot_checkoresLeft() then
  958.             oreFound = true
  959.             return true
  960.         else
  961.             oreFound = false
  962.             return false   
  963.         end
  964.     end
  965. end
  966.  
  967. function bot_returnStep()
  968.     --while posX ~= posXsave or posY ~= posYsave or posZ ~= posZsave or posD ~= posDsave do
  969.         local x = #posXsave
  970.         if posZ > posZsave[x] then bot_down() end
  971.         if posZ < posZsave[x] then bot_up() end
  972.         if posD == 0 then
  973.             if posX > posXsave[x] then bot_back() end
  974.             if posX < posXsave[x] then bot_forward() end
  975.         elseif posD == 1 then
  976.             if posY > posYsave[x] then bot_back() end
  977.             if posY < posYsave[x] then bot_forward() end
  978.         elseif posD == 2 then
  979.             if posX < posXsave[x] then bot_back() end
  980.             if posX > posXsave[x] then bot_forward() end   
  981.         elseif posD == 3 then
  982.             if posY < posYsave[x] then bot_back() end
  983.             if posY > posYsave[x] then bot_forward() end   
  984.         end
  985.         while posD ~= posDsave[x] do
  986.             bot_turnRight()
  987.         end
  988.         if posD == 0 then
  989.             if posX > posXsave[x] then bot_back() end
  990.             if posX < posXsave[x] then bot_forward() end
  991.         elseif posD == 1 then
  992.             if posY > posYsave[x] then bot_back() end
  993.             if posY < posYsave[x] then bot_forward() end
  994.         elseif posD == 2 then
  995.             if posX < posXsave[x] then bot_back() end
  996.             if posX > posXsave[x] then bot_forward() end   
  997.         elseif posD == 3 then
  998.             if posY < posYsave[x] then bot_back() end
  999.             if posY > posYsave[x] then bot_forward() end   
  1000.         end
  1001.     --end
  1002.     table.remove(posXsave,x)
  1003.     table.remove(posYsave,x)
  1004.     table.remove(posZsave,x)
  1005.     table.remove(posDsave,x)
  1006. end
  1007.  
  1008. function bot_mineOres()
  1009.     local mineores = true
  1010.     local amountOreVein = 0
  1011.     while mineores do
  1012.         if config[7] == 1 then
  1013.             if bot_StatusInventory() then
  1014.                 bot_dropStuffEnder()
  1015.             end
  1016.         end
  1017.         BotStatus = statusText[3]..": "..amountOreVein
  1018.         displayUpdate(false)
  1019.         if amountOreVein < maxOres then
  1020.             bot_turntoOre()
  1021.             bot_savePos()
  1022.             bot_digOre()
  1023.             amountOreVein = amountOreVein + 1
  1024.             displayUpdate(false)
  1025.             while mineOresCheck() == false and #posXsave > 0 do
  1026.                 bot_returnStep()
  1027.                 returnedStep = true
  1028.                 BotStatus = statusText[4]..": "..amountOreVein
  1029.             end
  1030.         else
  1031.             while #posXsave > 0 do
  1032.                 bot_returnStep()
  1033.                 returnedStep = true
  1034.                 BotStatus = statusText[4]..": "..amountOreVein
  1035.             end
  1036.             oreFound = false
  1037.             maxOreLimitHit = true
  1038.         end
  1039.         if #posXsave == 0 and oreFound == false then
  1040.             mineores = false
  1041.             amountOreTotal = amountOreTotal + amountOreVein
  1042.             BotStatus = statusText[1]
  1043.             turnDforward(posDforward)
  1044.             -- if bot_checkoresRight() or bot_checkoresLeft() then
  1045.                 -- bot_mineOres()
  1046.             -- end
  1047.         end
  1048.     end
  1049. end
  1050.  
  1051. function bot_returnhome()
  1052.     BotStatus = statusText[5]
  1053.     posXhome = posX
  1054.     posYhome = posY
  1055.     posZhome = posZ
  1056.     posDhome = posD
  1057.    
  1058.     while posZ ~= 1 do
  1059.         if posZ > 1 then
  1060.             bot_down()
  1061.         elseif posZ < 1 then
  1062.             bot_up()
  1063.         end
  1064.     end
  1065.     while posD ~= 2 do
  1066.         bot_turnRight()
  1067.     end
  1068.     while posX ~= 0 do
  1069.         bot_forward()
  1070.     end
  1071.     if posY ~= 0 then
  1072.         if config[5] == 1 then
  1073.             while posD ~= 3 do
  1074.                 bot_turnRight()
  1075.             end
  1076.         elseif config[5] == 3 then
  1077.             while posD ~= 1 do
  1078.                 bot_turnRight()
  1079.             end
  1080.         end
  1081.         while posY ~= 0 do
  1082.             bot_forward()
  1083.         end
  1084.         while posD ~= 2 do
  1085.             bot_turnRight()
  1086.         end
  1087.     end
  1088.     bot_down()
  1089. end
  1090.  
  1091. function bot_leavehome()
  1092.     BotStatus = statusText[6]
  1093.     bot_up()
  1094.     if posYhome ~= 0 then
  1095.         while posD ~= config[5] do
  1096.             bot_turnRight()
  1097.         end
  1098.         while posY ~= posYhome do
  1099.             bot_forward()
  1100.         end
  1101.     end
  1102.     while posD ~= 0 do
  1103.         bot_turnRight()
  1104.     end
  1105.    
  1106.     while posX ~= posXhome do
  1107.         bot_forward()
  1108.     end
  1109.     while posZ ~= posZhome do
  1110.         if posZ > posZhome then
  1111.             bot_down()
  1112.         elseif posZ < posZhome then
  1113.             bot_up()
  1114.         end
  1115.     end
  1116.     while posD ~= posDhome do
  1117.         bot_turnRight()
  1118.     end
  1119.     posXhome = 0
  1120.     posYhome = 0
  1121.     posZhome = 0
  1122.     posDhome = 0
  1123.     BotStatus = statusText[1]
  1124. end
  1125.  
  1126. function bot_StatusFuel()
  1127.     if  turtle.getFuelLevel() < config[4] then
  1128.         return true
  1129.     else
  1130.         return false
  1131.     end
  1132. end
  1133.  
  1134. function bot_StatusInventory()
  1135.     if turtle.getItemCount(config[3]) > 0 then
  1136.         return true
  1137.     else
  1138.         return false
  1139.     end
  1140. end
  1141.  
  1142. function bot_checkStatus()
  1143.     if bot_StatusFuel() then
  1144.         bot_home("Fuel")
  1145.     elseif bot_StatusInventory() then
  1146.         bot_home("Inv")
  1147.     elseif cancelProgram then
  1148.         bot_returnhome()
  1149.         bot_dropStuff()
  1150.         programEnd()
  1151.     end
  1152. end
  1153.  
  1154. function bot_dropStuffHome()
  1155.     bot_checkMaxOreLimitHit()
  1156.     BotStatus = statusText[7]
  1157.     displayUpdate(false)
  1158.     for i=firstDropSlot,16 do
  1159.         turtle.select(i)
  1160.         if turtle.getItemCount() > 0 then
  1161.             while not turtle.drop() do
  1162.                 BotStatus = statusText[11]
  1163.                 displayUpdate(false)
  1164.                 term.clear()
  1165.                 term.setCursorPos(1,1)
  1166.                 print("Empty chest and press ENTER.")
  1167.                 io.read()
  1168.                 BotStatus = statusText[7]
  1169.                 displayUpdate(false)
  1170.             end
  1171.         end
  1172.     end
  1173.     turtle.select(firstDropSlot)
  1174.     BotStatus = statusText[1]
  1175. end
  1176.  
  1177. function bot_dropStuffEnder()
  1178.     bot_checkMaxOreLimitHit()
  1179.     BotStatus = statusText[7]
  1180.     displayUpdate(false)
  1181.     bot_dig()
  1182.     turtle.select(1)
  1183.     turtle.place()
  1184.     for i=firstDropSlot,16 do
  1185.         turtle.select(i)
  1186.         if turtle.getItemCount() > 0 then
  1187.             while not turtle.drop() do
  1188.                 BotStatus = statusText[11]
  1189.                 displayUpdate(false)
  1190.                 term.clear()
  1191.                 term.setCursorPos(1,1)
  1192.                 print("Empty chest!")
  1193.             end
  1194.             BotStatus = statusText[7]
  1195.             displayUpdate(false)
  1196.         end
  1197.     end
  1198.     turtle.select(1)
  1199.     bot_dig()
  1200.     BotStatus = statusText[1]
  1201. end
  1202.  
  1203. function bot_checkMaxOreLimitHit()
  1204.     if maxOreLimitHit == true then
  1205.         BotStatus = statusText[12]
  1206.         displayUpdate(false)
  1207.         term.clear()
  1208.         term.setCursorPos(1,1)
  1209.         print("Bot hit max Ore Limit("..maxOres.."Ores) for one vein, maybe there is a new material which needs to be added to the ignore list?")
  1210.         print("Press ENTER to resume")
  1211.         io.read()
  1212.         maxOreLimitHit = false
  1213.     end
  1214. end
  1215.  
  1216. function bot_refuel(minimum)
  1217.     BotStatus = statusText[2]
  1218.     displayUpdate(false)
  1219.     while turtle.getFuelLevel() < minimum do
  1220.         advRefuel()
  1221.     end
  1222.     turtle.select(firstDropSlot)
  1223.     BotStatus = statusText[1]
  1224. end
  1225.  
  1226. function bot_home(reason)
  1227.     if config[7] == 0 then
  1228.         bot_returnhome()
  1229.         bot_dropStuffHome()
  1230.         bot_refuel(config[4])
  1231.         bot_leavehome()
  1232.     else
  1233.         if reason == "Fuel" then
  1234.             bot_returnhome()
  1235.             bot_refuel(config[4])
  1236.             bot_leavehome()
  1237.         elseif reason == "Inv" then
  1238.             bot_dropStuffEnder()
  1239.         end
  1240.     end
  1241. end
  1242.  
  1243. function nextShaft()
  1244.     bot_up()
  1245.     posDforward = config[5]
  1246.     turnDforward(posDforward)
  1247.     for i=1,3 do
  1248.         bot_digTunnel()
  1249.         bot_digDown()
  1250.     end
  1251.     posDforward = 0
  1252.     turnDforward(posDforward)
  1253.     bot_down()
  1254. end
  1255.  
  1256. function skipShaft()
  1257.     bot_up()
  1258.     posDforward = config[5]
  1259.     turnDforward(posDforward)
  1260.     for i=1, skipShaftsNum do
  1261.         for i=1,3 do
  1262.             bot_digTunnel()
  1263.             bot_digDown()
  1264.         end
  1265.     end
  1266.     posDforward = 0
  1267.     turnDforward(posDforward)
  1268.     bot_down()
  1269. end
  1270.  
  1271. function programEnd()
  1272.     endTime = os.clock()
  1273.     differenceTime = endTime - startTime
  1274.     differenceTime = math.floor (differenceTime)
  1275.     BotStatus = differenceTime.."s / "..amountOreTotal.." Ores"
  1276.     if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
  1277.     displayUpdate(false)
  1278.     print("END")
  1279. end
  1280.  
  1281. function programStop()
  1282.     while true do
  1283.         displayUpdate(false)
  1284.         print("STOP")
  1285.         sleep(5)
  1286.     end
  1287. end
  1288.  
  1289. function programTerminate()
  1290.     print("Terminated")
  1291.     sleep(1)
  1292.     os.reboot()
  1293. end
  1294.  
  1295. function turnDforward(pos)
  1296.     while posD ~= pos do
  1297.         if posD == 0 and pos == 1 then
  1298.             bot_turnRight()
  1299.         elseif posD == 0 and pos == 3 then
  1300.             bot_turnLeft()
  1301.         elseif posD == 1 and pos == 0 then
  1302.             bot_turnLeft()
  1303.         elseif posD == 1 and pos == 2 then
  1304.             bot_turnRight()
  1305.         elseif posD == 2 and pos == 1 then
  1306.             bot_turnLeft()
  1307.         elseif posD == 2 and pos == 3 then
  1308.             bot_turnRight()
  1309.         elseif posD == 3 and pos == 2 then
  1310.             bot_turnLeft()
  1311.         elseif posD == 3 and pos == 0 then
  1312.             bot_turnRight()
  1313.         else
  1314.             bot_turnRight()
  1315.         end
  1316.     end
  1317. end
  1318.  
  1319. function bot_GPSreboot()
  1320.     if bot_getGPSpos() then
  1321.         if GPSfile() then
  1322.             if not bot_checkGPShome() then
  1323.                 bot_returnhomeGPS()
  1324.                 createStartup(false)
  1325.                 if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
  1326.                 BotStatus = statusText[8]
  1327.                 programStop()
  1328.             end
  1329.             createStartup(false)
  1330.             if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
  1331.             BotStatus = statusText[9]
  1332.             programStop()
  1333.         else
  1334.             main()
  1335.         end
  1336.     else
  1337.         BotStatus = statusText[10]
  1338.         print("No GPS found!")
  1339.         print("To start without GPS press ENTER.")
  1340.         io.read()
  1341.         createStartup(false)
  1342.         if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
  1343.         main()
  1344.     end
  1345. end
  1346.  
  1347. function createStartup(autostart)
  1348.     if fs.exists("startup") then fs.delete("startup") end
  1349.     L1 = "fs.delete('botminer')"
  1350.     L2 = "shell.run('pastebin','get','q354743w','botminer')"
  1351.     L3 = "shell.run('botminer')"
  1352.  
  1353.     startup = fs.open("startup", "w")
  1354.     startup.writeLine(L1)
  1355.     startup.writeLine(L2)
  1356.     if autostart then
  1357.         startup.writeLine(L3)
  1358.     end
  1359.     startup.close()
  1360. end
  1361.  
  1362. function advRefuel()
  1363.     local neededLavaBuckets = (turtle.getFuelLimit() - turtle.getFuelLevel()) / 1000
  1364.     local neededCoal        = (turtle.getFuelLimit() - turtle.getFuelLevel()) / 80
  1365.     local neededCoalStacks  = neededCoal / 64
  1366.     turtle.select(firstDropSlot)
  1367.     term.clear()
  1368.     term.setCursorPos(1,1)
  1369.     print("Refuel Overview")
  1370.     print("Fuel Level: "..turtle.getFuelLevel().." / "..turtle.getFuelLimit())
  1371.     print("-------------------------------------")
  1372.     print("Needed Material for full refuel:     ")
  1373.     print("Lava Buckets   : ".. neededLavaBuckets)
  1374.     print("Coal / Charcoal: ".. neededCoal.." ("..neededCoalStacks.." Stacks)")
  1375.     print("-------------------------------------")
  1376.     print("Put fuel in any slot and press ENTER.")
  1377.     io.read()
  1378.     for i=firstDropSlot, 16 do
  1379.         if turtle.getFuelLevel() >= turtle.getFuelLimit() then
  1380.             break
  1381.         end
  1382.         turtle.select(i)
  1383.         turtle.refuel()
  1384.         term.clear()
  1385.         term.setCursorPos(1,1)
  1386.         print("Fuel: "..turtle.getFuelLevel().." / "..turtle.getFuelLimit())
  1387.     end
  1388.     print("Remove Buckets and Press ENTER.")
  1389.     io.read()
  1390. end
  1391.  
  1392. function bot_EnderChest()
  1393.     while turtle.getItemCount(1) ~= 1 do
  1394.         term.clear()
  1395.         term.setCursorPos(1,1)
  1396.         print("Put EnderChest in first slot and press ENTER.")
  1397.         io.read()
  1398.     end
  1399.     firstDropSlot = 2
  1400. end
  1401.  
  1402. function main()
  1403.     if config[7] == 1 then bot_EnderChest() end
  1404.     advRefuel()
  1405.     bot_refuel(config[4])
  1406.     startTime = os.clock()
  1407.     if skipShafts then
  1408.         skipShaft()
  1409.         skipShafts = false
  1410.         startShaft = skipShaftsNum + 1
  1411.     end
  1412.     for x=startShaft, config[2] do
  1413.         shaft = x
  1414.         if shaft > skipShaftsNum then
  1415.             for i=1, config[1] do
  1416.                 displayUpdate(false)
  1417.                 bot_checkStatus()
  1418.                 bot_digTunnel()
  1419.                 if bot_checkoresUp() or bot_checkoresDown() or bot_checkoresRight() or bot_checkoresLeft() then
  1420.                     bot_mineOres()
  1421.                 end
  1422.             end
  1423.             if bot_checkoresFornt() then
  1424.                 bot_mineOres()
  1425.             end
  1426.             posDforward = 2
  1427.             bot_up()
  1428.             if bot_checkoresFornt() or bot_checkoresRight() or bot_checkoresLeft() then
  1429.                 bot_mineOres()
  1430.             end
  1431.             turnDforward(posDforward)
  1432.             while posX > 0 do
  1433.                 displayUpdate(false)
  1434.                 bot_checkStatus()
  1435.                 bot_returnTunnel()
  1436.                 if bot_checkoresUp() or bot_checkoresDown() or bot_checkoresRight() or bot_checkoresLeft() then
  1437.                     bot_mineOres()
  1438.                 end
  1439.             end
  1440.             bot_down()
  1441.             displayUpdate(false)
  1442.         end
  1443.         if shaft < config[2] then
  1444.             nextShaft()
  1445.         end
  1446.     end
  1447.     if config[7] == 1 then bot_dropStuffEnder() end
  1448.     bot_returnhome()
  1449.     if config[7] == 0 then bot_dropStuffHome() end 
  1450.     programEnd()
  1451. end
  1452.  
  1453. function detectENTER()
  1454.         local sEvent, param = os.pullEvent("key")
  1455.         if sEvent == "key" then
  1456.             if param == 28 then
  1457.                 print("Enter detected")
  1458.             end
  1459.         end
  1460. end
  1461.  
  1462. function RebootDisplayUpdate()
  1463.     while true do
  1464.         displayUpdate(true)
  1465.         print("Press ENTER.")
  1466.         sleep(2)
  1467.     end
  1468. end
  1469.  
  1470. if useArgs() then
  1471.     if programInspect then
  1472.         while true do
  1473.             local has_block, data = turtle.inspect()
  1474.             term.clear()
  1475.             term.setCursorPos(1,1)
  1476.             if has_block then
  1477.                 print(data.name)
  1478.             else
  1479.                 print("No block")
  1480.             end
  1481.             io.read()
  1482.         end
  1483.     end
  1484.     if programReset then
  1485.         for i=1, #filenames do
  1486.             if fs.exists(filenames[i]) then fs.delete(filenames[i]) end
  1487.         end
  1488.     end
  1489.     checkwlan()
  1490.     configFile()
  1491.     if config[6] == 1 and fs.exists(filenames[3]) then
  1492.         bot_GPSreboot() --reboot script if GPS is used
  1493.     else
  1494.         if DisplaySavefile() then
  1495.             DisplayDataTable[8] =  "X-"..DisplayDataTable[8]
  1496.             parallel.waitForAny(RebootDisplayUpdate,detectENTER)
  1497.             createStartup(false)
  1498.             if fs.exists(filenames[4]) then fs.delete(filenames[4]) end
  1499.             programTerminate()
  1500.         end
  1501.         main()
  1502.     end
  1503. end
Advertisement
Add Comment
Please, Sign In to add comment