Advertisement
TeoremaPi

Aplanar

Feb 24th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. -- 'flat' for turtles
  2. -- Made by ryanv09 (modified by TeoremaPi)
  3.  
  4. -- Place the turtle at southwest corner of desired surface
  5.  
  6. arg = {...}
  7.  
  8. length = arg[1]
  9. width = arg[2]
  10.  
  11.  
  12. -- This is the slot that is checked for blocks
  13. slots = 1
  14. -- This is the slot that is checked for fuel
  15. fuel  = 16
  16.  
  17.  
  18. -- Usage
  19. if (length == nil or width == nil) then
  20.   print ("Usage: flat <length> <width>")
  21.   return
  22. end
  23.  
  24.  
  25. -- Checks if the turtle is empty
  26. -- If empty, pauses turtle until last slot has resources
  27. function empty()
  28.     if (turtle.getItemCount(slots) == 0) then
  29.         for slot = 1, slots + 1, 1 do
  30.             if (turtle.getItemCount(slot) ~= 0 and slot < fuel) then
  31.                 slots = slot
  32.                 turtle.select(slots)
  33.                 break
  34.             end
  35.         end
  36.  
  37.         if (turtle.getItemCount(slots) == 0) then
  38.             slots = 1
  39.             print(string.format("I am empty. Please load more materials in slot %d to continue.", slots))
  40.         end
  41.  
  42.         while (turtle.getItemCount(slots) == 0) do
  43.             sleep(1)
  44.         end  
  45.     end
  46.  
  47.     if (turtle.getFuelLevel()<10) then
  48.         if (turtle.getItemCount(fuel) == 0) then
  49.             print(string.format("I am empty. Please load more fuel in slot %d to continue.", fuel))
  50.            
  51.             while (turtle.getItemCount(fuel) == 0) do
  52.                 sleep(1)
  53.             end
  54.         end
  55.  
  56.         turtle.select(fuel)
  57.         turtle.refuel()
  58.         turtle.select(slots)
  59.  
  60.     end
  61.    
  62. end
  63.  
  64.  
  65. function go()
  66.     while not turtle.forward() do
  67.         turtle.dig()
  68.     end
  69. end
  70.  
  71.  
  72. for i=0,(width - 1),1 do
  73.  
  74.   for j=1,(length - 1),1 do
  75.     empty()
  76.     go()
  77.     turtle.placeDown()
  78.   end
  79.  
  80.  
  81.   if (i % 2 == 0) then
  82.    
  83.     if (i ~= width - 1) then
  84.       turtle.turnRight()
  85.       go()
  86.       turtle.turnRight()
  87.       empty()  
  88.       turtle.placeDown()
  89.     end
  90.   else  
  91.     if (i ~= width - 1) then
  92.       turtle.turnLeft()
  93.       go()
  94.       turtle.turnLeft()
  95.       empty()
  96.       turtle.placeDown()
  97.     end
  98.   end
  99.  
  100.   if (j ~= length - 1) then
  101.     empty()
  102.     turtle.placeDown()
  103.   end
  104. end
  105.  
  106. print("\nSurface complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement