Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local sides = require("sides")
- local component = require("component")
- local inventoryController = component.getPrimary("inventory_controller")
- -- Gets the tool from the chest.
- local function GetTool()
- robot.select(2)
- -- Get the first tool in the tool chest.
- local foundTool = false
- robot.turnLeft()
- for chestSlot = 1, inventoryController.getInventorySize(sides.front) do
- if inventoryController.suckFromSlot(sides.front, chestSlot) then
- foundTool = true
- break
- end
- end
- robot.turnRight()
- -- Equip the tool.
- inventoryController.equip()
- -- Reselect the first slot, containing the cobblestone or stone blocks.
- robot.select(1)
- return foundTool
- end
- -- Checks for a tool and if none exists then get tool from the chest
- local function CheckForTool()
- -- Check if a tool is equipped and if not then get the tool from the chest.
- if robot.durability() == nil then
- return GetTool()
- end
- return true
- end
- -- Checks if we can fill the chest with the block.
- local function AttemptToFillChest()
- if robot.count(1) > 0 then
- local success = false
- robot.turnAround()
- for chestSlot = 1, inventoryController.getInventorySize(sides.front) do
- if inventoryController.dropIntoSlot(sides.front, chestSlot) then
- success = true
- break
- end
- end
- robot.turnAround()
- return success
- end
- return true
- end
- while true do
- -- Check if the first slot is full and if so then put the items in the block chest.
- if AttemptToFillChest() then
- -- Make sure the tool is equipped, and if so then
- if CheckForTool() then
- robot.swing()
- end
- end
- -- Sleep
- os.sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement