SHARE
TWEET

Untitled

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