Advertisement
DYankee

Area Mine v0.3

May 10th, 2022 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.11 KB | None | 0 0
  1. PasteId = "AKaJGAks"
  2. V = "0.3"
  3. local W,H = term.getSize()
  4. MOption = 1
  5.  
  6. --list of fuels and their value
  7. Fuel = {
  8.     "minecraft:coal_block" == 800,
  9.     "minecraft:coal" == 80,
  10.     "actuallyadditions:block_misc" == 800,
  11.     "quark:charcoal_block" == 800,
  12. }
  13.  
  14.  
  15.  
  16. --text functions
  17. function Print_centered(y,s)
  18.     s = tostring(s)
  19.     local x = math.floor((W - string.len(s)) /2)
  20.     term.setCursorPos(x,y)
  21.     term.clearLine()
  22.     term.write(s)
  23. end
  24. function Print_left(y,s)
  25.     s = tostring(s)
  26.     local x = 1
  27.     term.setCursorPos(x,y)
  28.     term.clearLine()
  29.     term.write(s)
  30. end
  31. function Print_right(y,s)
  32.     s = tostring(s)
  33.     local x = math.floor(W - string.len(s))
  34.     term.setCursorPos(x,y)
  35.     term.clearLine()
  36.     term.write(s)
  37. end
  38.  
  39. function Header()
  40.     Print_centered(1,"Area miner v" .. V)
  41. end
  42.  
  43. --turtle functions
  44. function GetFuelIndex()
  45.     for slotNum = 1, 16, 1 do
  46.         local item = turtle.getItemDetail(slotNum)
  47.         if(item ~=nil) then
  48.             for fuelIndex = 1, #fuel, 1 do
  49.                 if(item.name == fuel[fuelIndex]) then
  50.                     local fuelValue = fuelIndex[item.name]
  51.                 return slotNum, fuelValue
  52.                 end
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58. function Refuel(max)
  59.     while (turtle.getFuelLevel() < max) do
  60.     local index = getFuelIndex()
  61.         if(index ~= nil) then
  62.         turtle.select(index)
  63.         turtle.refuel(1)
  64.         end
  65.     end
  66. end
  67.  
  68.  
  69.  
  70. function Get_MOption(menu,max)
  71.     if MOption > max then
  72.         MOption = max
  73.     end
  74.     while true do
  75.         local event, key = os.pullEvent()
  76.         if event == "key" then
  77.             if key == 265 or key == 87 then
  78.                 if MOption > 1 then
  79.                     MOption = MOption - 1
  80.                     menu()
  81.                 end
  82.             elseif key == 264 or key == 83 then
  83.                 if MOption < max then
  84.                     MOption = MOption + 1
  85.                     menu()
  86.                 end
  87.             elseif key == 257 then
  88.                 break
  89.             end
  90.         end
  91.     end
  92.     return(MOption)
  93. end
  94.  
  95. function Set_dig_area()
  96.     local x,y,z = 0,0,0
  97.     local function draw_menu()
  98.         term.clear()
  99.         Header()
  100.         Print_centered(2,("Set dig area"))
  101.         Print_left(3,"Width = "..x)
  102.         Print_left(4,"Depth = "..z)
  103.         Print_left(5,"Hight = "..y)
  104.     end
  105.     draw_menu()
  106.  
  107.     --Get sizes
  108.     Print_left(6,"Please enter Width:")
  109.     term.setCursorPos(1,7)
  110.     x = read("*n")
  111.     term.clear()
  112.     draw_menu()
  113.  
  114.     Print_left(6,"Please enter Depth:")
  115.     term.setCursorPos(1,7)
  116.     z = read("*n")
  117.     term.clear()
  118.     draw_menu()
  119.  
  120.     Print_left(6,"Please enter Hight:")
  121.     term.setCursorPos(1,7)
  122.     y = read("*n")
  123.     term.clear()
  124.     draw_menu()
  125.  
  126.     --Get Directions
  127.     Print_left(6,"Please enter lateral direction:")
  128.     term.setCursorPos(1,7)
  129.     local latDir = read()
  130.     term.clear()
  131.     draw_menu()
  132.  
  133.     Print_left(6,"Please enter lateral direction:")
  134.     term.setCursorPos(1,7)
  135.     local vertDir = read()
  136.     term.clear()
  137.     draw_menu()
  138.  
  139.     Curent_dig_area = {
  140.     x = x,
  141.     z = z,
  142.     y = y,
  143.     lat = latDir,
  144.     vert = vertDir
  145.     }
  146.     Main_menu()
  147. end
  148.  
  149. function Dig()
  150.     local x = tonumber(Curent_dig_area.x)
  151.     local z = tonumber(Curent_dig_area.z)
  152.     local y = tonumber(Curent_dig_area.y)
  153.     if Curent_dig_area.lat == "right" then
  154.         LatDirection = true
  155.     else
  156.         LatDirection = false
  157.     end
  158.    
  159.     local fuelNeeded = x * z * (math.ceil(y/3))
  160.     local tRows = math.floor(y/3)
  161.     turtle.refuel(fuelNeeded)
  162.  
  163.     local function Mine_row()
  164.         if y >=3 then
  165.             for i = 1, z - 1, 1 do
  166.                 turtle.digUp()
  167.                 turtle.dig()
  168.                 turtle.digDown()
  169.                 turtle.forward()
  170.                 print(i .. "-" .. z)
  171.             end
  172.         elseif y == 2 then
  173.             for i = 1, z - 1, 1 do
  174.                 turtle.digUp()
  175.                 turtle.dig()
  176.                 turtle.forward()
  177.                 print(i .. "-" .. z)
  178.             end
  179.         elseif y == 1 then
  180.             for i = 1, z - 1, 1 do
  181.                 turtle.dig()
  182.                 turtle.forward()
  183.                 print(i .. "-" .. z)
  184.             end
  185.         end
  186.     end
  187.  
  188.     local function Next_row(direction,curentRow)
  189.         if direction == false then
  190.             if (curentRow% 2 == 1) then
  191.                 turtle.turnLeft()
  192.                 if y >= 3 then
  193.                     turtle.digUp()
  194.                     turtle.dig()
  195.                     turtle.digDown()
  196.                 elseif y == 2 then
  197.                     turtle.digUp()
  198.                     turtle.dig()
  199.                 elseif y == 1 then
  200.                     turtle.dig()
  201.                 end
  202.                 turtle.forward()
  203.                 turtle.turnLeft()
  204.             else
  205.                 turtle.turnRight()
  206.                 if y >= 3 then
  207.                     turtle.digUp()
  208.                     turtle.dig()
  209.                     turtle.digDown()
  210.                 elseif y == 2 then
  211.                     turtle.digUp()
  212.                     turtle.dig()
  213.                 elseif y == 1 then
  214.                     turtle.dig()
  215.                 end
  216.                 turtle.forward()
  217.                 turtle.turnRight()
  218.             end
  219.         elseif direction == true then
  220.             if (curentRow% 2 == 1) then
  221.                 turtle.turnRight()
  222.                 if y >= 3 then
  223.                     turtle.digUp()
  224.                     turtle.dig()
  225.                     turtle.digDown()
  226.                 elseif y == 2 then
  227.                     turtle.digUp()
  228.                     turtle.dig()
  229.                 elseif y == 1 then
  230.                     turtle.dig()
  231.                 end
  232.                 turtle.forward()
  233.                 turtle.turnRight()
  234.             else
  235.                 turtle.turnLeft()
  236.                 if y >= 3 then
  237.                     turtle.digUp()
  238.                     turtle.dig()
  239.                     turtle.digDown()
  240.                 elseif y == 2 then
  241.                     turtle.digUp()
  242.                     turtle.dig()
  243.                 elseif y == 1 then
  244.                     turtle.dig()
  245.                 end
  246.                 turtle.forward()
  247.                 turtle.turnLeft()
  248.             end
  249.         end
  250.     end
  251.  
  252.  
  253.  
  254. --get in start pos
  255.     turtle.up()
  256.     turtle.dig()
  257.     turtle.forward()
  258. --dig loop
  259.     while y >= 1 do
  260.         for i = 1, x, 1 do
  261.             Mine_row()
  262.             if i < x then
  263.                 Next_row(LatDirection,i)
  264.             else
  265.                 turtle.digUp()
  266.                 turtle.digDown()
  267.             end
  268.         end
  269.         if y >= 3 then
  270.             y = y - 3
  271.         elseif y == 2 then
  272.             y = 2 - 2
  273.         elseif y == 1 then
  274.             y = y - 1
  275.         end
  276.         if y > 0 then
  277.             turtle.turnRight()
  278.             turtle.turnRight()
  279.             if x%2 == 0 then
  280.                 LatDirection = not LatDirection
  281.             end
  282.             if y >=3 then
  283.                 turtle.up()
  284.                 turtle.digUp()
  285.                 turtle.up()
  286.                 turtle.digUp()
  287.                 turtle.up()
  288.             else
  289.                 turtle.up()
  290.                 turtle.digUp()
  291.                 turtle.up()
  292.             end
  293.         end
  294.     end
  295. end
  296.  
  297.  
  298.  
  299.  
  300. -- ui and logic for main menu
  301. function Main_menu()
  302.     -- ui for the main menu
  303.     local function draw_menu()
  304.         term.clear()
  305.         Header()
  306.         Print_centered(5,((MOption == 1 and "[ Start ]") or "Start"))
  307.         Print_centered(6,((MOption == 2 and "[ Change dig size ]") or "Change dig size"))
  308.         Print_centered(7,((MOption == 3 and "[ Exit ]") or "Exit"))
  309.     end
  310.     term.clear()
  311.     draw_menu()
  312.     Get_MOption(draw_menu,3)
  313.  
  314. --logic for Main_menu
  315.     if MOption == 1 then
  316.         print(Curent_dig_area.x)
  317.         print(Curent_dig_area.z)
  318.         print(Curent_dig_area.y)
  319.         sleep(3)
  320.         term.clear()
  321.         Dig()
  322.     elseif MOption == 2 then
  323.         Set_dig_area()
  324.     elseif MOption ==3 then
  325.         shell.run("/os/programMenu")
  326.     end
  327. end
  328.  
  329. Main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement