Advertisement
Guest User

start.lua

a guest
Nov 22nd, 2020
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 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 AXE_NAME = "ThaumicTinkerer:ichorAxeGem"
  7. local HOE_NAME = "EMT:ElectricHoeGrowth"
  8. local SAPLING_NAME = "Forestry:sapling"
  9.  
  10. local function equipItem(name)
  11.     local emptySlot = 0
  12.     for i = 1, robot.inventorySize() do
  13.         if not inventory.getStackInInternalSlot(i) then
  14.             emptySlot = i
  15.             goto next
  16.         end
  17.     end
  18.  
  19.     :: next ::
  20.  
  21.     if emptySlot ~= 0 then
  22.         robot.select(emptySlot)
  23.         inventory.equip()
  24.     else
  25.         print("Can't find empty slot for sorting")
  26.         goto finish
  27.     end
  28.  
  29.     for i = 1, robot.inventorySize() do
  30.         local item = inventory.getStackInInternalSlot(i)
  31.         if item and item.name and item.name == name then
  32.             robot.select(i)
  33.             inventory.equip()
  34.             goto finish
  35.         end
  36.     end
  37.  
  38.     :: finish ::
  39. end
  40.  
  41. local function unload()
  42.  
  43.     robot.turnLeft()
  44.     local saplingsDetected = false
  45.     for i = 1, robot.inventorySize() do
  46.         local item = inventory.getStackInInternalSlot(i)
  47.         if item then
  48.             if item.name and item.name == AXE_NAME then
  49.                 goto continue
  50.             elseif item.name and item.name == HOE_NAME then
  51.                 goto continue
  52.             elseif item.label and item.name == SAPLING_NAME and saplingsDetected == false then
  53.                 saplingsDetected = true
  54.                 goto continue
  55.             else
  56.  
  57.                 robot.select(i)
  58.                 inventory.dropIntoSlot(sides.front, i)
  59.             end
  60.         end
  61.  
  62.         :: continue ::
  63.     end
  64.  
  65.     robot.turnRight()
  66. end
  67.  
  68. local function charge()
  69.  
  70.     local hoeSlot = -1
  71.     for i = 1, robot.inventorySize() do
  72.         local item = inventory.getStackInInternalSlot(i)
  73.         if item and item.name and item.name == HOE_NAME and item.charge and item.charge <= 2000 then
  74.             hoeSlot = i
  75.             goto charge
  76.         end
  77.     end
  78.  
  79.     :: charge ::
  80.  
  81.     if hoeSlot ~= -1 then
  82.         robot.turnRight()
  83.  
  84.         print("hoe charging started")
  85.         robot.select(hoeSlot)
  86.         inventory.dropIntoSlot(sides.front, 1)
  87.         os.sleep(15)
  88.         inventory.suckFromSlot(sides.front, 1)
  89.         print("hoe charging finished")
  90.  
  91.         robot.turnLeft()
  92.     end
  93.  
  94. end
  95.  
  96. local function safeMovement(func)
  97.     local result, reason = func()
  98.     while not result do
  99.         print(result, result)
  100.         result, reason = func()
  101.     end
  102. end
  103.  
  104. local function plantSapling()
  105.     equipItem(SAPLING_NAME)
  106.  
  107.     safeMovement(robot.up)
  108.     safeMovement(robot.forward)
  109.     robot.useDown()
  110.     safeMovement(robot.back)
  111.     safeMovement(robot.down)
  112.     print("=========================")
  113. end
  114.  
  115. local function growSapling()
  116.     equipItem(HOE_NAME)
  117.  
  118.     for i = 1, 10 do
  119.         robot.use(sides.front)
  120.         os.sleep(0.2)
  121.     end
  122. end
  123.  
  124. local function chopSapling()
  125.     equipItem(AXE_NAME)
  126.  
  127.     robot.swing()
  128.     os.sleep(0.2)
  129. end
  130.  
  131. local function suckItems()
  132.     os.sleep(10)
  133.     robot.suck()
  134.     robot.suckUp()
  135. end
  136.  
  137. while true do
  138.     unload()
  139.     charge()
  140.     plantSapling()
  141.     growSapling()
  142.     chopSapling()
  143.     suckItems()
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement