Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "4"
- --MENU
- local menu = {"Set own Path", "Manual", "Logger", "Refuel", "Settings" }
- local menufunction = {path, manual, logger, refuel, settings}
- local settingsmenu = {"Pre Settings", "Set own Path"}
- local settingsmenufunction = {presettings, newpath}
- --/MENU
- --DEFINITION
- local l = 0
- local allitems = 0
- local selectcounter = 1
- 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
- local cutCounter = 0
- local modemid = 0
- local modemmode = false
- local menucount = 0
- --/DEFINITION
- turtle.select(1)
- --SAVES
- function load(name)
- local file = fs.open(name,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function save(table,name)
- local file = fs.open(name,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- --/SAVES
- --TERM
- function startMessage()
- print("------Welcome to the miner".. version .."------")
- end
- function clearterm()
- term.clear()
- term.setCursorPos(1,1)
- 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
- --/TERM
- --SAVE INIT
- fs.makeDir("saves")
- if fs.exists("saves/modemmode") then
- if load("saves/modemmode") == "true" then
- rednet.open("right")
- end
- end
- if fs.exists("saves/fuelslot") ~= true then
- startMessage()
- clearterm()
- print("--Pre-settings--")
- write("Modem mode(true/false):")
- modemmode = read()
- if modemmode == "true" then
- write("Computer ID(number):")
- modemid = tonumber(read())
- rednet.open("right")
- end
- save(modemmode, "saves/modemmode")
- save(modemid, "saves/modemid")
- save(0, "saves/fuelslot")
- save(0, "saves/height")
- save(0, "saves/width")
- save(0, "saves/length")
- save(0, "saves/direction")
- save(0, "saves/fback")
- save(0, "saves/fbclear")
- end
- --/SAVE INIT--
- --FUNCTIONS
- function tableLength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- 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 usefuel(slotnum)
- turtle.select(slotnum)
- turtle.refuel(1)
- modemmode = load("saves/modemmode")
- modemid = load("saves/modemid")
- if modemmode == "true" then
- rednet.send(modemid, turtle.getFuelLevel())
- end
- end
- function setPositionVars()
- lastx = actx
- lasty = acty
- lastz = actz
- lastyaw = actyaw
- end
- function countDown(time, fuelslot)
- for p = time,0,-1 do
- writeterm("Sleep mode for :" ..p.. " seconds", 2)
- if fuelslot ~= nil then
- usefuel(fuelslot)
- end
- sleep(1)
- end
- end
- --/FUNCTIONS
- --WALKING
- function turtledig()
- turtle.suck()
- modemmode = load("saves/modemmode")
- modemid = load("saves/modemid")
- if modemmode == "true" then
- rednet.send(modemid, turtle.getFuelLevel())
- end
- 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()
- turtle.suck()
- forwardcounter = forwardcounter + 1
- blocksleft = fullblocksize - forwardcounter
- writeterm(blocksleft.." Blocks left until end", 0)
- writeterm(turtle.getFuelLevel().." Fuellevel", 1)
- blocksleft = 0
- turtle.digUp()
- if turtle.getItemCount(16) > 0 then
- setPositionVars()
- findBack(0,0,0,0,true)
- end
- end
- function turtledigdown()
- turtle.suck()
- 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()
- turtle.suck()
- if turtle.up() == false then
- while turtle.up() == false do
- turtledigup()
- turtle.suck()
- end
- end
- acty = acty + 1
- writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
- end
- function turtledown()
- turtle.suck()
- if turtle.down() == false then
- while turtle.down() == false do
- turtledigdown()
- turtle.suck()
- end
- end
- acty = acty - 1
- end
- function goforward()
- turtle.suck()
- modemmode = load("saves/modemmode")
- modemid = load("saves/modemid")
- if modemmode == "true" then
- rednet.send(modemid, turtle.getFuelLevel())
- end
- if turtle.forward() == false then
- while turtle.forward() == false do
- turtledig()
- turtle.suck()
- 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
- --/WALKING
- --MENUFUNCTIONS
- function manual()
- clearterm()
- startMessage()
- write("Fuel slot:")
- fuelslotnum = tonumber(read())
- usefuel(fuelslotnum)
- write("Heigth:")
- high = tonumber(read())
- write("Width:")
- width = tonumber(read())
- write("Length:")
- length = tonumber(read())
- write("up/down:")
- direction = read()
- write("Walk back to start position (true/false):")
- fback = read()
- if fback == "true" then
- write("Walk back to start position & clear Inventory - buggy (true/false):")
- fbclear = read()
- end
- clearterm()
- createterm()
- mine(high,width,length, fuelslotnum, direction, fback, fbclear)
- end
- function logger()
- clearterm()
- write("Fuel slot (1,4-16):")
- lfuelslotnum = tonumber(read())
- write("Saplings (left):")
- saplingsleft = tonumber(read())
- write("Saplings (front):")
- saplingsfront = tonumber(read())
- write("Sleep Timer:")
- sleepTimer = tonumber(read())
- clearterm()
- startMessage()
- while true do
- for m = 0, saplingsfront do
- cutCounter = cutCounter + 1
- if cutCounter > 1 then
- cutCounter = 0
- end
- findBack(actx + 1,0,actz,0,false)
- turtle.select(3)
- if turtle.compare() then
- mineTree(actx,actz)
- end
- turtle.select(2)
- turtle.place()
- for n = 0,saplingsleft do
- if cutCounter == 1 then
- findBack(actx,0,actz + 3,0,false)
- else
- findBack(actx,0,actz - 3,0,false)
- end
- turtle.select(3)
- if turtle.compare() then
- mineTree(actx,actz)
- end
- turtle.select(2)
- turtle.place()
- end
- findBack(actx,0,actz + 1,0,false)
- findBack(actx + 2,0,actz,0,false)
- findBack(actx,0,actz - 1,0,false)
- end
- findBack(actx,0,actz+2,0,false)
- findBack(0,0,0,2,false)
- turtle.select(3)
- turtle.drop(turtle.getItemCount(3)-1)
- for i = 4,16 do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- turtle.select(1)
- countDown(sleepTimer, lfuelslotnum)
- turtleleft()
- turtleleft()
- end
- end
- function mineTree(x,z)
- x = x + 1
- findBack(x,6,z,0,false)
- x = x - 1
- findBack(x,0,z,0,false)
- end
- function path()
- new = load("saves/fuelslot")
- if new == 0 then
- clearterm()
- startMessage()
- write("Fuel slot (number 1-16):")
- fuelslotnum = tonumber(read())
- usefuel(fuelslotnum)
- write("Heigth (number):")
- high = tonumber(read())
- write("Width (number):")
- width = tonumber(read())
- write("Length (number):")
- length = tonumber(read())
- write("Direction (up/down):")
- direction = read()
- write("Walk back to start position (true/false):")
- fback = read()
- if fback == "true" then
- write("Walk back to start position & clear Inventory - buggy (true/false):")
- fbclear = read()
- end
- save(fuelslotnum, "saves/fuelslot")
- save(high, "saves/height")
- save(width, "saves/width")
- save(length, "saves/length")
- save(direction, "saves/direction")
- save(fback, "saves/fback")
- save(fbclear, "saves/fbclear")
- clearterm()
- startMessage()
- mainmenu()
- else
- fuelslotnum = load("saves/fuelslot")
- high = load("saves/height")
- width = load("saves/width")
- length = load("saves/length")
- direction = load("saves/direction")
- fback = load("saves/fback")
- fbclear = load("saves/fbclear")
- clearterm()
- createterm()
- mine(high,width,length, fuelslotnum, direction, fback, fbclear)
- end
- 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
- clearterm()
- createterm()
- end
- function settings()
- clearterm()
- startMessage()
- mainmenu(settingsmenu, settingsmenufunction)
- end
- --/MENUFUNCTIONS
- --MENUSETTINGSFUNCTIONS
- function newpath()
- save(0, "saves/fuelslot")
- path()
- end
- function presettings()
- startMessage()
- clearterm()
- print("--Pre-settings--")
- write("Modem mode(true/false):")
- modemmode = read()
- if modemmode == "true" then
- write("Computer ID(number):")
- modemid = tonumber(read())
- rednet.open("right")
- end
- save(modemmode, "saves/modemmode")
- save(modemid, "saves/modemid")
- clearterm()
- startMessage()
- mainmenu()
- end
- --/MENUSETTINGSFUNCTIONS
- function mainmenu(T, T2)
- selectcounter = 1
- menucount = 0
- if T == nil then
- T = menu
- end
- if T2 == nil then
- T2 = menufunction
- end
- print("Choose Program:")
- for _ in pairs(T) do
- menucount = menucount + 1
- term.setCursorPos(1,2 + menucount)
- term.clearLine()
- if menucount == selectcounter then
- print("["..T[menucount].."]")
- else
- print(" "..T[menucount].." ")
- end
- end
- print()
- print("------"..turtle.getFuelLevel().." Fuellevel------")
- while true do
- local event1, param2 = os.pullEvent("key")
- if param2 == 200 then
- selectcounter = selectcounter - 1
- changeSelector(selectcounter, T)
- elseif param2 == 208 then
- selectcounter = selectcounter + 1
- changeSelector(selectcounter, T)
- elseif param2 == 28 then
- T2[selectcounter]()
- end
- end
- end
- function changeSelector(selectcounter, T)
- if selectcounter < 1 then
- selectcounter = maxprogram
- elseif selectcounter > tableLength(T) then
- selectcounter = 1
- end
- menucount = 0
- for _ in pairs(T) do
- menucount = menucount + 1
- term.setCursorPos(1,2 + menucount)
- term.clearLine()
- if menucount == selectcounter then
- print("["..T[menucount].."]")
- else
- print(" "..T[menucount].." ")
- end
- end
- print()
- end
- function mine(high, width, length, fuelslotnum, direction, fback, fbclear)
- l = 0
- if fback == nil then
- fback = false
- end
- if fbclear == nil then
- fbclear = false
- end
- fullblocksize = high * width * length
- for i = 1, high do
- for j = 1, width do
- for k = 2, 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
- if direction == "down" then
- turtledigdown()
- turtledown()
- else
- turtledigup()
- turtleup()
- end
- turtleleft()
- turtleleft()
- end
- if fback == "true" and fbclear == "false" then
- findBack(0,0,0,0)
- elseif fback == "true" and fbclear == "true" then
- findBack(0,0,0,1)
- end
- clearterm()
- startMessage()
- mainmenu()
- end
- --INIT
- clearterm()
- startMessage()
- mainmenu()
- --/INIT
Advertisement
Add Comment
Please, Sign In to add comment