Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- --- Created by deathsgun.
- --- DateTime: 2019-05-21 15:01
- ---
- local arg1, arg2, arg3 = ...
- local delay = 0.25
- if arg1 == nil or arg2 == nil or arg3 == nil then
- print("Usage: miner <length> <height> <width>")
- return false
- end
- local length = tonumber(arg1)
- local height = tonumber(arg2)
- local width = tonumber(arg3)
- X = 0;
- Y = 0;
- Z = 0;
- ORIENTATION = 0;
- function left()
- turtle.turnLeft()
- if ORIENTATION == 0 then
- ORIENTATION = 3
- else
- ORIENTATION = ORIENTATION - 1
- end
- end
- function right()
- turtle.turnRight()
- if ORIENTATION == 3 then
- ORIENTATION = 0
- else
- ORIENTATION = ORIENTATION + 1
- end
- end
- function up()
- while not turtle.up() do
- digUp()
- sleep(delay)
- end
- Y = Y + 1
- end
- function down(q)
- if q == nil then
- q = 1
- end
- for _ = 1, q do
- while not turtle.down() do
- digDown()
- sleep(delay)
- end
- end
- Y = Y - q
- end
- function forward(q)
- if q == nil then
- q = 1
- end
- for _ = 1, q do
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- sleep(delay)
- end
- end
- if ORIENTATION == 0 then
- X = X + q
- elseif ORIENTATION == 1 then
- Z = Z + q
- elseif ORIENTATION == 2 then
- X = X - q
- elseif ORIENTATION == 3 then
- Z = Z - q
- end
- end
- function orient(orient)
- while orient ~= 0 do
- right()
- end
- end
- function dig()
- while turtle.detect() do
- turtle.dig()
- sleep(delay)
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(delay)
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- sleep(delay)
- end
- end
- function go(lx, ly, lz)
- print("going to " .. lx .. "/" .. ly .. "/" .. lz)
- if X < lx then
- orient(0)
- for _ = 1, (lx - X) do
- forward()
- end
- end
- if X > lx then
- orient(2)
- for _ = 1, X - lx do
- forward()
- end
- end
- if Y < ly then
- for _ = 1, ly - Y do
- up()
- end
- end
- if Y > ly then
- for _ = 1, Y - ly do
- down()
- end
- end
- if Z < lz then
- orient(1)
- for _ = 1, lz - Z do
- forward()
- end
- end
- if Z > lz then
- orient(3)
- for _ = 1, Z - lz do
- forward()
- end
- end
- end
- function deposit()
- for i = 2, 16 do
- turtle.select(i)
- while not turtle.drop() and turtle.getItemCount() ~= 0 do
- -- Waits until turtle can deposit item
- sleep(1)
- end
- turtle.drop()
- end
- turtle.select(1)
- return true
- end
- function check()
- return turtle.getItemCount(15) == 0
- end
- neededFuel = height*width*length;
- neededCoal = neededFuel / 80
- if neededCoal < 1 then
- neededCoal = 1
- end
- print("This operation takes " ..neededCoal .. "of Coal!")
- if neededFuel < turtle.getFuelLevel() then
- turtle.select(1)
- print("Please put " .. neededCoal .. " piece(s) of coal into Slot 1!")
- while neededFuel < turtle.getFuelLevel() do
- turtle.refuel()
- end
- end
- turtle.select(2)
- print("Creating a tunnel of " .. height .. "x" .. width .. "x" .. length)
- lx = X
- ly = Y
- lz = Z
- for _ = 1, length do
- lx = X
- ly = Y
- lz = Z
- term.write("=")
- for _ = 1, width do
- forward()
- for _ = 1, height do
- up()
- end
- down(height)
- if _ == 1 then
- right()
- elseif _ <= width then
- left()
- forward(width)
- end
- end
- go(lx, ly, lz)
- end
- go(0, 0, 0)
- orient(2)
- deposit()
- orient(0)
- print("Finished task!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement