Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Made by Murlocking for Minecraft 1.7.0 and Opencomputers
- Robot Program to dig a 3x3 tunnel and place rail tracks
- Requirements: Robot: Computer Tier 3, Inventory Upgrade, Inventory Controller, Hover Upgrade, Angel Upgrade,
- Inventory Controller, Disk Drive to copy program to the robot, Generator
- To use the robot, equip a pickaxe in the 'tool' slot, in slot 1: put an Ender Chest with light source blocks
- listed under 'Light_names', in slot 2: any light source blocks from 'Light_names',
- in slot 4: add normal rails listed under 'nRail_names', keep slot 5 empty, in slot 6: powered rails,
- in slot 7: redstone block, in slot 8: a different Ender Chest to return fuel(mainly empty buckets),
- in slot 9: place your building materials (Mat_names), keep slot 10&11 empty, in slot 12:
- place a different Ender Chest with your building materials in it, in slot 14: place a different
- Ender Chest with your fuels and normal rails (nRail_names / Fuel_names), keep slot 15&16 empty.
- Place the robot facing a direction where you want it to dig, leave on the side of the robot,
- for restocking and also leave an empty space behind the robot.
- Make sure there's a block below the 'air' block behind the robot so it can place a rail on it.
- Run the program like so 'programName X Y Z' where ;
- X = number of rows to dig in the direction the robot face,
- Y = the number of rows to dig after completing X,
- Z = direction the robot turn after completing X (can be left or right).
- If you don't specify Y or Z arguments, the robot will error out after digging X rows.
- Robot will automatically restock on materials and place rails, it will also occasionally
- place powered rails (15 block) and light source (7 blocks).
- It's recommended to equip your best mining tool or monitor the robot tool if you are early game.
- I used a Tinker Construct Pickaxe that was almost indestructible. You might need to change the program
- adjust to that, here's a few ideas :
- 1. Repair tool from Tinker Tool using robot inventory and crafting upgrade,
- use stone tool and add a chest to slot 13 to store your items before crafting.
- 2. Unbreakable Tool
- 3. Auto-Repair Tool and long os.sleep period.
- 4. Chest in slot 13 with new tools to replace broken one.
- --]]
- 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 = {...}
- local rowsToDig1 = args[1]
- local rowsToDig2 = args[2]
- local direction = string.upper(args[3])
- 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[9] = "nevermine:oreRosite"
- trash_names[10] = "minecraft:coal_ore"
- trash_names[11] = "minecraft:netherrack"
- trash_names[12] = "minecraft:stone_slab"
- trash_names[13] = "minecraft:nether_brick_stairs"
- trash_names[14] = "minecraft:nether_brick_fence"
- trash_names[15] = "minecraft:nether_brick"
- trash_names[16] = "minecraft:quartz"
- trash_names[17] = "minecraft:quartz_ore"
- local Mat_names = {}
- Mat_names[1] = "minecraft:dirt"
- Mat_names[2] = "minecraft:cobblestone"
- Mat_names[3] = "minecraft:netherrack"
- local Light_names = {}
- Light_names[1] = "nevermine:deepCrystal"
- Light_names[2] = "minecraft:glowstone"
- Light_names[3] = "minecraft:lit_pumpkin"
- local RSBlock_names = {}
- RSBlock_names[1] = "minecraft:redstone_block"
- local PowRail_names = {}
- PowRail_names[1] = "minecraft:golden_rail"
- -- 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(9)
- robot.place()
- end
- end
- local function Bd()
- if not dDown() then
- robot.select(9)
- robot.placeDown()
- end
- end
- local function Bu()
- if not dUp() then
- robot.select(9)
- 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
- -- Place Glowstone Blocks
- local function GBf()
- while d() do
- robot.swing()
- os.sleep(2)
- end
- robot.select(2) ; robot.place()
- end
- -- MovementEx script
- local function MovementEx()
- Bd() ; go()
- Bd() ; left() ; go() ; Bf() ; Bd() ; TURN() ; go() ; go() ; Bd() ; Bf() ; goUp()
- GBf() ; TURN() ; go() ; go() ; Bf() ; goUp()
- Bf() ; Bu() ; TURN() ; go() ; Bu() ; go() ; Bf() ; Bu()
- TURN() ; go() ; goDown() ; goDown() ; rSand() ; left()
- end
- -- find light source blocks
- local function findLight(stack_info)
- if stack_info == nil then
- return false
- end
- for index, known_light_name in ipairs(Light_names) do
- if stack_info.name == known_light_name then
- return true
- end
- end
- return false
- end
- -- restock on light source blocks
- local function getLight()
- left() ; robot.select(1) ; robot.place() ; robot.select(2) ; robot.drop()
- for slot=1,27 do
- local stack_info = inventory.getStackInSlot(side, slot)
- if findLight(stack_info) then
- print(stack_info.name, "I found something in slot", slot, "Restocking, stand by!")
- inventory.suckFromSlot(sides.front, slot)
- break
- end
- end
- robot.select(1) ; robot.swing() ; right()
- end
- -- find powered rails
- local function findPowRail(stack_info)
- if stack_info == nil then
- return false
- end
- for index, known_powrail_name in ipairs(PowRail_names) do
- if stack_info.name == known_powrail_name then
- return true
- end
- end
- return false
- end
- -- find redstone block
- local function findRSBlock(stack_info)
- if stack_info == nil then
- return false
- end
- for index, known_rsblock_name in ipairs(RSBlock_names) do
- if stack_info.name == known_rsblock_name then
- return true
- end
- end
- return false
- end
- -- restock on powered rails and redstone blocks
- local function getPowRail()
- left() ; robot.select(1) ; robot.place()
- robot.select(6)
- for slot=1,27 do
- local stack_info = inventory.getStackInSlot(side, slot)
- if findPowRail(stack_info) then
- print(stack_info.name, "I found P.Rails in slot", slot, "Restocking, stand by!")
- inventory.suckFromSlot(sides.front, slot)
- break
- end
- end
- robot.select(7)
- for slot=1,27 do
- local stack_info = inventory.getStackInSlot(side, slot)
- if findRSBlock(stack_info) then
- print(stack_info.name, "I found RS Blocks in slot", slot, "Restocking, stand by!")
- inventory.suckFromSlot(sides.front, slot)
- break
- end
- end
- robot.select(1) ; robot.swing() ; right()
- end
- -- place powered rail and a redstone block underneath it
- local function placeRailEx()
- local stack_info = inventory.getStackInInternalSlot(6)
- if findPowRail(stack_info) then
- print("I'm placing a", stack_info.name, "there.")
- TURN() ; robot.forward()
- robot.swingDown() ; robot.select(7) ; robot.placeDown()
- robot.back() ; robot.select(6) ; robot.place()
- TURN()
- end
- end
- -- find building materials
- local function findMat(stack_info)
- if stack_info == nil then
- return false
- end
- for index, known_mat_name in ipairs(Mat_names) do
- if stack_info.name == known_mat_name then
- return true
- end
- end
- return false
- 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
- -- find trash items collected during dig to clear inventory for other materials, might need to add more materials based on where you are digging
- 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.select(14) ; robot.swing() ; 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 his place into a filter chest, and robot use retrieved fuel
- local function refuel()
- right() ; robot.select(14) ; robot.place()
- robot.select(16) ; robot.drop() ; robot.select(15) ; robot.drop()
- 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
- -- restock on building materials
- local function getMat()
- right() ; robot.select(12) ; robot.place()
- robot.select(10) ; robot.drop() ; robot.select(11) ; robot.drop() ;
- robot.select(9)
- repeat
- for slot=1,27 do
- local stack_info = inventory.getStackInSlot(side, slot)
- if findMat(stack_info) then
- print("Low building materials", "Restocking from slot" ,slot)
- inventory.suckFromSlot(sides.front, slot)
- break
- end
- end
- until robot.count(9) >= 13 or robot.count(10) >= 13 or robot.count(11) >= 13
- for slot=9, 11 do
- robot.select(slot)
- if robot.count() <= 12 then
- for cslot=1, 3 do
- inventory.dropIntoSlot(side, cslot)
- end
- end
- end
- for slot=10, 11 do
- robot.select(slot)
- if robot.count() >= 13 then
- robot.transferTo(9)
- end
- end
- robot.select(12) ; 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
- TURN() ; robot.select(4) ; robot.place() ; TURN() -- place rails
- end
- end
- --[[
- Dig a tunnel for # in the direction the robot is facing, then turn, and dig for # in the new direction that was defined during start-up.
- It will refuel, restock and place a rail behind the robot and dig a 3x3 hole with a shell around it.
- --]]
- local function digit()
- for i = 1, rowsToDig1 do
- if computer.energy() <= 2000 then
- refuel() -- refuel duh?
- end
- if robot.count(4) <= 2 then
- getRail() -- restock on rails
- end
- if robot.count(9) <= 12 then
- getMat() -- restock on building mats
- end
- if robot.count(2) <= 1 then
- getLight()
- end
- if robot.count(6) <= 1 then
- getPowRail()
- end
- if i%15 == 0 then do
- placeRailEx()
- else
- placeRail()
- end
- if i%7 == 0 then do
- MovementEx()
- else
- Movement()
- end
- end
- if direction == "LEFT" then
- left()
- elseif direction == "RIGHT" then
- right()
- end
- for i = 1, rowsToDig2 do
- if computer.energy() <= 2000 then
- refuel() -- refuel duh?
- end
- if robot.count(4) <= 2 then
- getRail() -- restock on rails
- end
- if robot.count(9) <= 12 then
- getMat() -- restock on building mats
- end
- if robot.count(2) <= 1 then
- getLight()
- end
- if robot.count(6) <= 1 then
- getPowRail()
- end
- if i%15 == 0 then do
- placeRailEx()
- else
- placeRail()
- end
- if i%7 == 0 then do
- MovementEx()
- else
- Movement()
- end
- end
- end
- -- Call the program
- digit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement