Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- SIMPLE MINER V3
- This program will mine a hole of your specified dimensions if you provide him a pickaxe.
- It takes in arguments, first being the depth of the hole, second being the length in
- the direction the robot is pointing and the third being the length that is facing the
- robot to the right.
- Bugs:
- - none atm
- --]]
- local r = require("robot")
- local arg = {...}
- -- getting variables for size / setting variables
- if arg[1] == nil or arg[2] == nil or arg[3] == nil then
- print("Depth number: ")
- depth = tonumber(io.read())
- print("Blocks X: ")
- sideX = tonumber(io.read())
- print("Blocks Y: ")
- sideY = tonumber(io.read())
- else
- depth = tonumber(arg[1])
- sideX = tonumber(arg[2])
- sideY = tonumber(arg[3])
- end
- side = "r"
- --[[
- FUNCTIONS part
- --]]
- -- The function to move in any direction
- function move(direction)
- -- u = up; d = down; f = forward
- if direction == nil then
- -- forward
- if not r.forward() then
- local _, why = r.detect()
- if why == "entity" then
- while not r.forward() do
- io.write("Go away! (sleep for 3s)\n")
- r.swing()
- r.swing()
- os.sleep(3)
- end
- elseif why == "air" then -- why is this needed!!!
- if arg[4] == debug then
- print("just moving through air -.-")
- end
- r.forward()
- else
- io.write("Obstacle! Can't move, stopping operation. (", why, ")\n")
- print("may I proceed?")
- io.read()
- r.forward()
- end
- end
- elseif direction == "down" then
- -- down
- if not r.down() then
- local _, why = r.detectDown()
- if why == "entity" then
- while not r.down() do
- io.write("Go away! (sleep for 3s)\n")
- r.swing()
- r.swing()
- os.sleep(3)
- end
- elseif why == "air" then -- why is this needed!!!
- if arg[4] == debug then
- print("just moving through air -.-")
- end
- r.down()
- else
- io.write("Obstacle! Can't move, stopping operation. (", why, ")\n")
- print("may I proceed?")
- io.read()
- r.down()
- end
- end
- end
- end
- -- The function to swing / mine blocks
- function swing(direction)
- -- u = up; d = down; f = forward
- if direction == nil then
- -- forward
- if not r.swing() then
- local _, why = r.detect()
- if why == "entity" then
- while not r.swing() do
- io.write("Go away! (sleep for 3s)\n")
- r.swing()
- r.swing()
- os.sleep(3)
- end
- elseif why == "air" then
- io.write("just swinging at air -.-\n")
- else
- io.write("Obstacle! Can't swing, stopping operation. (", why, ")\n")
- io.write("Please remove the obstacle. May I proceed?\n")
- io.read()
- end
- end
- elseif direction == "down" then
- -- down
- if not r.swingDown() then
- local _, why = r.detectDown()
- if why == "entity" then
- while not r.swingDown() do
- io.write("Go away! (sleep for 3s)\n")
- r.swing()
- r.swing()
- os.sleep(3)
- end
- elseif why == "air" then
- io.write("just swinging at air -.-\n")
- else
- io.write("Obstacle! Can't swing, stopping operation. (", why, ")\n")
- io.write("Please remove the obstacle. May I proceed?\n")
- io.read()
- end
- end
- end
- end
- --[[
- THE MAIN PROGRAM
- --]]
- -- ToDo: checks for tools (later maybe fuel or sth... if it has generator module, ...)
- -- the moving and swinging part
- for i=1,depth do
- swing("down")
- move("down")
- io.write("Floor ", i, "\n")
- for j=1,sideX do
- io.write(" - row ", j, "\n")
- for k=1,sideY-1 do
- swing()
- move()
- end
- if j ~= sideX then
- if side == "r" then
- r.turnRight()
- swing()
- move()
- r.turnRight()
- side = "l"
- elseif side == "l" then
- r.turnLeft()
- swing()
- move()
- r.turnLeft()
- side = "r"
- end
- end
- end
- r.turnAround()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement