Advertisement
civilwargeeky

floorMaker.lua

May 19th, 2015
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. --Floor/Ceiling Maker
  2. --Made by Civilwargeeky
  3. --Version 1.0.0
  4.  
  5. local tArgs = {...}
  6. s = (tArgs[1] or ""):lower():sub(1,1)
  7. p = (tArgs[2] or ""):lower():sub(1,1)
  8. if #tArgs < 2 then --Print help
  9.   print("Usage: floorMaker <left/right> <up/down> [x dist] [z dist]")
  10.   print()
  11.   print("left/right is turn direction at end of first row")
  12.   print("up/down places blocks above or below the turtle")
  13.   error("",0)
  14. end
  15. local dir, func = (s == "r" and "right") or "left"
  16. local placeDir = (p == "u" and "up") or "down"
  17. local xDist = tonumber(tArgs[3]) --Want it to be nil if not there
  18. if xDist then xDist = math.abs(math.floor(xDist))-1 end
  19. local zDist = tonumber(tArgs[4])
  20. if zDist then zDist = math.abs(math.floor(zDist)) end
  21. local rows = 0
  22. placeFunc = placeDir == "up" and turtle.placeUp or turtle.placeDown
  23.  
  24. local function change()
  25.   if dir == "left" then
  26.     dir = "right"
  27.     func = turtle.turnRight
  28.   else
  29.     dir = "left"
  30.     func = turtle.turnLeft
  31.   end
  32. end
  33. change() --Assigns func, need default
  34. change()
  35.  
  36. local slot = 1
  37. turtle.select(slot)
  38. local function place()
  39.   if turtle.getItemCount(slot) == 0 then
  40.     repeat --Scanning inventory for blocks
  41.      slot = slot + 1
  42.      turtle.select(slot)
  43.     until turtle.getItemCount(slot) > 0 or (slot >= 16 or error("No blocks"))
  44.   end
  45.   placeFunc()
  46. end
  47.  
  48. local function go()
  49.   term.clear()
  50.   term.setCursorPos(1,1)
  51.   print("Dir:      ",dir)
  52.   print("PlaceDir: ",placeDir)
  53.   print("Distance: ",xDist+1)
  54.   print()
  55.   print("On row:   ",rows)
  56.   print("Rows:     ",zDist)
  57.   while not turtle.forward() do
  58.     if not turtle.detect() then
  59.       turtle.attack()
  60.     else
  61.       return false
  62.     end
  63.   end
  64.   return true
  65. end
  66.  
  67. while rows <= (zDist or math.huge) do
  68.   rows = rows + 1
  69.   if not xDist then --Initial behavior
  70.     xDist = -1
  71.     repeat --First row check
  72.       place()
  73.       xDist = xDist + 1
  74.     until not go()
  75.   else --Normally. Allow this in loop so user can specify a distance
  76.     for i=1, xDist do
  77.       place()
  78.       go()
  79.     end
  80.   end
  81.   place()
  82.   func()
  83.   if rows == zDist or not go() then
  84.     break --We have hit the other wall
  85.   end
  86.   func()
  87.   change()
  88. end
  89.  
  90. print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement