Advertisement
Zekrommaster110

[LUA | CC1.4.7] Room Digging Programm v2.0

Nov 26th, 2016
4,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 KB | None | 0 0
  1. -- © 2016 zekro Development
  2. -- zekro.jimdo.com | zekrodev.jimdo.com | youtube.com/zekrommaster110
  3.  
  4. -- The program will work in the cartesian coordinate system right in that direction the picture shows.
  5. -- So the turtle will start digging to the right and back when you look at the back of the turtle.
  6. --
  7. --     z   x        
  8. --     |  /        
  9. --     | /          
  10. --     |/          
  11. --     -------- y              
  12.  
  13.  
  14. local _x, _y, _z = ...
  15. local x = tonumber(_x)
  16. local y = tonumber(_y)
  17. local z = tonumber(_z)
  18.  
  19. local t = turtle
  20.  
  21. local currentLayer = 0
  22. local bcount = 0
  23.  
  24.  
  25. ------------------------------------------------------------------------------------------------
  26. -- FUNCTIONS -----------------------------------------------------------------------------------
  27. ------------------------------------------------------------------------------------------------
  28.  
  29. function cls()
  30.    shell.run("clear")
  31. end
  32.  
  33. function checkInv()
  34.     for i=1, 16, 1 do
  35.         if (t.getItemCount(i) >= 1) then
  36.             return true
  37.         end
  38.     end
  39.     return false
  40. end
  41.  
  42. function checkFuel()
  43.     if y % 2 == 1 then
  44.         fuelNeed = z * ((x * y - 1) + (x + y - 2) + 1) + z - 2
  45.     else
  46.         fuelNeed = z * ((x * y - 1) + (y - 1) + 1) + z - 2
  47.     end
  48.     fuelIn = t.getFuelLevel()
  49.     fuelToRefill = fuelNeed - fuelIn
  50.     if fuelIn < fuelNeed then
  51.         print("Not enough fuel!\n")
  52.         print("AVAILABLE FUEL: ", fuelIn)
  53.         print("FUEL NEED:      ", fuelNeed)
  54.         print("FUEL TO INPUT:  ", fuelToRefill)
  55.         print("\nThat means: ")
  56.         print("- ", fuelToRefill / 5, " Sticks")
  57.         print("- ", fuelToRefill / 15, " Wood")
  58.         print("- ", fuelToRefill / 80, " Coal")
  59.         print("- ", fuelToRefill / 120, " Blaze Rods")
  60.         print("- ", fuelToRefill / 1000, " Buckets Lava")
  61.         print("\nPut fuel to input in slot 1...")
  62.        
  63.         while t.getItemCount(1) == 0 do
  64.             os.sleep(0.5)
  65.         end
  66.         t.refuel(64)
  67.         checkFuel()
  68.     end
  69. end
  70.  
  71. function count()
  72.     bcount = bcount+1
  73.     cls()
  74.     print("Digging in progress...\n\n", bcount, " blocks digged...")
  75. end
  76.  
  77. function fw(times)
  78.     for i=1, times, 1 do
  79.         t.forward()
  80.     end
  81. end
  82.  
  83. function digLine()
  84.     for i=2, x, 1 do
  85.         t.dig()
  86.         count()
  87.         t.forward()
  88.     end
  89. end
  90.  
  91. function digLayer()
  92.     for i=1, y, 1 do
  93.         digLine()
  94.         if i % 2 == 0 and i ~= y then
  95.             t.turnLeft()
  96.             t.dig()
  97.             count()
  98.             t.forward()
  99.             t.turnLeft()
  100.         elseif i ~= y then
  101.             t.turnRight()
  102.             t.dig()
  103.             count()
  104.             t.forward()
  105.             t.turnRight()
  106.         end
  107.     end
  108.     if y % 2 == 1 then
  109.         t.turnRight()
  110.         t.turnRight()
  111.         fw(x-1)
  112.         t.turnRight()
  113.         fw(y-1)
  114.     else
  115.         t.turnRight()
  116.         fw(y-1)
  117.     end
  118.     t.turnRight()
  119.    
  120.     if (t.getItemCount(16) >= 1) then
  121.         for i=1, currentLayer, 1 do
  122.             t.down()
  123.         end
  124.         for i=1, 16, 1 do
  125.             t.select(i)
  126.             t.dropDown(64)
  127.         end
  128.         t.select(1)
  129.         for i=2, currentLayer, 1 do
  130.             t.up()
  131.         end
  132.     end
  133. end
  134.  
  135. ------------------------------------------------------------------------------------------------
  136. -- MAIN PROGRAMM -------------------------------------------------------------------------------
  137. ------------------------------------------------------------------------------------------------
  138.  
  139. cls()
  140. t.select(1)
  141.  
  142. if x == nil or y == nil or z == nil then
  143.     print("The program arguments are invalid!\nPlease use the program like this:\n\n\"<programm name> <xcords> <ycords> <zcords>\"",
  144.     "\n\nExample:\n\"room 20 14 18\"")
  145.     error()
  146. elseif x <= 1 or y <= 1 or z <= 1 then
  147.     print("Please use coordinates that are more than 1 block.")
  148.     error()
  149. end
  150.  
  151. while (checkInv() == true) do
  152.     cls()
  153.     print("Please clear the inventory of the turtle to continue.")
  154.     os.sleep(0.5)
  155. end
  156.  
  157. checkFuel()
  158.  
  159. cls()
  160. if (x*y*z) >= 800 then
  161.     print("The turtle will dig ", (x*y*z), " blocks in this progress, so the inventory of the turtle will flow over. So I implemented a drop-out-system: Please place a (double) chest right under the turtle to catch overflowing items.")
  162.     print("\n\nPress enter to continue...")
  163.     io.read()
  164. end
  165.  
  166. cls()
  167. for i=1, z, 1 do
  168.     currentLayer = currentLayer+1
  169.     digLayer()
  170.     if i ~= z then
  171.         t.digUp()
  172.         count()
  173.         t.up()
  174.     end
  175. end
  176.  
  177. for i=1, z, 1 do
  178.     t.down()
  179. end
  180.  
  181. cls()
  182. print("Progress finished!\n\n", bcount, " blocks got digged.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement