Advertisement
Jahn_M_L

room

Apr 6th, 2021 (edited)
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. --[[
  2. How to use...
  3. Place the turle between 2 blocks and write "room <lenght> <with>"
  4. BLOCK
  5. TURTLE
  6. BLOCK
  7.  
  8. ]]--
  9.  
  10. local args = {...}
  11. local xCurrent, zCurrent = 1, 1
  12. local xMax, zMax
  13. local facing = 0 --start 0, gedreht 1
  14. if #args == 2 then
  15.     xMax = tonumber(args[1])
  16.     zMax = tonumber(args[2])
  17. elseif #args==0 then
  18.     xMax, zMax = 3, 3
  19. end
  20.  
  21. function clearInventory()
  22.     if turtle.getItemDetail(1).name=="enderstorage:ender_storage" then
  23.         if turtle.detectDown() then
  24.             turtle.digDown()
  25.         end
  26.         turtle.select(1)
  27.         turtle.placeDown()
  28.         for selSlot = 2,16 do
  29.           turtle.select(selSlot)
  30.           turtle.dropDown()
  31.         end
  32.         turtle.select(1)
  33.         turtle.digDown()
  34.     end
  35. end
  36.  
  37. function dig()
  38.     if turtle.detectUp() then
  39.         turtle.digUp()
  40.     end
  41.  
  42.     if turtle.detect() then
  43.         a, data = turtle.inspect()
  44.         if data.name =="minecraft:sand" or data.name == "minecraft:gravel" then
  45.             while turtle.detect() do
  46.                 turtle.dig()
  47.                 sleep(1)
  48.                 data = turtle.inspect()
  49.             end
  50.         else
  51.             turtle.dig()
  52.         end
  53.     end
  54.  
  55.     if turtle.detectDown() then
  56.         turtle.digDown()
  57.     end
  58. end
  59.  
  60. function digUpDown()
  61.     if turtle.detectUp() then
  62.         turtle.digUp()
  63.     end
  64.     if turtle.detectDown() then
  65.         turtle.digDown()
  66.     end
  67. end
  68.  
  69. function digForward()
  70.     while xCurrent < xMax do
  71.         dig()
  72.         turtle.forward()
  73.         xCurrent = xCurrent +1
  74.     end
  75. end
  76.  
  77. function rotate()
  78.     if facing==0 then
  79.         turtle.turnRight()
  80.         dig()
  81.         turtle.forward()
  82.         turtle.turnRight()
  83.         facing = 1
  84.     else
  85.         if facing==1 then
  86.         turtle.turnLeft()
  87.         dig()
  88.         turtle.forward()
  89.         turtle.turnLeft()
  90.         facing = 0
  91.         end
  92.     end
  93. end
  94.  
  95. function returnZ()
  96.     turtle.turnRight()
  97.     while zCurrent>1 do
  98.         turtle.forward()
  99.         zCurrent = zCurrent-1
  100.     end
  101.     turtle.turnRight()
  102. end
  103.  
  104. function ende()
  105.     if facing==0 then
  106.         digUpDown()
  107.         turtle.turnLeft()
  108.         turtle.turnLeft()
  109.         xCurrent = 1
  110.         while xCurrent < xMax do
  111.             turtle.forward()
  112.             xCurrent = xCurrent+1
  113.         end
  114.         returnZ()
  115.     elseif facing==1 then
  116.         digUpDown()
  117.         returnZ()
  118.         clearInventory()
  119.     end
  120. end
  121.  
  122. function start()
  123.     running = true
  124.     while running do
  125.         if xCurrent==xMax then
  126.             clearInventory()
  127.             rotate()
  128.             xCurrent = 1
  129.             zCurrent = zCurrent+1
  130.         end
  131.         digForward()
  132.         if zCurrent==zMax then
  133.             running=false
  134.         end
  135.     end
  136.     ende()
  137.     clearInventory()
  138. end
  139.  
  140.  
  141. --Begin
  142. if #args == 2 then
  143.     start()
  144. elseif #args == 0 then
  145.     start()
  146. else
  147.     print("Usage: room <x> <z>")
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement