FERROUSSAGE

farm seed robot

Aug 24th, 2021 (edited)
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. local robot = require("robot")
  2. local component = require("component")
  3. local sides = require("sides")
  4. local inventory = component.inventory_controller
  5.  
  6. local HOE_NAME = "EMT:ElectricHoeGrowth"
  7. local SEED_NAME = "minecraft:wheat_seeds"
  8.  
  9. local function equipItem(nameItem)
  10.     if nameItem ~= nil then
  11.         for i = 1, robot.inventorySize() do
  12.             local item = inventory.getStackInInternalSlot(i)
  13.             if item and item.name and item.name == nameItem then
  14.                 robot.select(i)
  15.                 inventory.equip()
  16.             end
  17.         end
  18.     else
  19.         robot.select(1)
  20.     end
  21. end
  22.  
  23. local function charge(indexItem)
  24.     robot.turnAround()
  25.     robot.select(indexItem)
  26.  
  27.     if(inventory.dropIntoSlot(sides.front, 1)) then
  28.         print("charging electro item started")
  29.         os.sleep(5)
  30.         if(inventory.suckFromSlot(sides.front, 1)) then
  31.             print("charging electro item finished")
  32.             robot.turnAround()
  33.         end
  34.     end
  35. end
  36.  
  37. local function findChargeItem(itemName)
  38.     for i = 1, robot.inventorySize() do
  39.         local item = inventory.getStackInInternalSlot(i)
  40.         if item and item.name and item.name == itemName and item.charge <= 2000 then
  41.             return charge(i)
  42.         end
  43.     end
  44. end
  45.  
  46. local function plantSeed()
  47.     equipItem(SEED_NAME)
  48.     print("plant seed")
  49.     os.sleep(0.1)
  50.  
  51.     robot.use()
  52.  
  53.     os.sleep(0.1)
  54. end
  55.  
  56. local function growSeed()
  57.     findChargeItem(HOE_NAME)
  58.  
  59.     equipItem(HOE_NAME)
  60.     print("growth seed")
  61.  
  62.     os.sleep(0.1)
  63.     for i = 1, 4 do
  64.         robot.use()
  65.     end
  66.     os.sleep(0.1)
  67. end
  68.  
  69. local function destroyWheat()
  70.     print("destroy wheat")
  71.     os.sleep(0.1)
  72.     robot.swing()
  73.     os.sleep(0.1)
  74. end
  75.  
  76. local function dropItems()
  77.     os.sleep(0.1)
  78.  
  79.     local activeSeed = false
  80.  
  81.     robot.turnRight()
  82.     print("drop items")
  83.  
  84.     for i = 1, robot.inventorySize() do
  85.         local item = inventory.getStackInInternalSlot(i)
  86.         if item then
  87.             if item.name and item.name == HOE_NAME then
  88.                 goto continue
  89.             elseif item.label and item.name == SEED_NAME and activeSeed == false then
  90.                 activeSeed = true
  91.                 goto continue
  92.             else
  93.                 for j = i, 20 do
  94.                     robot.select(i)
  95.                     inventory.dropIntoSlot(3, 1)
  96.                 end
  97.             end
  98.         end
  99.  
  100.         :: continue ::
  101.     end
  102.     robot.turnLeft()
  103. end
  104.  
  105. while true do
  106.     plantSeed()
  107.     growSeed()
  108.     destroyWheat()
  109.     dropItems()
  110. end
Advertisement
Add Comment
Please, Sign In to add comment