Advertisement
SomeoneNew666

Minecraft ComputerCraft Room Mining Program

Sep 10th, 2020 (edited)
3,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.69 KB | None | 0 0
  1. function PlaceTorch()
  2.   for a = 1, 16 do
  3.     turtle.select(a)
  4.     c = turtle.getItemCount(a)
  5.     if c == 0 then
  6.  
  7.     else
  8.       s = turtle.getItemDetail(a)
  9.  
  10.       if s.name == "minecraft:torch" then
  11.         turtle.placeDown()
  12.         return
  13.       end
  14.     end
  15.   end
  16. end
  17.  
  18. local tArgs = {...}
  19. if #tArgs ~= 3 then
  20.   print("Requires length, width & height!")
  21.   return
  22. end
  23.  
  24. local x = tonumber(tArgs[1]) - 1
  25. local y = tonumber(tArgs[2])
  26. local z = tonumber(tArgs[3])
  27. local x2 = 0
  28. local y2 = 0
  29. local startingtorch = false
  30. local distance = 0
  31. local countdown = false
  32.  
  33. if x == nil or y == nil or z == nil then
  34.   print("Invalid dimensions!")
  35.   return
  36. end
  37.  
  38. if x < 0 or y < 0 or z < 0 then
  39.   print("Invalid (negative) dimensions!")
  40.   return
  41. end
  42.  
  43. local fuel = turtle.getFuelLevel()
  44. local roomSize = x * y * z
  45. while fuel < roomSize do
  46.   if not turtle.refuel(1) then
  47.     print("Not enough fuel!")
  48.     return
  49.   end
  50. end
  51.  
  52. local xTimes = x + 1
  53. local yTimes = y
  54. local xTorches = 0
  55. local yTorches = 0
  56. local t = true
  57. local tt = true
  58.  
  59. while t == true do
  60.   if xTimes >= 4 then
  61.     xTimes = xTimes - 4
  62.     xTorches = xTorches + 1
  63.   elseif xTimes < 4 and xTimes > 0 then
  64.     xTorches = xTorches + 1
  65.     t = false
  66.   elseif xTimes == 1 then
  67.     xTorches = xTorches + 1
  68.     t = false
  69.   else
  70.     t = false
  71.     if xTimes == 0 then
  72.       xTimes = 4
  73.     end
  74.   end
  75. end
  76.  
  77. while tt == true do
  78.   if yTimes >= 4 then
  79.     yTimes = yTimes - 4
  80.     yTorches = yTorches + 1
  81.   elseif yTimes < 4 and yTimes > 0 then
  82.     yTorches = yTorches + 1
  83.     tt = false
  84.   elseif yTimes == 1 then
  85.     yTorches = yTorches + 1
  86.     tt = false
  87.   else
  88.     tt = false
  89.     if yTimes == 0 then
  90.       yTimes = 4
  91.     end
  92.   end
  93. end
  94.  
  95. local RequiredTorches = xTorches * yTorches
  96. local Torches = 0
  97.  
  98. for a = 1, 16 do
  99.   turtle.select(a)
  100.   c = turtle.getItemCount(a)
  101.   if c == 0 then
  102.  
  103.   else
  104.     s = turtle.getItemDetail(a)
  105.     if s.name == "minecraft:torch" then
  106.       Torches = Torches + c
  107.     end
  108.   end
  109. end
  110.  
  111. if RequiredTorches > Torches and z > 1 then
  112.     print("Not enough Torches! You require a total of " .. RequiredTorches .. " Torches!")
  113.     return
  114. else
  115.     print("Good to go!")
  116. end
  117.  
  118. local direction = true
  119. for i = 1, z do
  120.   for j = 1, y do
  121.     for k = 1, x do
  122.       if i == 2 and j == yTimes and k == xTimes then
  123.         PlaceTorch()
  124.         startingtorch = true
  125.       end
  126.       if turtle.forward() == false then
  127.         repeat
  128.           turtle.dig()
  129.           sleep(0.25)
  130.         until turtle.forward() == true
  131.       end
  132.       if i == 2 and startingtorch == true then
  133.         if countdown == false then
  134.           x2 = x2 + 1
  135.           if x2 == 4 then
  136.             PlaceTorch()
  137.             x2 = 0
  138.           end
  139.         elseif countdown == true then
  140.           distance = distance + 1
  141.           if xTimes == 1 then
  142.             if distance == (x + 1) * 3 + 1 then
  143.               distance = 0
  144.               PlaceTorch()
  145.               countdown = false
  146.             end
  147.           elseif xTimes == 2 then
  148.             if distance == (x + 1) * 3 + 2 then
  149.               distance = 0
  150.               PlaceTorch()
  151.               countdown = false
  152.             end
  153.           elseif xTimes == 3 then
  154.             if distance == (x + 1) * 3 + 3 then
  155.               distance = 0
  156.               PlaceTorch()
  157.               countdown = false
  158.             end
  159.           elseif xTimes == 4 then
  160.             if distance == (x + 1) * 3 + 4 then
  161.               distance = 0
  162.               PlaceTorch()
  163.               countdown = false
  164.             end
  165.           end
  166.         end
  167.       end
  168.     end
  169.     if j < y then
  170.       if direction then
  171.         if i == 2 and countdown == false and startingtorch == true then
  172.           countdown = true
  173.         end
  174.         turtle.turnRight()
  175.         if turtle.forward() == false then
  176.           repeat
  177.             turtle.dig()
  178.             sleep(0.25)
  179.           until turtle.forward() == true
  180.         end
  181.         if i == 2 and startingtorch == true and countdown == true then
  182.           distance = distance + 1
  183.         end
  184.         turtle.turnRight()
  185.         direction = false
  186.       else
  187.         turtle.turnLeft()
  188.         if turtle.forward() == false then
  189.           repeat
  190.             turtle.dig()
  191.             sleep(0.25)
  192.           until turtle.forward() == true
  193.         end
  194.         if i == 2 and startingtorch == true and countdown == true then
  195.           distance = distance + 1
  196.           if xTimes == 1 then
  197.             if distance == (x + 1) * 3 + 1 then
  198.               distance = 0
  199.               PlaceTorch()
  200.               countdown = false
  201.             end
  202.           elseif xTimes == 2 then
  203.             if distance == (x + 1) * 3 + 2 then
  204.               distance = 0
  205.               PlaceTorch()
  206.               countdown = false
  207.             end
  208.           elseif xTimes == 3 then
  209.             if distance == (x + 1) * 3 + 3 then
  210.               distance = 0
  211.               PlaceTorch()
  212.               countdown = false
  213.             end
  214.           elseif xTimes == 4 then
  215.             if distance == (x + 1) * 3 + 4 then
  216.               distance = 0
  217.               PlaceTorch()
  218.               countdown = false
  219.             end
  220.           end
  221.         end
  222.         turtle.turnLeft()
  223.         direction = true
  224.       end
  225.     end
  226.   end
  227.   if i < z then
  228.     turtle.digUp()
  229.     turtle.up()
  230.     turtle.turnRight()
  231.     turtle.turnRight()
  232.   end
  233. end
  234.  
  235. if y % 2 == 0 then
  236.   turtle.turnRight()
  237.   for i = 1, y do
  238.     turtle.forward()
  239.   end
  240.   turtle.turnRight()
  241. else
  242.   turtle.turnLeft()
  243.   for i = 1, y do
  244.     turtle.forward()
  245.   end
  246.   turtle.turnLeft()
  247.   for i = 1, x do
  248.     turtle.forward()
  249.   end
  250.   turtle.turnRight()
  251.   turtle.turnRight()
  252. end
  253. for i = 1, z do
  254.   turtle.down()
  255. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement