Chaos_Cash

seedProducer.lua

Nov 10th, 2025 (edited)
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. local directions = {"north", "east", "south", "west"}
  2. local curDir = 1
  3.  
  4.  
  5.  
  6. local function getDir()
  7. local file = fs.open("curDir", "r")
  8.     if file then
  9.         local savedDir = file.readAll()
  10.         for k, dir in pairs(directions) do
  11.             if savedDir == dir then
  12.                 curDir = k
  13.             end
  14.         end
  15.     end
  16. end
  17.  
  18.  
  19.  
  20. local function turn(dir)
  21.     while directions[curDir] ~= dir do
  22.         if turtle.turnRight() then
  23.             curDir = curDir + 1
  24.             if curDir == 5 then
  25.                 curDir = 1
  26.             end
  27.            
  28.             local file = fs.open("curDir", "w")
  29.             file.write(directions[curDir])
  30.             file.flush()
  31.             file.close()
  32.             sleep(0.25)
  33.         end
  34.     end
  35. end
  36.  
  37.  
  38.  
  39. local function startup()
  40.     getDir()
  41. end
  42.  
  43.  
  44.  
  45. local function clearInventory()
  46.     turn("east")
  47.     for i = 1, 16 do
  48.         local item = turtle.getItemDetail(i)
  49.         if item then
  50.             if item.name ~= "minecraft:bone_meal" then
  51.                 turtle.select(i)
  52.                 turtle.drop()
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58.  
  59.  
  60. local function collectDrops()
  61.     repeat
  62.     until not turtle.suck()
  63. end
  64.  
  65.  
  66.  
  67. local function growPlant()
  68.     turn("north")
  69.     repeat
  70.     until not turtle.suckUp()
  71.    
  72.     local i2 = 0
  73.     for i = 1, 16 do
  74.         local item = turtle.getItemDetail(i)
  75.         if item then
  76.             if item.name == "minecraft:bone_meal" then
  77.                 turtle.select(i)
  78.                 repeat
  79.                     i2 = i2 + 1
  80.                     if i2 % 20 == 0 then
  81.                         collectDrops()
  82.                     end
  83.                 until not turtle.place()
  84.                 collectDrops()
  85.             end
  86.         end
  87.     end
  88. end
  89.  
  90.  
  91.  
  92. local function feedChicken()
  93.     turn("south")
  94.    
  95.     for i = 1, 16 do
  96.         local item = turtle.getItemDetail(i)
  97.         if item then
  98.             if item.name:match("chicken_food") then
  99.                 turtle.select(i)
  100.                 if not turtle.drop() then
  101.                     break
  102.                 end
  103.             end
  104.         end
  105.     end
  106. end
  107.  
  108.  
  109.  
  110. local function produceBoneMeal()
  111.     turn("south")
  112.    
  113.     local hasBones = false
  114.     for i = 1, 16 do
  115.         local item = turtle.getItemDetail(i)
  116.         if item then
  117.             if item.name == "minecraft:bone" then
  118.                 hasBones = true
  119.             end
  120.         end
  121.     end
  122.    
  123.     if not hasBones then
  124.         turtle.suck()
  125.     end
  126.    
  127.     for i = 1, 16 do
  128.         local item = turtle.getItemDetail(i)
  129.         if item then
  130.             if item.name == "minecraft:bone" then
  131.                 turtle.select(i)
  132.                 if not turtle.dropUp() then
  133.                     break
  134.                 end
  135.             end
  136.         end
  137.     end
  138. end
  139.  
  140.  
  141.  
  142. local function main()
  143.     while true do
  144.         feedChicken()
  145.         clearInventory()
  146.         growPlant()
  147.         produceBoneMeal()
  148.     end
  149. end
  150.  
  151.  
  152.  
  153. startup()
  154. main()
Advertisement
Add Comment
Please, Sign In to add comment