Xgamer911

flooring

Sep 1st, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. -- This program will build a flat layer of blocks of,
  2. -- the specified length and width, the floors width will be
  3. -- expanded to the right.
  4. -- Original code from: http://www.hernblog.com/ian/floor.lua
  5. -- Modified for turtle movement and refueling by XGamer911
  6. -- Place fuel in slot 16
  7.  
  8. -- Usage: floor.lua length width.
  9.  
  10. params = {...}
  11. -- The input is text so we convert the text to a number.
  12. floorLength = tonumber(params[1])
  13. floorWidth = tonumber(params[2])
  14.  
  15. currentSlot = 1
  16.  
  17. -- This variable is used to alternate which way we are turning.
  18. turnRight = true
  19.  
  20. function gotoNextSlotIfEmpty()
  21. if turtle.getItemCount(currentSlot) == 0 then
  22. currentSlot = currentSlot + 1
  23. turtle.select(currentSlot)
  24. end
  25. end
  26.  
  27. function refuel()
  28. fuel = turtle.getFuelLevel()
  29. if fuel < 5 then
  30. turtle.select(16)
  31. turtle.refuel(1)
  32. turtle.select(currentSlot)
  33. end
  34. end
  35.  
  36. turtle.select(currentSlot)
  37. -- turtle.up()
  38.  
  39. for width = 1, floorWidth do
  40.  
  41. for length = 1, floorLength do
  42.  
  43. refuel()
  44. turtle.placeDown()
  45. gotoNextSlotIfEmpty()
  46. if length ~= floorLength then
  47. turtle.forward()
  48. end
  49.  
  50. end
  51.  
  52. -- When you get to the end of a row of blocks you need to turn around and setup for the next row,
  53. -- but every time you turn around you need to alternate the way that you turn.
  54. -- If this is confusing try drawing it out on a peice of paper.
  55. if turnRight then
  56. turtle.turnRight()
  57. turtle.forward()
  58. turtle.turnRight()
  59. else
  60. turtle.turnLeft()
  61. turtle.forward()
  62. turtle.turnLeft()
  63. end
  64.  
  65. -- Change so that we turn the other way next time.
  66. turnRight = not turnRight
  67. end
Advertisement
Add Comment
Please, Sign In to add comment