Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local l = 0
- local allitems = 0
- local selectcounter = 0
- local maxprogram = 3
- local forwardcounter = 0
- local fullblocksize = 0
- local i = 0
- local j = 0
- local k = 0
- local width = 0
- local height = 0
- local length = 0
- local actx = 0
- local acty = 0
- local actz = 0
- local actyaw = 0
- local lastx = 0
- local lasty = 0
- local lastz = 0
- local lastyaw = 0
- local anwser = false
- turtle.select(1)
- function startMessage()
- print("----Welcome to the miner v.3----")
- end
- function items()
- for i = 1, 16 do
- actitem = turtle.getItemCount(i)
- allitems = allitems + actitem
- end
- return allitems
- end
- function clearInv()
- for i = 1,16 do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- turtle.select(1)
- end
- function clearterm()
- term.clear()
- term.setCursorPos(1,1)
- end
- function usefuel(slotnum)
- turtle.select(slotnum)
- turtle.refuel(1)
- end
- function setPositionVars()
- lastx = actx
- lasty = acty
- lastz = actz
- lastyaw = actyaw
- end
- function turtledig()
- forwardcounter = forwardcounter + 1
- blocksleft = fullblocksize - forwardcounter
- writeterm(blocksleft.." Blocks left until end", 0)
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- blocksleft = 0
- turtle.dig()
- if turtle.getItemCount(16) > 0 then
- setPositionVars()
- findBack(0,0,0,0,true)
- end
- end
- function turtledigup()
- forwardcounter = forwardcounter + 1
- blocksleft = fullblocksize - forwardcounter
- writeterm(blocksleft.." Blocks left until end", 0)
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- blocksleft = 0
- turtle.digUp()
- end
- function turtledigdown()
- forwardcounter = forwardcounter + 1
- blocksleft = fullblocksize - forwardcounter
- writeterm(blocksleft.." Blocks left until end", 0)
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- blocksleft = 0
- turtle.digDown()
- if turtle.getItemCount(16) > 0 then
- setPositionVars()
- findBack(0,0,0,0,true)
- end
- end
- function turtleup()
- if turtle.up() == false then
- while turtle.up() == false do
- turtledigup()
- end
- end
- acty = acty + 1
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function turtledown()
- if turtle.down() == false then
- while turtle.down() == false do
- turtledigdown()
- end
- end
- acty = acty - 1
- end
- function goforward()
- if turtle.forward() == false then
- while turtle.forward() == false do
- turtledig()
- end
- end
- if actyaw == 0 then
- actx = actx + 1
- elseif actyaw == 1 then
- actz = actz - 1
- elseif actyaw == 2 then
- actx = actx - 1
- elseif actyaw == 3 then
- actz = actz + 1
- end
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function findBack(x, y, z, yaw, anwser)
- if anwser ~= true then
- anwser = false
- end
- if x < actx then
- while actyaw ~= 2 do
- turtleleft()
- end
- elseif x > actx then
- while actyaw ~= 0 do
- turtleleft()
- end
- end
- while actx ~= x do
- goforward()
- end
- if z > actz then
- while actyaw ~= 3 do
- turtleleft()
- end
- elseif z < actz then
- while actyaw ~= 1 do
- turtleleft()
- end
- end
- while actz ~= z do
- goforward()
- end
- if y < acty then
- while acty ~= y do
- turtledown()
- end
- elseif y > acty then
- while acty ~= y do
- turtleup()
- end
- end
- while actyaw ~= yaw do
- turtleleft()
- end
- if anwser == true then
- turtleleft()
- turtleleft()
- clearInv()
- turtleleft()
- turtleleft()
- findBack(lastx, lasty, lastz, lastyaw, false)
- end
- end
- function turtleright()
- turtle.turnRight()
- actyaw = actyaw + 1
- if actyaw > 3 then
- actyaw = 0
- end
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function turtleleft()
- turtle.turnLeft()
- actyaw = actyaw - 1
- if actyaw < 0 then
- actyaw = 3
- end
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function turnright()
- turtleright()
- turtledig()
- goforward()
- turtleright()
- end
- function turnleft()
- turtleleft()
- turtledig()
- goforward()
- turtleleft()
- end
- function manual()
- clearterm()
- startMessage()
- write("Fuel slot:")
- fuelslotnum = tonumber(read())
- usefuel(fuelslotnum)
- write("High:")
- high = tonumber(read())
- write("Width:")
- width = tonumber(read())
- write("Length")
- length = tonumber(read())
- clearterm()
- createterm()
- mine(high,width,length, fuelslotnum)
- end
- function createterm()
- term.setCursorPos(1,6)
- term.clearLine()
- print("------X Blocks left until end------")
- print("------X Fuellevel------")
- end
- function writeterm(msg,cursorlevel)
- cursorlevel = 6 + cursorlevel
- term.setCursorPos(1,cursorlevel)
- term.clearLine()
- print("------"..msg.."------")
- end
- function control()
- clearterm()
- startMessage()
- print("[p] = stop")
- print("[w] = forward")
- print("[f] = down")
- print("[r] = up")
- while true do
- local event, param1 = os.pullEvent("char")
- if param1 == "p" then
- break
- elseif param1 == "w" then
- goforward()
- elseif param1 == "d" then
- turtle.turnRight()
- elseif param1 == "a" then
- turtle.turnLeft()
- elseif param1 == "s" then
- turtle.back()
- elseif param1 == "f" then
- turtle.down()
- elseif param1 == "r" then
- turtle.up()
- end
- end
- end
- function path()
- clearterm()
- startMessage()
- createterm()
- mine(4,1,150,16)
- end
- function refuel()
- clearterm()
- startMessage()
- createterm()
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- for j = 1,turtle.getItemCount(i) do
- usefuel(i)
- writeterm("", 0)
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- end
- end
- end
- end
- function mainmenu()
- print("Choose Program:")
- print("[X path of pain]")
- print(" Manual ")
- print(" Control Turtle ")
- print(" Refuel ")
- print()
- print("------"..turtle.getFuelLevel().." Fuellevel------")
- while true do
- local event1, param2 = os.pullEvent("key")
- if param2 == 200 then
- selectcounter = selectcounter - 1
- changeSelector(selectcounter)
- elseif param2 == 208 then
- selectcounter = selectcounter + 1
- changeSelector(selectcounter)
- elseif param2 == 28 then
- if selectcounter == 0 then
- path()
- elseif selectcounter == 1 then
- manual()
- elseif selectcounter == 2 then
- control()
- elseif selectcounter == 3 then
- refuel()
- end
- end
- end
- end
- function changeSelector(selectcounter)
- if selectcounter < 0 then
- selectcounter = maxprogram
- elseif selectcounter > maxprogram then
- selectcounter = 0
- end
- if selectcounter == 0 then
- term.setCursorPos(1,3)
- term.clearLine()
- print("[X path of pain]")
- term.setCursorPos(1,4)
- term.clearLine()
- print(" Manual ")
- term.setCursorPos(1,5)
- term.clearLine()
- print(" Control Turtle ")
- term.setCursorPos(1,6)
- term.clearLine()
- print(" Refuel ")
- elseif selectcounter == 1 then
- term.setCursorPos(1,3)
- term.clearLine()
- print(" X path of pain ")
- term.setCursorPos(1,4)
- term.clearLine()
- print("[Manual]")
- term.setCursorPos(1,5)
- term.clearLine()
- print(" Control Turtle ")
- term.setCursorPos(1,6)
- term.clearLine()
- print(" Refuel ")
- elseif selectcounter == 2 then
- term.setCursorPos(1,3)
- term.clearLine()
- print(" X path of pain ")
- term.setCursorPos(1,4)
- term.clearLine()
- print(" Manual ")
- term.setCursorPos(1,5)
- term.clearLine()
- print("[Control Turtle]")
- term.setCursorPos(1,6)
- term.clearLine()
- print(" Refuel ")
- elseif selectcounter == 3 then
- term.setCursorPos(1,3)
- term.clearLine()
- print(" X path of pain ")
- term.setCursorPos(1,4)
- term.clearLine()
- print(" Manual ")
- term.setCursorPos(1,5)
- term.clearLine()
- print(" Control Turtle ")
- term.setCursorPos(1,6)
- term.clearLine()
- print("[Refuel]")
- end
- end
- function mine(high, width, length, fuelslotnum)
- l = 0
- fullblocksize = high * width * length
- for i = 1, high do
- for j = 1, width do
- for k = 1, length do
- if turtle.refuel(1) == true then
- usefuel(fuelslotnum)
- end
- turtledig()
- goforward()
- end
- if j < width then
- l = l + 1
- if l < 2 then
- turnright()
- else
- turnleft()
- l = 0
- end
- end
- end
- turtledigup()
- turtleup()
- turtleleft()
- turtleleft()
- end
- findBack(0,0,0,0)
- end
- clearterm()
- startMessage()
- mainmenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement