Advertisement
DrPleaseRespect

DrPleaseRespect_Miner

Jul 16th, 2021
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.61 KB | None | 0 0
  1. -- on runtime
  2. version_num = "1.0"
  3.  
  4. function Turn(orientation, times)
  5.     if(orientation == "Left" or orientation == "left") then
  6.         for i = 1, times, 1 do
  7.             turtle.turnLeft()
  8.         end
  9.     elseif(orientation == "Right" or orientation == "right") then
  10.         for i = 1, times, 1 do
  11.             turtle.turnRight()
  12.         end
  13.     end
  14. end
  15.  
  16. function Move(direction,times)
  17.     direction = string.lower(direction)
  18.     if (direction == "forward") then
  19.         for i = 1, times, 1 do
  20.             turtle.forward()
  21.         end
  22.     elseif (direction == "back") then
  23.         for i = 1, times, 1 do
  24.             turtle.back()
  25.         end
  26.     elseif (direction == "up") then
  27.         for i = 1, times, 1 do
  28.             turtle.up()
  29.         end
  30.     elseif (direction == "down") then
  31.         for i = 1, times, 1 do
  32.             turtle.down()
  33.         end
  34.     end
  35.  
  36. end
  37.  
  38. function Minetunnel()
  39.     turtle.dig()
  40.     while not turtle.forward() do
  41.         turtle.dig()
  42.     end
  43.     turtle.digUp()
  44. end
  45.  
  46. function MineQuit()
  47.     repeat
  48.         local _, key = os.pullEvent("key")
  49.     until key == keys.q or miner_break == true
  50.     miner_break = true
  51. end
  52.  
  53.  
  54. function MinetunnelReturn(orientation)
  55.     orientation = string.lower(orientation)
  56.     if(orientation == "left") then
  57.         Turn("left",1)
  58.     elseif (orientation == "right") then
  59.         Turn("right",1)
  60.     end
  61.     for i = 1, 10, 1
  62.     do
  63.        
  64.         Minetunnel()
  65.     end
  66.     Turn("right",2)
  67.     for i = 1, 10, 1 do
  68.         Minetunnel()
  69.     end
  70.     if(orientation == "left") then
  71.         Turn("left",1)
  72.     elseif (orientation == "right") then
  73.         Turn("right",1)
  74.     end
  75. end
  76.  
  77. function Miner(tunnels)
  78.     miner_break = false
  79.     miner_finished = false
  80.     local iteration = tunnels
  81.     local insufficient_fuel = false
  82.     for length = 1,tunnels,1 do
  83.         global_length = length
  84.         iteration = iteration - 1
  85.         if turtle.getFuelLevel() <= tunnels*3 + 50 then
  86.             insufficient_fuel = true
  87.             break
  88.         end
  89.         if miner_break == true then
  90.             break
  91.         end
  92.         MinetunnelReturn("left")
  93.         if miner_break == true then
  94.             break
  95.         end
  96.         MinetunnelReturn("right")
  97.        
  98.         if (tunnels > 1) then
  99.             if (iteration >= 1) then
  100.                 for i = 1,3,1 do
  101.                     Minetunnel()
  102.                 end
  103.             end
  104.         end
  105.     end
  106.     local tunnelblocks = tunnels * 3
  107.     Move("back",tunnelblocks)
  108.     if insufficient_fuel == true then
  109.         nofuel = true
  110.     end
  111.     miner_finished = true
  112.     miner_break = true
  113. end
  114.  
  115. function Header(clear)
  116.     local text = ' Branch Mine Helper '
  117.     local headertext = '---------------------------------------'
  118.     term.setBackgroundColor(colors.gray)
  119.     if clear == true then
  120.         term.clear()
  121.     end
  122.     term.setCursorPos(1,1)
  123.     term.blit(headertext,'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee','000000000000000000000000000000000000000')
  124.     term.setCursorPos(10,1)
  125.     term.blit(text,'00000000000000000000','ffffffffffffffffffff')
  126.     term.setCursorPos(11,5)
  127. end
  128.  
  129. function MainMenu()
  130.     term.setCursorPos(2,3)
  131.     term.setTextColor(colors.white)
  132.     term.blit("+-Options:--------+","0e00000000eeeeeeee0",'7777777777777777777')
  133.     term.setCursorPos(2,4)
  134.     term.blit("| [R]efuel        |","001e100000000000000",'7fffffffffffffffff7')
  135.     term.setCursorPos(2,5)
  136.     term.blit("| [S]tart         |","001e100000000000000",'7fffffffffffffffff7')
  137.     term.setCursorPos(2,6)
  138.     term.blit("| [E]xit          |","001e100000000000000",'7fffffffffffffffff7')
  139.     term.setCursorPos(2,7)
  140.     term.blit("+-----------------+",'0eeeeeeeeeeeeeeeee0','7777777777777777777')
  141.     term.setCursorPos(2,10)
  142.     term.blit("Script Created By DrPleaseRespect","eeeeeeeeeeeeeeeeebbbbbbbbbbbbbbbb",'fffffffffffffffffffffffffffffffff')
  143.     term.setCursorPos(2,11)
  144.     term.blit("Ver. ","eee00","fffff")
  145.     term.setCursorPos(7,11)
  146.     term.setBackgroundColor(colors.black)
  147.     term.write(version_num)
  148.     term.setBackgroundColor(colors.gray)
  149. end
  150.  
  151. function GetKey()
  152.     while true do
  153.         local event, key, is_held = os.pullEvent('key')
  154.         return key
  155.     end
  156. end
  157.  
  158. function scrollthing(height)
  159.     for i = 1, height, 1 do
  160.         term.scroll(1)
  161.         Header(false)
  162.         os.sleep(0.01)
  163.     end
  164. end
  165.  
  166.  
  167. function scrollthing_noheader(height)
  168.     for i = 1, height,1 do
  169.         term.scroll(1)
  170.         os.sleep(0.01)
  171.     end
  172.    
  173. end
  174.  
  175. function custom_refuel()
  176.     for i = 1, 16, 1 do
  177.         turtle.select(i)
  178.         turtle.refuel()
  179.     end
  180.     turtle.select(1)
  181. end
  182.  
  183. function FuelThing()
  184.     while true do
  185.         Header(true)
  186.         Fuel = turtle.getFuelLevel()
  187.         Max_Fuel = turtle.getFuelLimit()
  188.         term.setCursorPos(2,3)
  189.         term.setTextColor(colors.white)
  190.         term.blit("+-Fuel Amount:----------+","0e000000000000eeeeeeeeee0",'7777777777777777777777777')
  191.         term.setCursorPos(2,4)
  192.         term.blit("| Fuel:                 |","0000000000000000000000000",'7fffffffffffffffffffffff7')
  193.         term.setCursorPos(2,5)
  194.         term.blit("| Max Fuel:             |","0000000000000000000000000",'7fffffffffffffffffffffff7')
  195.         term.setCursorPos(2,6)
  196.         term.blit("+-----------------------+","0eeeeeeeeeeeeeeeeeeeeeee0",'7777777777777777777777777')
  197.         term.setCursorPos(10,4)
  198.         term.setBackgroundColor(colors.black)
  199.         term.write(Fuel)
  200.         term.setCursorPos(14,5)
  201.         term.write(Max_Fuel)
  202.         term.setBackgroundColor(colors.gray)
  203.         term.setCursorPos(2,8)
  204.         term.blit("+---Options---+","0ddd0000000ddd0",'777777777777777')
  205.         term.setCursorPos(2,9)
  206.         term.blit("| [R]efuel    |","001e10000000000",'7fffffffffffff7')
  207.         term.setCursorPos(2,10)
  208.         term.blit("| [E]xit      |","001e10000000000","7fffffffffffff7")
  209.         term.setCursorPos(2,11)
  210.         term.blit("+-------------+","0ddddddddddddd0","777777777777777")
  211.         local key = GetKey()
  212.         if key == keys.r then
  213.             term.setCursorPos(4,9)
  214.             term.blit('[R]','5b5','fff')
  215.             term.setCursorPos(2,13)
  216.             term.write("Press Enter to Continue")
  217.             local key = GetKey()
  218.             if key == keys.enter then
  219.                 term.setBackgroundColor(colors.black)
  220.                 term.setTextColor(colors.yellow)
  221.                 term.setCursorPos(12,6)
  222.                 term.write("+---------------+")
  223.                 term.setCursorPos(12,7)
  224.                 term.setTextColor(colors.red)
  225.                 term.write("|  Please Wait  |")
  226.                 term.setTextColor(colors.yellow)
  227.                 term.setCursorPos(12,8)
  228.                 term.write("+---------------+")
  229.                 term.setBackgroundColor(colors.gray)
  230.                 term.setTextColor(colors.white)
  231.                 custom_refuel()
  232.             end
  233.         elseif key == keys.e then
  234.             term.setCursorPos(4,10)
  235.             term.blit('[E]','5b5','fff')
  236.             term.setCursorPos(2,13)
  237.             term.write("Press Enter to Continue")
  238.             local key = GetKey()
  239.             if key == keys.enter then
  240.                 scrollthing(15)
  241.                 break
  242.             end
  243.         end
  244.     end
  245. end
  246.  
  247. function MinerMenu()
  248.     tunnel_length = 1
  249.     while true do
  250.         if tunnel_length < 1 then
  251.             tunnel_length = 1
  252.         elseif tunnel_length > 1000 then
  253.             tunnel_length = 1000
  254.         end
  255.         Header(true)
  256.         term.setCursorPos(2,4)
  257.         term.setTextColor(colors.white)
  258.         term.blit("+- Tunnel Length: -----------+","0aa00000000000000aaaaaaaaaaaa0","ffffffffffffffffffffffffffffff")
  259.         term.setCursorPos(2,5)
  260.         term.blit("| Length:                    |","0aaaaaaaaaaaaaaaaaaaaaaaaaaaa0","ffffffffffffffffffffffffffffff")
  261.         term.setCursorPos(2,6)
  262.         term.blit("+----------------------------+","0aaaaaaaaaaaaaaaaaaaaaaaaaaaa0","ffffffffffffffffffffffffffffff")
  263.         term.setCursorPos(12,5)
  264.         term.write(tunnel_length)
  265.         term.setCursorPos(2,8)
  266.         term.write("Left Arrow = -1  | Up Arrow = +10")
  267.         term.setCursorPos(2,9)
  268.         term.write("Right Arrow = +1 | Down Arrow = -10")
  269.         term.setCursorPos(2,11)
  270.         term.blit("[S]tart","1e10000",'fffffff')
  271.         term.setCursorPos(2,12)
  272.         term.blit("[E]xit","1e1000",'ffffff')
  273.         local key = GetKey()
  274.         if key == keys.left then
  275.             tunnel_length = tunnel_length - 1
  276.         elseif key == keys.right then
  277.             tunnel_length = tunnel_length + 1
  278.         elseif key == keys.up then
  279.             tunnel_length = tunnel_length + 10
  280.         elseif key == keys.down then
  281.             tunnel_length = tunnel_length - 10
  282.         elseif key == keys.s then
  283.             term.setCursorPos(2,11)
  284.             term.blit("[S]",'5b5', 'fff')
  285.             term.setCursorPos(10,11)
  286.             term.write('Press Enter to Continue')
  287.             local function minething()
  288.                 Miner(tunnel_length)
  289.             end
  290.             local key_pressed = GetKey()
  291.             if key_pressed == keys.enter then
  292.                 parallel.waitForAny(minething, MineQuit, WhileMiningMenu)
  293.                 scrollthing(15)
  294.                 break
  295.             end
  296.         elseif key == keys.e then
  297.             term.setCursorPos(2,12)
  298.             term.blit("[E]",'5b5', 'fff')
  299.             term.setCursorPos(10,12)
  300.             term.write('Press Enter to Continue')
  301.             local key_pressed = GetKey()
  302.             if key_pressed == keys.enter then
  303.                 scrollthing(15)
  304.                 break
  305.             end
  306.         end
  307.     end
  308. end
  309.  
  310. function WhileMiningMenu()
  311.     while true do
  312.         Header(true)
  313.         term.setCursorPos(2,3)
  314.         term.blit("+- Info: ------------+","0d0000000dddddddddddd0","7777777777777777777777")
  315.         term.setCursorPos(2,4)
  316.         term.blit("| Fuel:              |","0000000000000000000000","7ffffffffffffffffffff7")
  317.         term.setCursorPos(2,5)
  318.         term.blit("| Length:            |","0000000000000000000000","7ffffffffffffffffffff7")
  319.         term.setCursorPos(2,6)
  320.         term.blit("| Max Length:        |","0000000000000000000000","7ffffffffffffffffffff7")
  321.         term.setCursorPos(2,7)
  322.         term.blit("+--------------------+","0dddddddddddddddddddd0","7777777777777777777777")
  323.         term.setCursorPos(10,4)
  324.         term.write(turtle.getFuelLevel())
  325.         term.setCursorPos(12,5)
  326.         term.write(global_length)
  327.         term.setCursorPos(16,6)
  328.         term.write(tunnel_length)
  329.         term.setCursorPos(2,9)
  330.         term.write('Press Q to Exit')
  331.         if miner_break == true then
  332.             term.setCursorPos(2,9)
  333.             term.write('Waiting for Routine to Finish')
  334.             if miner_finished == true then
  335.                 break
  336.             end
  337.         end
  338.         sleep(0.5)
  339.     end
  340. end
  341.  
  342.  
  343. -- function modal(message)
  344. --     local x , y = term.getCursorPos()
  345. --     local message_length = string.len(message)
  346. --     local top = '+'
  347. --     for i = 1,message_length,1 do
  348. --         top = top .. '-'
  349. --     end
  350. --     top = top .. '+'
  351. --     term.setCursorPos(x,y)
  352. --     y = y + 1
  353. --     term.write(top)
  354. --     term.setCursorPos(x,y)
  355. --     y = y + 1
  356. --     term.write('|'..message..'|')
  357. --     term.setCursorPos(x,y)
  358. --     term.write(top)
  359. -- end
  360.  
  361. --Miner(5)
  362.  
  363. while true do
  364.     miner_break = false
  365.     nofuel = false
  366.     if nofuel == true then
  367.         FuelThing()
  368.     end
  369.     Header(true)
  370.     MainMenu()
  371.     local key_pressed = GetKey()
  372.     if key_pressed == keys.r then
  373.         term.setCursorPos(4,4)
  374.         term.blit("[R]",'5b5', 'fff')
  375.         term.setCursorPos(2,8)
  376.         term.write('Press Enter to Continue')
  377.         local key_pressed = GetKey()
  378.         if key_pressed == keys.enter then
  379.             scrollthing(10)
  380.             FuelThing()
  381.         end
  382.     elseif key_pressed == keys.s then
  383.         term.setCursorPos(4,5)
  384.         term.blit("[S]",'5b5', 'fff')
  385.         term.setCursorPos(2,8)
  386.         term.write('Press Enter to Continue')
  387.         local key_pressed = GetKey()
  388.         if key_pressed == keys.enter then
  389.             scrollthing(10)
  390.             MinerMenu()
  391.         end
  392.     elseif key_pressed == keys.e then
  393.         term.setCursorPos(4,6)
  394.         term.blit("[E]",'5b5', 'fff')
  395.         term.setCursorPos(2,8)
  396.         term.write('Press Enter to Continue')
  397.         local key_pressed = GetKey()
  398.         if key_pressed == keys.enter then
  399.             term.setBackgroundColor(colors.black)
  400.             scrollthing_noheader(15)
  401.             term.setCursorPos(1,1)
  402.             term.clear()
  403.             error()
  404.         end
  405.     end
  406. end
  407.  
  408.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement