Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local computer = require("computer")
- local sides = require("sides")
- local component = require("component")
- local ser = require("serialization")
- local c = component.crafting
- local inventory = component.inventory_controller
- local g = component.generator
- local size = inventory.getInventorySize(sides.front)
- local passable, state = robot.detect() -- return values for robot.detect()
- local nRail_names = {}
- nRail_names[1] = "minecraft:rail"
- nRail_names[2] = "TConstruct:rail.wood"
- local args = {...} -- ... gets the program's arguments somehow
- local rowsToDig = args[1] -- getting the first argument in the argument table
- local function isnRail(stack_info)
- if stack_info == nil then
- return false
- end
- for index, known_rail_name in ipairs(nRail_names) do
- if stack_info.name == known_rail_name then
- return true
- end
- end
- return false
- end
- for slot=1, size do
- local stack_info = inventory.getStackInSlot(sides.front, slot)
- --- inspect the stack_info when it is not nil
- if isnRail(stack_info) then
- print(stack_info.name, "found in slot", slot)
- inventory.suckFromSlot(sides.front, slot)
- break
- end
- end
- local function checkEnergy()
- if computer.energy() <= 200 then
- robot.select(15)
- g.insert()
- robot.select(2)
- robot.drop()
- robot.select(3)
- robot.drop()
- robot.select(5)
- robot.drop()
- robot.select(6)
- robot.drop()
- robot.select(7)
- robot.drop()
- robot.select(9)
- robot.drop()
- robot.select(10)
- robot.drop()
- robot.select(11)
- robot.drop()
- robot.select(14)
- robot.turnLeft()
- robot.place()
- robot.select(15)
- inventory.suckFromSlot(3, 1)
- g.insert()
- inventory.suckFromSlot(3, 1)
- robot.swing()
- robot.select(2)
- robot.transferTo(14)
- os.sleep(20)
- robot.turnRight()
- os.sleep(60)
- end
- end
- local function placeRails()
- robot.select(4)
- if robot.count() <=2 then
- robot.select(15)
- robot.turnRight()
- robot.place()
- robot.select(2)
- robot.drop()
- robot.select(3)
- robot.drop()
- robot.select(5)
- robot.drop()
- robot.select(6)
- robot.drop()
- robot.select(7)
- robot.drop()
- robot.select(8)
- robot.drop()
- robot.select(9)
- robot.drop()
- robot.select(10)
- robot.drop()
- robot.select(11)
- robot.drop()
- robot.select(4)
- isnRail(stack_info)
- robot.select(5)
- inventory.dropIntoSlot(side.front, 1)
- robot.select(2)
- robot.swing()
- robot.transferTo(15)
- robot.select(4)
- robot.turnLeft()
- end
- end
- robot.turnAround()
- robot.place()
- robot.turnAround()
- --[[local function checkTool()
- if not robot.durability(0.2) and robot.count(1) <= 0 then
- robot.select(2)
- robot.drop()
- robot.select(3)
- robot.drop()
- robot.select(4)
- robot.drop()
- robot.select(5)
- robot.drop()
- robot.select(6)
- robot.drop()
- robot.select(7)
- robot.drop()
- robot.select(8)
- robot.drop()
- robot.select(9)
- robot.drop()
- robot.select(10)
- robot.drop()
- robot.select(11)
- robot.drop()
- robot.select(17)
- robot.transferTo(2)
- c.craft(1)
- robot.select(2)
- robot.transferTo(17)
- end
- end --]]
- local function digHollow3x3()
- for i = 1, rowsToDig do
- checkEnergy()
- -- checkTool()
- robot.detectDown()
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.placeDown()
- end
- placeRails()
- robot.detect()
- if state == "solid" then robot.swing() -- swing at block 2
- -- checkTool()
- end
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward()
- robot.turnLeft() -- face left
- robot.detect() -- check for solid block
- if state == "solid" then robot.swing() -- swing at block 1
- end
- -- checkTool()
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward() -- moving forward under block 4
- robot.detectDown() -- detect under block 1
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.placeDown()
- end
- robot.detect() -- detect left side of block 1
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.place()
- end
- robot.turnAround() -- face right
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward() -- moving forward under block 5
- robot.detect()
- if state == "solid" then robot.swing()-- swing at block 3
- end
- -- checkTool()
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward() -- moving forward under block 6
- robot.detect() -- detect right side of block 3
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.place()
- end
- robot.detectDown() -- detect under block block 3
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.place()
- end
- robot.detectUp()
- if state == "solid" then robot.swingUp()-- swing at block 6
- end
- -- checkTool()
- repeat
- robot.detectUp()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.up() -- moving up under block 9
- robot.detect() -- detect block right of block 6
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.place()
- end
- robot.turnAround() -- face left
- robot.detect()
- if state == "solid" then robot.swing() -- swing at block 5
- end
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward() -- moving forward under block 8
- robot.detect()
- if state == "solid" then robot.swing() -- swing at block 4
- end
- -- checkTool()
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward() -- moving forward under block 7
- robot.detect() -- detect block at right of block 4
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.place()
- end
- robot.detectUp()
- if state == "solid" then robot.swingUp() -- swing at block 7
- checkTool()
- end
- repeat
- robot.detectUp()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.up() -- moving up at block 7 position
- robot.detect() -- detect block on left side of block 7
- if state == "liquid" or "air" then robot.select(13) -- dev/ null
- robot.place()
- end
- robot.detectUp() -- detect block above block 7
- if state == "liquid" or "air" then robot.select(13) -- dev/null
- robot.placeUp()
- end
- robot.turnAround() -- face right
- robot.detect()
- if state == "solid" then robot.swing() -- swing at block 8
- -- checkTool()
- end
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward() -- moving forward at block 8 position
- robot.detectUp() -- detect block above block 8
- if state == "liquid" or "air" then robot.select(13)
- robot.placeUp()
- end
- robot.detect()
- if state == "solid" then robot.swing()
- end
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward() -- moving forward at block 9 position
- robot.detectUp() -- detect block above block 9
- if state == "liquid" or "air" then robot.select(13)
- robot.placeUp()
- end
- robot.detect() -- detect block on the right of block 9
- if state == "liquid" or "air" then robot.select(13)
- robot.place()
- end
- robot.turnAround()
- repeat
- robot.detect()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.forward()
- robot.turnRight() -- face toward next layer
- repeat
- robot.detectDown()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.down()
- repeat
- robot.detectDown()
- if state == "solid" then robot.swing()
- end
- until state == "liquid" or "air"
- robot.down()
- end
- end
- digHollow3x3()
Add Comment
Please, Sign In to add comment