Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local INVENTORY_SIZE = 16
  2. local FUEL_SLOT = 1
  3.  
  4. local function getNumberFromUser(message)
  5.     print(message)
  6.     local raw = io.read()
  7.     number = tonumber(raw)
  8.     return number
  9. end
  10.  
  11. local function getFirstSlotContainingBlocks()
  12.     for slot = 1, INVENTORY_SIZE do
  13.         local itemCount = turtle.getItemCount(slot)
  14.         if slot ~= FUEL_SLOT and itemCount > 0 then
  15.             return slot
  16.         end
  17.     end
  18.     return -1
  19. end
  20.  
  21. local function hasEnoughFuel()
  22.     return turtle.getFuelLevel() > 16
  23. end
  24.  
  25. local function checkFuel()
  26.     if not hasEnoughFuel() then
  27.         refuel()
  28.     end
  29. end
  30.  
  31. local function refuel()
  32.     turtle.select(FUEL_SLOT)
  33.     turtle.refuel(1)
  34. end
  35.  
  36. local function build(x, y)
  37.     for xProgress = 1, x do
  38.         for yProgress = 1, y do
  39.             checkFuel()
  40.             turtle.forward()
  41.             if (turtle.detectDown()) then
  42.                 -- clear the block so we can place a new one
  43.                 turtle.digDown()
  44.             end
  45.             local slot = getFirstSlotContainingBlocks()
  46.             if (slot == -1) then
  47.                 print("No buildable blocks")
  48.                 return
  49.             end
  50.             turtle.select(slot)
  51.             turtle.placeDown()
  52.         end
  53.         turtle.forward()
  54.         turtle.turnRight()
  55.         turtle.forward()
  56.         turtle.turnRight()
  57.     end
  58.     print("Done!")
  59. end
  60.  
  61. local function init()
  62.     local x = getNumberFromUser("How far straight should I build?")
  63.     local y = getNumberFromUser("How far right should I build?")
  64.     build(x, y)
  65. end
  66.  
  67. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement