joshuaferr1s

farm.lua

Jun 9th, 2021 (edited)
733
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.   JoshCorp's Farm
  3.  
  4.   Usage: farm [width] [depth]
  5. ]]--
  6.  
  7. os.loadAPI("jcore")
  8.  
  9. local SEED = "minecraft:wheat_seeds"
  10. local CROP = "minecraft:wheat"
  11. local WAIT_TIME = 300
  12.  
  13. local width = 0
  14. local depth = 0
  15.  
  16. if #arg==2 then
  17.   width = tonumber(arg[1])
  18.   depth = tonumber(arg[2])
  19.  
  20.   if width<=1 then
  21.     print("[ERROR] Width must be larger than 1.")
  22.     return
  23.   end
  24.  
  25.   if depth<=1 then
  26.     print("[ERROR] Depth must be larger than 1.")
  27.     return
  28.   end
  29. else
  30.   print("[ERROR] Usage: farm [width] [depth]")
  31.   return
  32. end
  33.  
  34. local function farm()
  35.   local success, block = turtle.inspectDown()
  36.  
  37.   if success and block.state.age==7 then
  38.     turtle.digDown()
  39.     jcore.placeItemDown(SEED)
  40.   elseif success and block.name==CROP then
  41.    
  42.   else
  43.     if not jcore.placeItemDown(SEED) then
  44.       turtle.digDown()
  45.       jcore.placeItemDown(SEED)
  46.     end
  47.   end
  48. end
  49.  
  50. local function farmForward()
  51.   farm()
  52.   jcore.forward()
  53. end
  54.  
  55. jcore.checkItemCount(SEED, (width*depth)-1)
  56.  
  57. while true do
  58.   jcore.checkFuel((width*depth)+width+depth)
  59.  
  60.   for i=1, width do
  61.     for j=1, depth-1 do
  62.       farmForward()
  63.     end
  64.  
  65.     farm()
  66.  
  67.     if i%2==0 then
  68.       jcore.leftU()
  69.     else
  70.       jcore.rightU()
  71.     end
  72.   end
  73.  
  74.   jcore.returnHome2D(width, depth)
  75.  
  76.   jcore.depositInventory()
  77.   jcore.inventorySort()
  78.  
  79.   turtle.turnRight()
  80.   jcore.forward()
  81.  
  82.   sleep(WAIT_TIME)
  83. end
  84.  
RAW Paste Data