Advertisement
sanderronde

floorbot.lua

Jan 5th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. local args = { ... }
  2. local size = args[1]
  3.  
  4. local function is_stone_below()
  5.     local success, data = turtle.inspect()
  6.     if not success then
  7.         return false
  8.     end
  9.     if data.name == "minecraft:stone" then
  10.         return true
  11.     end
  12.     return false
  13. end
  14.  
  15. local function find_stone()
  16.     for s = 1, 16 do
  17.         turtle.select(s)
  18.         if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:stone" then
  19.             return true
  20.         end
  21.     end
  22.     return false
  23. end
  24.  
  25. local function select_stone()
  26.     while true do
  27.         if find_stone() then
  28.             return
  29.         end
  30.         os.pullEvent('turtle_inventory')
  31.     end
  32. end
  33.  
  34. local function do_replace()
  35.     if is_stone_below() then
  36.         return
  37.     end
  38.     -- Not stone
  39.     turtle.digDown()
  40.     turtle.placeDown()
  41. end
  42.  
  43. local function check_fuel(amount)
  44.     if not amount then
  45.         amount = 1
  46.     end
  47.     if turtle.getFuelLevel() < amount then
  48.         while true do
  49.             if turtle.refuel() then
  50.                 return
  51.             end
  52.             os.pullEvent('turtle_inventory')
  53.         end
  54.     end
  55. end
  56.  
  57. local orientation_fw = true
  58.  
  59. local function init()
  60.     for x = 0, size do
  61.         for z = 0, size do
  62.             check_fuel(1)
  63.             do_replace()
  64.             turtle.forward()
  65.         end
  66.  
  67.         if orientation_fw then
  68.             turtle.turnRight()
  69.             turtle.forward()
  70.             turtle.turnRight()
  71.             orientation_fw = false
  72.         else
  73.             turtle.turnLeft()
  74.             turtle.forward()
  75.             turtle.turnLeft()
  76.             orientation_fw = true
  77.         end
  78.     end
  79. end
  80.  
  81. if not size then
  82.     print("Missing args")
  83. else
  84.     init()
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement