Advertisement
Guest User

deepBranch

a guest
Feb 19th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.58 KB | None | 0 0
  1. -----Quick Configs-------------
  2. nonOre = {"gross:stuff"}
  3. ignore = { "minecraft:stone",
  4.            "minecraft:sand",
  5.            "minecraft:gravel",
  6.            "minecraft:dirt",
  7.            "chisel:chisel.limestone",
  8.            "chisel:chisel.marble" }
  9. -------------------------------
  10.  
  11. check = {}
  12. shaftVal = 0
  13.  
  14.  
  15. function fuelCheck()
  16.   if turtle.getFuelLevel() < 80 then
  17.     local tmp = turtle.getSelectedSlot()
  18.     turtle.select(16)
  19.     turtle.refuel(1)
  20.     turtle.select(tmp)
  21.   end
  22. end
  23.  
  24. function genericInspect(check,arg)
  25.   for i = 1,#ignore do
  26.     if check.name == ignore[i] then
  27.       return false
  28.     end
  29.   end
  30.   for i = 1,#arg do
  31.     if check.name == arg[i] then
  32.       return false
  33.     end
  34.   end
  35.   return true
  36. end
  37.  
  38.  
  39. function identify(arg)
  40.   local dig
  41.   local tmp
  42.   local tmp2
  43.   turtle.turnLeft()
  44.   tmp,tmp2 = turtle.inspect()
  45.   dig = genericInspect(tmp2,arg)
  46.   if dig then
  47.     turtle.dig()
  48.   end
  49.   turtle.turnRight()
  50.   turtle.turnRight()
  51.   tmp,tmp2 = turtle.inspect()
  52.   dig = genericInspect(tmp2,arg)
  53.   if dig then
  54.     turtle.dig()
  55.   end
  56.   turtle.turnLeft()
  57.   tmp,tmp2 = turtle.inspectDown()
  58.   dig = genericInspect(tmp2,arg)
  59.   if dig then
  60.     turtle.digDown()
  61.   end
  62.   turtle.up()
  63.   tmp,tmp2 = turtle.inspectUp()
  64.   dig = genericInspect(tmp2,arg)
  65.   if dig then
  66.     turtle.digUp()
  67.   end
  68.   turtle.turnRight()
  69.   tmp,tmp2 = turtle.inspect()
  70.   dig = genericInspect(tmp2,arg)
  71.   if dig then turtle.dig() end
  72.   turtle.turnLeft()
  73.   turtle.turnLeft()
  74.   tmp,tmp2 = turtle.inspect()
  75.   dig = genericInspect(tmp2,arg)
  76.   if dig then turtle.dig() end
  77.   turtle.turnRight()
  78.   turtle.down()
  79. end
  80.  
  81. function nextStep()
  82.   fuelCheck()
  83.   while turtle.detect() do
  84.     turtle.dig()
  85.     sleep(.7)
  86.   end
  87.   turtle.forward()
  88.   while turtle.detectUp() do
  89.     turtle.digUp()
  90.     sleep(.7)
  91.   end
  92. end
  93.  
  94. function placeTorch()
  95.   local tmp = turtle.getSelectedSlot()
  96.   turtle.select(15)
  97.   fuelCheck()
  98.   turtle.up()
  99.   while turtle.detectUp() do
  100.     turtle.digUp()
  101.     sleep(.7)
  102.   end
  103.   turtle.placeUp()
  104.   turtle.down()
  105.   turtle.select(tmp)
  106. end
  107.  
  108. function digBranch(depth,arg)
  109.   for i = 1,depth do
  110.     nextStep()
  111.     identify(arg)
  112.     if i == 1 or i%7 == 0 or i == depth then
  113.       placeTorch()
  114.     end
  115.   end
  116.   turtle.turnLeft()
  117.   turtle.turnLeft()
  118.   for i = 1,depth do
  119.     turtle.forward()
  120.   end
  121. end
  122.  
  123.  
  124.  
  125. function nextTine(td,dir,arg)
  126.   nextStep()
  127.   if dir == "r" then identify(arg) end--
  128.   nextStep()
  129.   if dir == "r" then identify(arg) end--
  130.   nextStep()
  131.   if dir == "r" then identify(arg) end--
  132.   if dir == "r" then
  133.     turtle.turnRight()
  134.   else
  135.     turtle.turnLeft()
  136.   end
  137.   digBranch(td,arg)
  138.   if dir == "r" then
  139.     turtle.turnRight()
  140.   else
  141.     turtle.turnLeft()
  142.   end
  143. end
  144.  
  145. function completeSide(tn,td,dir,arg)
  146.   for i = 1, tn do
  147.     nextTine(td,dir,arg)
  148.   end
  149.   turtle.turnRight()
  150.   turtle.turnRight()
  151.   for i = 1,tn*3 do
  152.     fuelCheck()
  153.     turtle.forward()
  154.   end
  155.   turtle.turnRight()
  156.   turtle.turnRight()
  157. end
  158.  
  159. function clearInv()
  160.   turtle.turnRight()
  161.   for i = 1,14 do
  162.     turtle.select(i)
  163.     if turtle.compareDown() then
  164.       turtle.drop()
  165.     end
  166.   end
  167.   turtle.turnLeft()
  168.   turtle.turnLeft()
  169.   for i = 1,14 do
  170.     turtle.select(i)
  171.     turtle.drop()
  172.   end
  173.   turtle.turnRight()
  174. end
  175.  
  176. function shaft(depth)
  177.   shaftVal = depth
  178.   local t = true
  179.   fuelCheck()
  180.   turtle.forward()
  181.   for i = 1,depth do
  182.     if i%40 == 0 then
  183.       fuelCheck()
  184.     end
  185.    
  186.     turtle.digDown()
  187.     if not turtle.down() then
  188.       shaftVal = i - 1
  189.     end
  190.   end
  191.  
  192.   for k = 1,depth do
  193.   fuelCheck()
  194.     if k%40 == 0 then
  195.       fuelCheck()
  196.     end
  197.       turtle.up()
  198.   end
  199.   turtle.back()
  200. end
  201.  
  202. function shaftDown(depth)
  203.   fuelCheck()
  204.   turtle.forward()
  205.   for i = 1,depth do
  206.     if i%40 == 0 then
  207.       fuelCheck()
  208.     end
  209.     turtle.down()
  210.   end
  211. end
  212.  
  213. function shaftUp(depth)
  214.   fuelCheck()
  215.   for i = 1,depth do
  216.     if i%40 == 0 then
  217.       fuelCheck()
  218.     end
  219.     turtle.up()
  220.   end
  221.   turtle.back()
  222. end
  223.  
  224. function fullMine(sd,tn,td,arg)
  225.   shaft(sd)
  226.   clearInv()
  227.   shaftDown(sd)
  228.   completeSide(tn,td,"r",arg)
  229.   shaftUp(sd)
  230.   clearInv()
  231.   shaftDown(sd)
  232.   completeSide(tn,td,"l",arg)
  233.   shaftUp(sd)
  234.   clearInv()
  235. end
  236.  
  237. function fuelEstimate(sd,tn,td)
  238.   return (((sd*4)+4)+(tn*18)+(((td*3)+td)*tn))
  239. end
  240.  
  241. function torchEstimate(tn,td)
  242.   return (tn+(td%7))
  243. end
  244.  
  245. function invInsure()
  246.   local tmp = {}
  247.   tmp = turtle.getItemDetail(turtle.select(16))
  248.   if tmp == nil then
  249.     error("You must put coal in slot 16")
  250.   end
  251.   if tmp.name ~= "minecraft:coal" then
  252.     error("You must put coal in slot 16")
  253.   end
  254.   tmp = turtle.getItemDetail(turtle.select(15))
  255.   if tmp == nil then
  256.     error("You must put torches or glowstone in slot 15")
  257.   end
  258.   if tmp.name ~= "minecraft:torch" and tmp.name ~= "minecraft:glowstone" then
  259.     error("You must put torches or glowstone in slot 15")
  260.   end
  261. end
  262.  
  263. -----------
  264. --Program--
  265. -----------
  266. tArgs = {...}
  267. term.clear()
  268. term.setCursorPos(1,1)
  269. print("Shaft Depth: "..tostring(tArgs[1]))
  270. print("Number of Tines: "..tostring(tArgs[2]))
  271. print("Tine Depth: "..tostring(tArgs[3]))
  272. write("Total Blocks of Travel: ")
  273. local tfuel = fuelEstimate(tArgs[1],tArgs[2],tArgs[3])
  274. local ttorch = torchEstimate(tArgs[2],tArgs[3])
  275. print(tfuel)
  276. write("Total Mandatory Fuel: ")
  277. print(tfuel/80)
  278. write("Total Mandatory Torches: ")
  279. print(ttorch)
  280. invInsure()
  281. if tfuel/80 > 64 or tfuel/80 > turtle.getItemCount(turtle.select(16)) then
  282.   --error("Not enough fuel!")
  283.   printError("Not enough fuel!")
  284.   local count = 0
  285.   local x,y = term.getCursorPos()
  286.   print("Add "..tostring((tfuel/80)-turtle.getItemCount(turtle.select(16))).." more fuel to continue!")
  287.   while tfuel/80 > turtle.getItemCount(turtle.select(16)) do
  288.     term.setCursorPos(x,y)
  289.     print("Add "..tostring((tfuel/80)-turtle.getItemCount(turtle.select(16))).." more fuel to continue!")
  290.     count = count + 1
  291.     sleep(3)
  292.     if count == 60 then error("Timeout error on refuel") end
  293.   end
  294. end
  295. if ttorch > 64 or ttorch > turtle.getItemCount(turtle.select(15)) then
  296.   printError("Not enough torches!")
  297.   local x,y = term.getCursorPos()
  298.   print("Add "..tostring(ttorch - turtle.getItemCount(turtle.select(15))).." more to continue!")
  299.   local count = 0
  300.   while ttorch > turtle.getItemCount(turtle.select(15)) do
  301.     term.setCursorPos(x,y)
  302.     print("Add "..tostring(ttorch - turtle.getItemCount(turtle.select(15))))
  303.     count = count + 1
  304.     sleep(3)
  305.     if count == 60 then error("Timeout error on torch fill") end
  306.   end
  307. end
  308. print("Proceeding with dig...")
  309.  
  310.  
  311. fullMine(tArgs[1],tArgs[2],tArgs[3],tArgs)
  312.  
  313. print("Dig complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement