Advertisement
Tag365

OpenComputers Robot block miner

Jun 2nd, 2017
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local robot = require("robot")
  2. local sides = require("sides")
  3. local component = require("component")
  4. local inventoryController = component.getPrimary("inventory_controller")
  5.  
  6. -- Gets the tool from the chest.
  7. local function GetTool()
  8.     robot.select(2)
  9.    
  10.     -- Get the first tool in the tool chest.
  11.     local foundTool = false
  12.     robot.turnLeft()
  13.     for chestSlot = 1, inventoryController.getInventorySize(sides.front) do
  14.         if inventoryController.suckFromSlot(sides.front, chestSlot) then
  15.             foundTool = true
  16.             break
  17.         end
  18.     end
  19.     robot.turnRight()
  20.    
  21.     -- Equip the tool.
  22.     inventoryController.equip()
  23.    
  24.     -- Reselect the first slot, containing the cobblestone or stone blocks.
  25.     robot.select(1)
  26.    
  27.     return foundTool
  28. end
  29.  
  30. -- Checks for a tool and if none exists then get tool from the chest
  31. local function CheckForTool()
  32.     -- Check if a tool is equipped and if not then get the tool from the chest.
  33.     if robot.durability() == nil then
  34.         return GetTool()
  35.     end
  36.     return true
  37. end
  38.  
  39. -- Checks if we can fill the chest with the block.
  40. local function AttemptToFillChest()
  41.     if robot.count(1) > 0 then
  42.         local success = false
  43.         robot.turnAround()
  44.         for chestSlot = 1, inventoryController.getInventorySize(sides.front) do
  45.             if inventoryController.dropIntoSlot(sides.front, chestSlot) then
  46.                 success = true
  47.                 break
  48.             end
  49.         end
  50.         robot.turnAround()
  51.         return success
  52.     end
  53.     return true
  54. end
  55.  
  56. while true do
  57.     -- Check if the first slot is full and if so then put the items in the block chest.
  58.     if AttemptToFillChest() then
  59.         -- Make sure the tool is equipped, and if so then
  60.         if CheckForTool() then
  61.             robot.swing()
  62.         end
  63.     end
  64.    
  65.    
  66.     -- Sleep
  67.     os.sleep(.1)
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement