Advertisement
mike1928734

farm_crops

Jan 29th, 2023 (edited)
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. -- farm_crops
  2. -- pastebin run 36eK9aPm
  3.  
  4. os.loadAPI("/dorflib/api/dt")
  5. os.loadAPI("/dorflib/api/dtb")
  6.  
  7. function farm_crops()
  8.  
  9.     xcount = 1
  10.     zcount = 1
  11.  
  12.     xcont = true
  13.     zcont = true
  14.  
  15.     turtle.select(1)
  16.     turner = turtle.turnRight
  17.     print("starting")
  18.     while xcont do
  19.         print("xcount: ", xcount)
  20.         while zcont do
  21.             print("zcount: ", zcount)
  22.        
  23.             farm()
  24.        
  25.             if keep_going() then
  26.                 dt.fforward()
  27.                 zcount = zcount + 1
  28.             else
  29.                 zcont = false
  30.             end
  31.         end
  32.        
  33.         if (xcount % 2) == 1 then
  34.             turner = turtle.turnRight
  35.         else
  36.             turner = turtle.turnLeft
  37.         end
  38.        
  39.         turner()
  40.         if (keep_going) then
  41.             dt.fforward()
  42.             xcount = xcount + 1
  43.             zcont = true
  44.         else
  45.             xcont = false
  46.             zcont = false
  47.         end
  48.         turner()
  49.        
  50.     end
  51. end
  52.  
  53. function keep_going()
  54.    
  55.     sf, bf = turtle.inspect()
  56.     sd, bd = turtle.inspectDown()
  57.  
  58.     if (sf or (sd and (get_crop_age(bd.name) == 0))) then
  59.         print("keep_going: stop")
  60.         return false
  61.     else
  62.         print("keep_going: go")
  63.         return true
  64.     end
  65.  
  66. end
  67.  
  68.  
  69. function farm()
  70.     s, b = turtle.inspectDown()
  71.     if s then
  72.         name = b.name
  73.     else
  74.         name = ""
  75.     end
  76.    
  77.     crop_age = get_crop_age(name)
  78.     if (crop_age > 0) then
  79.         if (b.state.age == crop_age) then
  80.             dt.ddown()
  81.             dtb.splace(turtle.placeDown)
  82.         end
  83.     end
  84. end
  85.  
  86.  
  87. function get_crop_age(name)
  88.    
  89.     if (name == "minecraft:wheat") then
  90.         return 7
  91.     elseif (name == "minecraft:potato") then
  92.         return 7
  93.     else
  94.         return 0
  95.     end
  96. end
  97.  
  98.  
  99. args = {...}
  100.  
  101. if #args < 1 then
  102.     farm_crops()
  103. else
  104.     farm_crops()
  105. end
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement