Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- _ _ _ _ _ _ _ _ _
- | |
- | |
- | |
- | |
- | |
- | |
- |x _ _ _ _ _ _ _ _|
- Enclosed area is the space to be mined where
- x is the starting position of the robot.
- Notes:
- - Put in the network address of the reciever.
- - Put in the port at which the robot and the reciever will communicate through.
- - When placing the robot, it must face into the quarry.
- - The charger needs to be placed on the left side of the robot. Make sure it gets power and a redstone signal.
- - The tool box/chest needs to be placed above the charger.
- - The storage chest needs to be placed on top of the tools chest.
- - When filling the tools box, a diamond level tool is prefered.
- Minimum Robot Specs:
- - Tier 1 Screen
- - 2 Tier 1 Memory cards
- - Tier 1 CPU
- - Tier 2 Computer Case
- - Tier 1 Graphics Card
- - Disk Drive
- - Wireless network card
- - 1 Inventory Upgrade
- - Inventory Controller Upgrade
- - Keyboard
- - EEPROM with lua BIOS
- - Tier 1 Hard Disk Drive with lua BIOS installed
- --]]
- local robot = require("robot")
- local shell = require("shell")
- local component = require("component")
- local text = require("text")
- local computer = require("computer")
- local left = robot.turnLeft
- local right = robot.turnRight
- local around = robot.turnAround
- local forward = robot.forward
- local down = robot.down
- local up = robot.up
- local swing = robot.swing
- local swingD = robot.swingDown
- local swingU = robot.swingUp
- local target = --targets address
- local port = --Port
- local switch = 1 --1 is for right and -1 is for left
- local zcord, xcord, ycord, f = 0, 0, 0, 0
- function mts(message)
- component.modem.send(target, port, message)
- end
- --Moves robot to the origin
- function returnToZero()
- --Saves current cords as old cords
- local zold, xold, yold, fold = zcord, xcord, ycord, math.fmod(f, 4)
- --Moves robot to y=0, x=0, z=0 f=2
- for i = yold, 1, -1 do
- up()
- end
- if (fold == 0) then
- left()
- elseif (fold == 2) then
- right()
- elseif (fold == 1) then
- around()
- end
- fold = 3
- for i = xold, 1, -1 do
- forward()
- end
- left()
- fold = 2
- for i = zold, 1, -1 do
- forward()
- end
- end
- --Moves robot to previous cordinites and face
- function returnToCords()
- local fold = math.fmod(f, 4)
- around()
- for i = 1, zcord do
- forward()
- end
- right()
- for i = 1, xcord do
- forward()
- end
- for i = 1, ycord do
- down()
- end
- if (fold == 0) then
- left()
- elseif (fold == 2) then
- right()
- elseif (fold == 3) then
- around()
- end
- end
- --No tool then get tool
- function eTool()
- --Goes to Origin
- returnToZero()
- --Equips new tool
- up()
- right()
- robot.select(1)
- robot.suck()
- component.inventory_controller.equip()
- robot.select(2)
- left()
- down()
- --Returns robot to previous cords
- returnToCords()
- end
- --Checks if inventory almost full then dump to storage
- function inv(done)
- if ((robot.count(robot.inventorySize()) > 1) or done) then
- --Go to drop off point
- returnToZero()
- --Transport items
- up()
- up()
- right()
- for i = 2, robot.inventorySize() do
- robot.select(i)
- robot.drop()
- end
- robot.select(2)
- left()
- down()
- down()
- --return back
- if not done then
- returnToCords()
- end
- end
- end
- --Robot gets stuck
- function stuck()
- --Checks to see if the problem is fixed
- mts("Robot is stuck")
- repeat
- print("Type 'FIXED' to resume")
- local input = string.upper(io.read())
- until string.upper(input) == "FIXED" and robot.detect()
- end
- --Robot needs to charge
- function energy()
- if (computer.energy() < (computer.maxEnergy()/3)) then
- returnToZero()
- while (computer.energy() < (computer.maxEnergy()-10)) do --[[ Waits for the robot to charge up--]]end
- returnToCords()
- end
- end
- --Check swinging
- function swingSafe(side)
- --Checks if there is a tool
- local _, dur_message = robot.durability()
- if (dur_message == "no tool equipped") then
- eTool()
- end
- --Checks if the side is broken
- if (side == "front") then
- local arg, message = swing()
- if (message == "entity") then
- local stuckCount = 0
- while (swing()) do
- swing()
- stuckCount = stuckCount + 1
- if (stuckCount == 10) then
- stuck()
- end
- end
- elseif (arg == false and message == "block") then
- return stuck()
- end
- elseif (side == "down") then
- local arg, message = swingD()
- if (message == "entity") then
- local stuckCount = 0
- while (swingD()) do
- swingD()
- stuckCount = stuckCount + 1
- if (stuckCount == 10) then
- stuck()
- end
- end
- elseif (arg == false and message == "block") then
- return stuck()
- end
- elseif (side == "up") then
- local arg, message = swingU()
- if (message == "entity") then
- local stuckCount = 0
- while (swingU()) do
- swingU()
- stuckCount = stuckCount + 1
- if (stuckCount == 10) then
- stuck()
- end
- end
- elseif (arg == false and message == "block") then
- return stuck()
- end
- end
- end
- --Check movement
- function moveSafe(side)
- --Checks if side is broken
- if (side == "front") then
- local _, message = forward()
- if (message == "entity" or message == "solid") then
- local stuckCount = 0
- while (not(forward())) do
- swingSafe(side)
- stuckCount = stuckCount + 1
- if (stuckCount == 10) then
- stuck()
- end
- end
- end
- elseif (side == "down") then
- local _, message = down()
- if (message == "entity" or message == "solid") then
- local stuckCount = 0
- while (not(down())) do
- swingSafe(side)
- stuckCount = stuckCount + 1
- if (stuckCount == 10) then
- stuck()
- end
- end
- end
- elseif (side == "up") then
- local _, message = up()
- if (message == "entity" or message == "solid") then
- local stuckCount = 0
- while (not(up())) do
- swingSafe(side)
- stuckCount = stuckCount + 1
- if (stuckCount == 10) then
- stuck()
- end
- end
- end
- end
- end
- --Right turn
- function rightTurn()
- swingSafe("down")
- right()
- f = f + switch
- moveSafe("front")
- if (math.fmod(ycord, 2) == 0) then
- xcord = xcord + 1
- elseif (math.fmod(ycord, 2) == 1) then
- xcord = xcord - 1
- end
- right()
- f = f + switch
- end
- --Left turn
- function leftTurn()
- swingSafe("down")
- left()
- f = f + switch
- moveSafe("front")
- if (math.fmod(ycord, 2) == 0) then
- xcord = xcord + 1
- elseif (math.fmod(ycord, 2) == 1) then
- xcord = xcord - 1
- end
- left()
- f = f + switch
- end
- --Quarry
- function dig(width, length, height)
- --Defaults slot to 2
- --Slot one is for grabbing a tool
- robot.select(2)
- --Width is x-axis
- --Length is z-axis
- --Height is y-axis
- for y = 1, height do --per layer
- for x = 1, width do --per row
- for z = 1, length - 1 do --per column
- swingSafe("down")
- moveSafe("front")
- if (math.fmod(ycord, 2) == 0) then
- zcord = zcord + switch
- elseif (math.fmod(ycord, 2) == 1) then
- zcord = zcord - switch
- end
- end
- energy() --Checks if robot needs to charge after one column
- if (x < width) then --Checks if the current column is the last column before the next layer
- if (switch == 1) then --to turn into the right column
- rightTurn()
- elseif (switch == -1) then --to turn into the left column
- leftTurn()
- end
- switch = -switch
- else
- break
- end
- end
- --Dig below and goes to bottom layer
- swingSafe("down")
- if (y < height) then
- moveSafe("down")
- around()
- f = f + (2*switch)
- ycord = ycord + 1
- end
- end
- inv(true)
- forward()
- mts("Quarry is finished")
- component.modem.close(123)
- computer.shutdown()
- end
- --Gets users dimension
- function userSize()
- local size
- --Continuously asks user for sizes until those are integers
- repeat
- print("Quarry Dimensions?")
- print("Width Length Height")
- size = text.tokenize(io.read())
- if (tonumber(size[1]) and tonumber(size[2]) and tonumber(size[3])) then
- size[1] = tonumber(size[1])
- size[2] = tonumber(size[2])
- size[3] = tonumber(size[3])
- else
- print("Some of those are not numbers, please try again...")
- end
- until tonumber(size[1]) and tonumber(size[2]) and tonumber(size[3])
- --Size confermation
- repeat
- print("Width: " .. size[1] .. "\nLength: " .. size[2] .. "\nHeight: " .. size[3])
- print("Are those the right sizes? y/n")
- local input = string.lower(io.read())
- if (input == "y") then
- dig(size[1], size[2], size[3])
- elseif (input == "n") then
- userSize()
- end
- until input == "y" or input == "n"
- end
- userSize()
Advertisement
Add Comment
Please, Sign In to add comment