Advertisement
fatboychummy

placeyboi.lua

Sep 21st, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local en = ... -- get input.  If there is any input, move down instead of up
  2. local et
  3.  
  4. -- find the first block in inventory, select it.
  5. local function find()
  6.   for i = 1, 16 do
  7.     if turtle.getItemCount(i) > 0 then
  8.       turtle.select(i)
  9.       return
  10.     end
  11.   end
  12.   -- if nothing found, error.
  13.   error("We have run out of items.", 0)
  14. end
  15.  
  16. -- make turtle.place/etc find the item before placing each time.
  17. function turtle.place()
  18.   find()
  19.   return turtle.native.place()
  20. end
  21.  
  22. function turtle.placeDown()
  23.   find()
  24.   return turtle.native.placeDown()
  25. end
  26.  
  27. function turtle.placeUp()
  28.   find()
  29.   return turtle.native.placeUp()
  30. end
  31.  
  32. -- if input, go down, else up
  33. if en then
  34.   en = turtle.down
  35.   et = turtle.placeUp
  36. else
  37.   en = turtle.up
  38.   et = turtle.placeDown
  39. end
  40.  
  41. local fails = 0
  42. while true do
  43.   turtle.place() -- place
  44.   if turtle.back() then
  45.     fails = 0 -- if we went back, reset fails to 0
  46.   else
  47.     turtle.turnRight() -- if we failed to move back, turn and increase fails
  48.     fails = fails + 1
  49.   end
  50.   if fails > 3 then
  51.     en() -- if we've turned 4 times, go up/down, then place a block there
  52.     et()
  53.     break
  54.   end
  55. end
  56.  
  57. -- reset turtle funcs
  58. turtle.place = turtle.native.place
  59. turtle.placeDown = turtle.native.placeDown
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement