Advertisement
fatboychummy

spinFarm.lua

Aug 25th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. local farmItem, farmBlock, maxMeta = ...
  2. maxMeta = tonumber(maxMeta) or 7
  3.  
  4. if farmItem == "help" then
  5.   print("Usage: <filename> <seedName> <blockName> [maxGrowth(default:7)]")
  6. end
  7.  
  8. farmItem = type(farmItem) == "string" and farmItem
  9.   or error("Bad argument #1: Expected a string")
  10. farmBlock = type(farmBlock) == "string" and farmBlock
  11.   or error("Bad argument #2: Expected a string")
  12.  
  13. local function find()
  14.   for i = 1, 16 do
  15.     if turtle.getItemCount(i) > 0
  16.         and (turtle.getItemDetail(i)).name == farmItem then
  17.       turtle.select(i)
  18.       return
  19.     end
  20.   end
  21.   error("Cannot place anything")
  22. end
  23.  
  24. local oldplc = turtle.place
  25. function turtle.place()
  26.   find()
  27.   return oldplc()
  28. end
  29.  
  30. local olddig = turtle.dig
  31. function turtle.dig()
  32.   local isBlock, block = turtle.inspect()
  33.   if isBlock then
  34.     if block.name == farmBlock and block.metadata >= maxMeta then
  35.       return olddig()
  36.     end
  37.     return false
  38.   end
  39.   return true
  40. end
  41.  
  42. while true do
  43.   print("START LOOP")
  44.   for i = 1, 4 do
  45.     print("CHECKING " .. tostring(i))
  46.     if turtle.dig() then
  47.       print("IT IS SO, WE PLACE.")
  48.       turtle.place()
  49.     end
  50.     print("RIGHT WE GO")
  51.     turtle.turnRight()
  52.   end
  53.   print("WE HAVE DONE THIS LOOP, LET US WAIT SOME TIME.")
  54.   os.sleep(10)
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement