Advertisement
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 g = component.generator
- local inventory = component.inventory_controller
- local left = robot.turnLeft
- local right = robot.turnRight
- local TURN = robot.turnAround
- local d = robot.detect
- local dUp = robot.detectUp
- local dDown = robot.detectDown
- local side = sides.front
- local args = {...} -- ... gets the program's arguments somehow
- local rowsToDig1 = args[1] -- getting the first argument in the argument table
- local rowsToDig2 = args[2]
- local nRail_names = {}
- nRail_names[1] = "minecraft:rail"
- nRail_names[2] = "TConstruct:rail.wood"
- local Fuel_names = {}
- Fuel_names[1] = "minecraft:coal"
- Fuel_names[2] = "minecraft:planks"
- Fuel_names[3] = "minecraft:log"
- Fuel_names[4] = "minecraft:blaze_rod"
- Fuel_names[5] = "minecraft:lava_bucket"
- local trash_names = {}
- trash_names[1] = "minecraft:dirt"
- trash_names[2] = "minecraft:sand"
- trash_names[3] = "minecraft:cobblestone"
- trash_names[4] = "minecraft:gravel"
- trash_names[5] = "minecraft:gold_ore"
- trash_names[6] = "minecraft:iron_ore"
- trash_names[7] = "nevermine:oreLimonite"
- trash_names[8] = "minecraft:redstone"
- trash_names[10] = "nevermine:oreRosite"
- trash_names[11] = "minecraft:coal_ore"
- -- Functions for movements
- local function goUp()
- while dUp() do
- robot.swingUp()
- os.sleep(2)
- end
- robot.up()
- os.sleep(0.8)
- end
- local function goDown()
- while dDown() do
- robot.swingDown()
- os.sleep(2)
- end
- robot.down()
- os.sleep(0.8)
- end
- local function go()
- while d() do --- while robot.detect == true do
- robot.swing()
- os.sleep(2)
- end
- robot.forward()
- os.sleep(0.8)
- end
- -- Extra Functions to break blocks without moving, clear sand blocks or anormalies
- local function rSand()
- while d() do --- while robot.detect == true do
- robot.swing()
- os.sleep(2)
- end
- robot.turnAround()
- while d() do
- robot.swing()
- os.sleep(2)
- end
- end
- -- Place Blocks with Dev/ Null
- local function Bf()
- if not d() then
- robot.select(13)
- robot.place()
- end
- end
- local function Bd()
- if not dDown() then
- robot.select(13)
- robot.placeDown()
- end
- end
- local function Bu()
- if not dUp() then
- robot.select(13)
- robot.placeUp()
- end
- end
- -- Movement script
- local function Movement()
- Bd() ; go()
- Bd() ; left() ; go() ; Bf() ; Bd() ; TURN() ; go() ; go() ; Bd() ; Bf() ; goUp()
- Bf() ; TURN() ; go() ; go() ; Bf() ; goUp()
- Bf() ; Bu() ; TURN() ; go() ; Bu() ; go() ; Bf() ; Bu()
- TURN() ; go() ; goDown() ; goDown() ; rSand() ; left()
- end
- -- find rails
- local function findRail(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
- local function findTrash(stack_info)
- if stack_info == nil then
- return false
- end
- for index, known_trash_name in ipairs(trash_names) do
- if stack_info.name == known_trash_name then
- return true
- end
- end
- return false
- end
- -- get rails from a chest inventory
- local function getRail()
- local stack_info = inventory.getStackInInternalSlot(4)
- if findTrash(stack_info) then
- robot.select(4) ; robot.drop()
- end
- right() ; robot.select(5) ; robot.drop()
- robot.select(14) ; robot.place() ; robot.select(4)
- for slot=1,27 do
- local stack_info = inventory.getStackInSlot(side, slot)
- if findRail(stack_info) then
- print(stack_info.name, "I found rails in slot", slot, ". Restocking, please stand by!")
- inventory.suckFromSlot(sides.front, slot)
- break
- end
- end
- robot.select(5) ; inventory.dropIntoSlot(side, 1)
- robot.swing() ; robot.transferTo(14) ; left()
- end
- -- find usuable fuel materials
- local function findFuel(stack_info)
- if stack_info == nil then
- return false
- end
- for index, known_fuel_name in ipairs(Fuel_names) do
- if stack_info.name == known_fuel_name then
- return true
- end
- end
- return false
- end
- -- get 'fuel' from a chest inventory, if something was in the robot, it place it into a filter chest, and use the new fuel
- local function refuel()
- right() ; robot.select(14) ; robot.place() ; robot.select(16) ; robot.drop() ; robot.select(15)
- for slot=1,27 do
- local stack_info = inventory.getStackInSlot(side, slot)
- if findFuel(stack_info) then
- print(stack_info.name, "I found fuel in slot", slot, "Refueling, stand by!")
- inventory.suckFromSlot(sides.front, slot)
- break
- end
- end
- robot.select(14) ; robot.swing()
- robot.select(8) ; robot.place() ; robot.select(16) ; g.remove() ; inventory.dropIntoSlot(side, 1) ; robot.select(15) ; g.insert() ; os.sleep(20)
- robot.select(8) ; robot.swing()
- left()
- end
- -- place rails only if rails are presents in player slot:4
- local function placeRail()
- local stack_info = inventory.getStackInInternalSlot(4)
- if findRail(stack_info) then
- print("I'm placing a", stack_info.name, "there.")
- TURN() ; robot.select(4) ; robot.place() ; TURN() -- place rails
- end
- end
- -- Run the program for # defined during start-up, if less than 200 energy.. refuel, if less than 2 rails.. restock,
- -- place a rail behind the robot and dig a 3x3.
- local function digit()
- for i = 1, rowsToDig1 do
- if computer.energy() <= 200 then
- refuel() -- refuel duh?
- end
- if robot.count(4) <= 2 then
- getRail() -- restock on rails
- end
- placeRail()
- Movement() -- dig a tunnel
- end
- robot.turnLeft()
- for i = 1, rowsToDig2 do
- if computer.energy() <= 200 then
- refuel() -- refuel duh?
- end
- if robot.count(4) <= 2 then
- getRail() -- restock on rails
- end
- placeRail()
- Movement() -- dig a tunnel
- end
- end
- -- Call the program
- digit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement