Advertisement
melzneni

TURTLE_MOVE_BLOCKS

Nov 26th, 2020 (edited)
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local args={...}
  2.  
  3. function placeForward(blockCount,offset)
  4.     local countAll={}
  5.     local consumed={}
  6.    
  7.     for i=1,16 do countAll[i]=turtle.getItemCount(i) end
  8.    
  9.     for i=1,blockCount do
  10.         if turtle.detect() then
  11.             local found=false
  12.             turtle.dig()
  13.             for l=1,16 do
  14.                 local c=turtle.getItemCount(l)
  15.                 if countAll[l]~=c then
  16.                     countAll[l]=c
  17.                     consumed[i]=l
  18.                     found=true
  19.                     break
  20.                 end
  21.             end
  22.             if not found then
  23.                 consumed[i]=-1
  24.             end
  25.         else
  26.             consumed[i]=-1
  27.         end
  28.        
  29.         while not turtle.forward() do
  30.             print("blocked")
  31.         end
  32.     end
  33.    
  34.     for i=1,offset-1 do
  35.         while not turtle.forward() do
  36.             print("blocked")
  37.         end
  38.     end
  39.    
  40.     for i=1,blockCount do
  41.         if consumed[blockCount+1-i]~=-1 then
  42.             turtle.select(consumed[blockCount+1-i])
  43.             turtle.place()
  44.         end
  45.        
  46.         while not turtle.back() do
  47.             print("blocked")
  48.         end
  49.     end
  50.    
  51.     for i=1,offset-1 do
  52.         while not turtle.back() do
  53.             print("blocked")
  54.         end
  55.     end
  56. end
  57.  
  58. if table.getn(args) ~= 4 then
  59.     print("arguments 'blockCount', 'offset', 'x' and 'y' expected")
  60. else
  61.     local blockCount=tonumber(args[1])
  62.     local offset=tonumber(args[2])
  63.     local X=tonumber(args[3])
  64.     local Y=tonumber(args[4])
  65.    
  66.     for y=1,Y do
  67.         for x=1,X do
  68.             placeForward(blockCount,offset)
  69.             if x~=X then
  70.                 turtle.turnRight()
  71.                 while not turtle.forward() do
  72.                     print("blocked")
  73.                 end
  74.                 turtle.turnLeft()
  75.             end
  76.         end
  77.         turtle.turnLeft()
  78.         for x=1,X-1 do
  79.             while not turtle.forward() do
  80.                 print("blocked")
  81.             end
  82.         end
  83.         turtle.turnRight()
  84.         if y~=Y then
  85.             while not turtle.up() do
  86.                 print("blocked")
  87.             end
  88.         end
  89.     end
  90.    
  91.     for y=1,Y-1 do
  92.         while not turtle.down() do
  93.             print("blocked")
  94.         end
  95.     end
  96.    
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement