Advertisement
VasVadum

FloorMaker

Dec 10th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Turtle will move forward and to the right.
  2. -- Turtle will build below itself.
  3.  
  4. arg = {...}
  5.  
  6. length = tonumber(arg[1])
  7. width = tonumber(arg[2])
  8.  
  9. currentSlot = 1
  10. processMore = true
  11.  
  12. -- Usage
  13. if (length == nil or width == nil) then
  14.     print ("Usage: Program <length> <width>")
  15.     print ("Length = Blocks forward.")
  16.     print ("Width = Blocks to the right.")
  17.     return
  18. end
  19.  
  20. -- Checks if the turtle slot is empty
  21. -- Going from slot to 16 wrapping (1 - 16)
  22. function slotEmpty()
  23.     for i=0,16,1 do
  24.         newSlot = ((currentSlot + i) % 16) + 1
  25.         if (turtle.getItemCount(newSlot) ~= 0) then
  26.             currentSlot = newSlot
  27.             turtle.select(newSlot)
  28.             print("\nFound a block at ".. newSlot .. " carry on")
  29.             return true
  30.         end
  31.     end
  32.     print("\nI've run out of blocks, I will wait for more.")
  33.     return false
  34. end
  35.  
  36. for i=0,(width - 1),1 do
  37.     for j=1,(length - 1),1 do
  38.         processMore = slotEmpty()
  39.         if processMore then
  40.             turtle.forward()
  41.             turtle.placeDown()
  42.         end
  43.     end
  44.  
  45.     if not processMore then
  46.         print("I have run out of blocks to place, I will wait for more.")
  47.         break
  48.     end
  49.    
  50.     if (i % 2 == 0) then
  51.         if (i ~= width - 1) then
  52.             turtle.turnRight()
  53.             turtle.forward()
  54.             turtle.turnRight()
  55.         end
  56.     else   
  57.         if (i ~= width - 1) then
  58.             turtle.turnLeft()
  59.             turtle.forward()
  60.             turtle.turnLeft()
  61.         end
  62.     end
  63.  
  64.     -- See if we have an item in any slot, if we do, then place it
  65.     -- if we don't have any items, then we break out of the loop, cause we're done
  66.     processMore = slotEmpty()
  67.     if processMore then
  68.         turtle.placeDown()
  69.     else
  70.         break
  71.     end
  72. end
  73.  
  74. print("\nMy programming indicates that the floor is completed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement