SHARE
TWEET

floor.lua

neo34rd Mar 24th, 2019 (edited) 170 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2. if #tArgs ~= 2 then
  3.   print("Requires width, length")
  4.   return
  5. end
  6.  
  7. local x = tonumber(tArgs[1]) - 1
  8. local y = tonumber(tArgs[2])
  9.  
  10. if x == nil or y == nil then
  11.   print("Invalid dimensions")
  12.   return
  13. end
  14.  
  15. if x < 0 or y < 0 then
  16.   print("Invalid (negative) dimensions")
  17.   return
  18. end
  19.  
  20. --- Load API
  21. os.loadAPI("move")
  22. os.loadAPI("inventory")
  23. os.loadAPI("transformation")
  24.  
  25. t = transformation.newTransform()
  26.  
  27. function enoughFuel(width, length)
  28.   total = width * length
  29.   if total >= turtle.getFuelLevel() then
  30.     print("Not enough fuel for floor size!")
  31.     print(turtle.getFuelLevel(), " level but requires ", total, " fuel!")
  32.     return false
  33.   end
  34.   return true
  35. end
  36.  
  37. if not enoughFuel(x, y) then
  38.     return
  39. end
  40.  
  41. --- Place any item below
  42. --- Returns true if successfully places and item below
  43. --- False otherwise
  44. function tryPlaceAnyDown()
  45.     local b = inventory.trySelectAnyFirst()
  46.     if not b then
  47.         print("No items for selection!")
  48.         return false
  49.     end
  50.     sleep(0.01)
  51.     b = turtle.placeDown()
  52.     if not b then
  53.         print("Cannot place down here!")
  54.         return false
  55.     end
  56.     return true
  57. end
  58.  
  59. --- Build the floor
  60. transformation.forward(t)
  61. local b = move.rectMotionDoWhile(t, x, y, tryPlaceAnyDown)
  62. if b == true then
  63.     print("Success!")
  64. elseif b == false then
  65.     print("Failure!")
  66. else
  67.     print("undefined!")
  68. end
  69.  
  70. transformation.gotoPosition(t, vector.makeZero())
  71.  
  72. print("Fuel remaining:")
  73. print(turtle.getFuelLevel());
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top