Advertisement
agentsix1

Farmer

Jun 7th, 2023 (edited)
1,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.92 KB | None | 0 0
  1. local width  = 9
  2. local depth  = 20
  3. local chest_type = "ironchest:crystal_chest"
  4. local chest_size = 108
  5. local storage_slot_start = 4
  6. local planting = {
  7.                     {
  8.                     name = "minecraft:wheat_seeds",
  9.                     crop = "minecraft:wheat",
  10.                     slot = 2
  11.                     },
  12.                     {
  13.                     name = "minecraft:carrot",
  14.                     crop = "minecraft:carrots",
  15.                     slot = 3
  16.                     }
  17.                  }
  18. local planting_size = table.getn(planting)
  19.  
  20. local plants = {
  21.                     {
  22.                         name = "minecraft:potatoes",
  23.                         seed = "minecraft:potato",
  24.                         age  = 7
  25.                     },
  26.                     {
  27.                         name = "minecraft:wheat",
  28.                         seed = "minecraft:wheat_seeds",
  29.                         age  = 7
  30.                     },
  31.                     {
  32.                         name = "minecraft:carrots",
  33.                         seed = "minecraft:carrot",
  34.                         age  = 7
  35.                     },
  36.                     {
  37.                         name = "minecraft:beetroots",
  38.                         seed = "minecraft:beetroot_seeds",
  39.                         age  = 3
  40.                     },
  41.                     {
  42.                         name = "thermal:bell_pepper",
  43.                         seed = "thermal:bell_pepper_seeds",
  44.                         age  = 10
  45.                     },
  46.                     {
  47.                         name = "thermal:radish",
  48.                         seed = "thermal:radish_seeds",
  49.                         age  = 10
  50.                     },
  51.                     {
  52.                         name = "thermal:rice",
  53.                         seed = "thermal:rice_seeds",
  54.                         age  = 7
  55.                     },
  56.                     {
  57.                         name = "thermal:spinach",
  58.                         seed = "thermal:spinach_seeds",
  59.                         age  = 7
  60.                     },
  61.                     {
  62.                         name = "thermal:eggplant",
  63.                         seed = "thermal:eggplant_seeds",
  64.                         age  = 7
  65.                     }                  
  66.                    
  67.                    
  68.                }
  69. local plants_size = table.getn(plants)
  70.  
  71.  
  72. function fuel_check()
  73.     local fuelLevel = turtle.getFuelLevel()
  74.     if turtle.getItemCount(1) < 1 then
  75.         print("We are currently waiting to be refueled!")
  76.         local waiting = true
  77.         while waiting do
  78.             if turtle.getItemCount(1) > 0 then
  79.                 print("Thank you!")
  80.                 waiting = false
  81.                 sleep(1)
  82.             end
  83.         end
  84.     end
  85.     if fuelLevel < 100 then
  86.         turtle.select(1)
  87.         turtle.refuel(2)
  88.         print("Refueled.")
  89.     end
  90. end
  91.  
  92. function check_age()
  93.     local _, data = turtle.inspectDown()
  94.     for i = 1, plants_size do
  95.         local plant = plants[i]
  96.         if data.name == plant.name then
  97.             if plant.age == data.state.age then
  98.                 print("fully grown")
  99.                 return true
  100.             end
  101.         end
  102.     end
  103.     return false
  104. end
  105.  
  106. function get_plant()
  107. local _, data = turtle.inspectDown()
  108.     for i = 1, plants_size do
  109.         local plant = plants[i]
  110.         if data.name == plant.name then
  111.             return plant
  112.         end
  113.     end
  114.     return nil
  115. end
  116.  
  117. function select_seed(plant)
  118.     for i = 1, planting_size do
  119.         if planting[i].crop == plant.name then
  120.             turtle.select(planting[i].slot)
  121.         end
  122.     end
  123. end
  124.  
  125. function check_seeds()
  126.     for i = 1, planting_size do
  127.         local plant = planting[i]
  128.         local item = turtle.getItemDetail(plant.slot)
  129.         if item == nil then
  130.             print("You need to put atleast 1 " .. plant.name .. " in slot " .. plant.slot .. ".")
  131.             return false
  132.         end
  133.         if item.name ~= plant.name then
  134.             print("You need to put atleast 1 " .. plant.name .. " in slot " .. plant.slot .. ".")
  135.             return false
  136.         end
  137.     end
  138.     return true
  139. end
  140.  
  141. function empty_slots()
  142.     for i = storage_slot_start, 16 do
  143.         if turtle.getItemCount(i) > 0 then
  144.             turtle.select(i)
  145.             turtle.drop()
  146.         end
  147.     end
  148. end
  149.  
  150. function harvest_crop()
  151.     if check_age() then
  152.         local plant = get_plant()
  153.         select_seed(plant)
  154.         turtle.digDown()
  155.         turtle.placeDown()
  156.     end
  157. end
  158.  
  159. while true do
  160.     fuel_check()
  161.     if not check_seeds() then
  162.         return
  163.     end
  164.    
  165.     for w = 1, width do
  166.         if w ~= 1 then
  167.             fuel_check()
  168.             for d = 1, depth do
  169.                 turtle.back()
  170.             end
  171.             turtle.turnRight()
  172.             turtle.forward()
  173.             turtle.turnLeft()
  174.         end
  175.         for d = 1, depth do
  176.             harvest_crop()
  177.             fuel_check()
  178.             turtle.forward()
  179.         end
  180.         harvest_crop()
  181.     end
  182.     fuel_check()
  183.     for d = 1, depth do
  184.         turtle.back()
  185.     end
  186.     turtle.turnLeft()
  187.     fuel_check()
  188.     for w = 1, width-1 do
  189.         turtle.forward()
  190.     end
  191.     turtle.turnLeft()
  192.     empty_slots()
  193.     turtle.turnRight()
  194.     turtle.turnRight()
  195.     os.sleep(30)
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement