Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local component = require("component")
- local currentSlot = 1
- local maxSlot = robot.inventorySize()
- local enableIC = component.isAvailable("inventory_controller")
- local itemName = 'ignore'
- function getItemName(slot)
- if not enableIC then
- return ''
- end
- local item = component.inventory_controller.getStackInInternalSlot(slot)
- if item then
- return item.name
- else
- return ''
- end
- end
- function up()
- local can, type = robot.detectUp()
- if can then
- robot.swingUp()
- up()
- else
- robot.up()
- end
- end
- function down()
- local can, type = robot.detectDown()
- if can then
- robot.swingDown()
- down()
- else
- robot.down()
- end
- end
- function forward()
- local can, type = robot.detect()
- if can then
- robot.swing()
- forward()
- else
- robot.forward()
- end
- end
- function findItem()
- for s = 1, maxSlot, 1 do
- if getItemName(s) ~= '' then
- return s
- end
- end
- return 0
- end
- function checkSlot()
- local newItemName = getItemName(currentSlot)
- if newItemName ~= '' then
- robot.select(currentSlot)
- return true
- else
- currentSlot = findItem()
- if currentSlot ~= 0 then
- robot.select(currentSlot)
- return true
- end
- return false
- end
- end
- function placeDown()
- local can, type = robot.detectDown()
- if can then
- robot.swingDown()
- placeDown()
- else
- if itemName ~= '' then
- if checkSlot() then
- robot.placeDown()
- end
- end
- end
- end
- function placeUp()
- local can, type = robot.detectUp()
- if can then
- robot.swingUp()
- placeUp()
- else
- if itemName ~= '' then
- if checkSlot() then
- robot.placeUp()
- end
- end
- end
- end
- function place()
- local can, type = robot.detect()
- if can then
- robot.swing()
- place()
- else
- if itemName ~= '' then
- if checkSlot() then
- robot.place()
- end
- end
- end
- end
- function dig()
- forward()
- placeDown()
- robot.turnLeft()
- place()
- up()
- place()
- up()
- place()
- up()
- place()
- placeUp()
- robot.turnLeft()
- robot.turnLeft()
- place()
- down()
- place()
- down()
- place()
- down()
- place()
- robot.turnLeft()
- end
- function main()
- while true do
- dig()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement