Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ORE COLLECTING MINER V2.5 by BrunoZockt
- V1.0 released 22.07.2016 17kb
- V1.1 released 16.08.2016 17kb
- V2.0 released 07.10.2017 35kb
- V2.1 released 15.12.2017 40kb
- V2.2 released 17.12.2017 42kb
- V2.3 released 11.02.2018 46kb
- V2.4 released 19.06.2018 57kb
- V2.5 released 15.07.2018 68kb
- This program is a work in progress and
- will automatically update itself.
- If you have any problems, questions or
- suggestions I'd be happy if you wrote
- an e-mail to [email protected].
- Feel free to use this program whenever
- you want. If you want to use parts of
- my program for developing, do so but
- don't say it's yours - a sidenote
- e.g. "by BrunoZockt" would be nice :)
- If you want to understand this program
- I recommend to read the variables first
- and then the rest of the code from the
- bottom to the top! Maybe I will add
- some comments for better understanding
- soon! The names of my functions and
- variables may sound strange because
- some are german and others are not
- really creative, but I hope you
- understand it anyways ;) ]]--
- -----###-----configurable variables-----###-----
- local extVar = {}
- local variables = {
- ["length"] = 8,
- ["quantity"] = 10,
- ["lateralTorches"] = 1,
- ["tunnelspace"] = 4,
- ["mainTorches"] = true,
- ["Autofuel"] = true,
- ["chestSelect"] = 3,
- ["torches"] = true,
- ["floor"] = true,
- ["language"] = "en",
- ["ignor"] = {"minecraft:stone", "minecraft:cobblestone", "minecraft:dirt", "minecraft:lava", "minecraft:flowing_lava", "minecraft:water", "minecraft:flowing_water", "minecraft:torch"},
- ["trash"] = false
- }
- -----###-----global variables-----###-----
- local label = os.getComputerLabel() or "the turtle"
- local chestSlot = 16
- local fuelLevel = turtle.getFuelLevel()
- local w, h = term.getSize()
- local searching = false
- local kill = false
- local level = 0
- local direction = 1
- local select = 1
- local FuelDemand
- local maxSpace = false
- local setup = false
- local menustate
- local checkbox = false
- local focus = 100
- -----###-----ugly global variables-----###-----
- local vars = {
- ["notificationCenter"] = {
- time = 0
- },
- ["drawOptions"] = {
- shift = 0,
- shift2 = 0,
- saved = false,
- scroll = 0,
- scroll2 = 0,
- ypos
- },
- ["drawPopup"] = {
- scroll = 0,
- lastscroll = 0,
- ypos = 9
- },
- ["drawNews"] = {
- scroll = 0
- }
- }
- -----###-----tables-----###-----
- local cache = {}
- local toDoList = {}
- local torchPositions = {}
- local gone = {}
- local timer = {}
- local chest = {"enderchest", "chest", "none"}
- local objects = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
- local slots = {"_","_","_","_","_","_","_","_","_","_","_","_","_","_","_","C"}
- local errors = {false, false, false, false, false, false, false, false}
- local Check = {["Fuellevel"] = false, ["torches"] = false, ["chest"] = false}
- local stats = {
- ["dug"] = 0,
- ["ores"] = 0,
- ["time"] = 0,
- ["moves"] = 0
- }
- -----###-----helpful functions-----###-----
- function Sprint(str, xpos, ypos)
- term.setCursorPos(xpos, ypos)
- term.write(str)
- end
- function printCentered(str, ypos)
- term.setCursorPos(w/2 - #str/2 + 1, ypos)
- term.write(str)
- end
- function printRight(str, ypos, xoffset)
- if xoffset == nil then
- xoffset = 0
- end
- term.setCursorPos(w - xoffset - (#str - 1), ypos)
- term.write(str)
- end
- function printLeft(str, ypos)
- term.setCursorPos(1, ypos)
- term.write(str)
- end
- function printB(tab, y, stop, start)
- if start == nil then
- start = 1
- end
- if stop == nil then
- stop = w
- end
- local letters = 0
- for i in pairs(tab) do
- letters = letters + #tab[i]
- end
- local space = (stop-start)+1-letters
- term.setCursorPos(start, y)
- if (space/(#tab+1))%1 == 0 then
- for i in ipairs(tab) do
- term.write(string.rep(" ", space/(#tab+1))..tab[i])
- end
- elseif (space/(#tab))%2 == 0 then
- term.write(string.rep(" ", (space/#tab)/2))
- for i in ipairs(tab) do
- term.write(tab[i]..string.rep(" ", space/#tab))
- end
- elseif space == #tab-1 then
- term.write(tab[1])
- for i = 2, #tab do
- term.write(" "..tab[i])
- end
- else
- for i in ipairs(tab) do
- term.write(string.rep(" ", round(space/(#tab-i+2), "u"))..tab[i])
- space = space - round(space/(#tab-i+2), "u")
- end
- end
- end
- function printWrapped(tab, xpos, ypos, Space, sep)
- local sep = sep or " "
- local leftSpace = Space
- local newxpos = xpos
- for word = 1, #tab do
- if Space < #tab[word] + #sep then
- return false
- elseif leftSpace >= #tab[word]+#sep then
- Sprint(tab[word]..sep, newxpos, ypos)
- leftSpace = leftSpace - (#tab[word]+#sep)
- newxpos = newxpos + #tab[word]+#sep
- else
- ypos = ypos + 1
- leftSpace = Space
- Sprint(tab[word]..sep, xpos, ypos)
- leftSpace = leftSpace - (#tab[word]+#sep)
- newxpos = xpos + (#tab[word]+#sep)
- end
- end
- return ypos
- end
- function printLine(xpos, start, stop, point, endPoint)
- for i = start, stop do
- Sprint("|", xpos, i)
- end
- if point ~= nil then
- Sprint(point, xpos, start)
- Sprint((endPoint or point), xpos, stop)
- end
- end
- function Splitter(inputstr, sep)
- if inputstr == nil then
- return nil
- elseif sep == nil then
- sep = "%s"
- end
- local t, i = {}, 1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- local Version = tonumber(Splitter(os.version())[2])
- function ItemCount(Block, Slot)
- if Slot == 0 then
- return false
- elseif Slot == nil then
- return false
- end
- if Version >= 1.64 then
- local Data = turtle.getItemDetail(Slot)
- if Data == nil then
- return 0
- elseif Data.name == Block then
- return Data.count
- else
- return false
- end
- else
- return turtle.getItemCount(Slot)
- end
- end
- function Color()
- if Version <= 1.45 then
- return false
- elseif term.isColor() then
- return true
- else
- return false
- end
- end
- function MoveObjects(deleted, mode)
- if mode == 1 then
- for k, v in ipairs(gone) do
- if v == deleted then
- return
- end
- end
- for k, v in ipairs(objects) do
- if k > deleted and k < 12 then
- objects[k] = objects[k] - 1
- end
- end
- table.insert(gone, deleted)
- elseif mode == 2 then
- for k, v in ipairs(gone) do
- if v == deleted then
- table.remove(gone, k)
- for k, v in ipairs(objects) do
- if k > deleted and k < 12 then
- objects[k] = objects[k] + 1
- end
- end
- end
- end
- end
- end
- function OreCounter()
- if searching == true then
- stats["ores"] = stats["ores"] + 1
- if stats["ores"] == 1 then
- print(lang.status(variables.language, 1))
- else
- print(lang.status(variables.language, 2, stats["ores"]))
- end
- end
- end
- function SlotCalculator(code, param)
- local output = {}
- if param ~= nil and param ~= "check" then
- item = param
- elseif param == "check" then
- if code == "T" then
- item = "minecraft:torch"
- elseif code == "C" then
- if variables.chestSelect == 1 then
- item = "EnderStorage:enderChest"
- elseif variables.chestSelect == 2 then
- item = "minecraft:chest"
- end
- end
- end
- for n = 1, #slots do
- if slots[n] == code then
- if param == "empty" then
- table.insert(output, n)
- elseif param == nil then
- if turtle.getItemCount(n) > 0 then
- table.insert(output, n)
- end
- elseif ItemCount(item, n) ~= false and ItemCount(item, n) ~= 0 then
- table.insert(output, n)
- end
- end
- end
- return output
- end
- function refuel(Amount, Execute)
- local ActualAmount = turtle.getItemCount()
- if ActualAmount < Amount then
- if Execute == true then
- if turtle.refuel() == false then
- return false
- else
- while turtle.refuel() ~= false do
- end
- return ActualAmount
- end
- else
- return false
- end
- else
- turtle.refuel(Amount)
- return true
- end
- end
- function basicInputHandler(orientation, event, key)
- if event == "key" then
- if key == 28 then
- menustate = menu[menustate].options[select]
- select = 1
- elseif orientation == "vertical" then
- if key == 200 and select > 1 then
- select = select-1
- elseif key == 208 and select < #menu[menustate].options then
- select = select + 1
- end
- else
- if key == 203 and select > 1 then
- select = select - 1
- elseif key == 205 and select < #menu[menustate].options then
- select = select + 1
- end
- end
- end
- end
- function save(path, content)
- local file = fs.open(path, "w")
- if type(content) == "table" then
- file.writeLine(textutils.serialize(content))
- else
- file.writeLine(content)
- end
- file.close()
- end
- function edit(path, content)
- local file = fs.open(path, "w")
- for k, v in pairs(content) do
- if type(content[k]) == "table" then
- file.writeLine(k.." = "..textutils.serialize(content[k]))
- else
- file.writeLine(k.." = "..tostring(content[k]))
- end
- end
- file.close()
- end
- function translate(str, category)
- if category == "layout" then
- n = 35
- end
- for i = 1, n do
- if str == lang[category]("en", i) then
- return lang[category](variables.language, i)
- end
- end
- end
- function round(int, mode, dez)
- if dez == nil then
- dez = 1
- end
- if mode == "d" then
- mode = 0.4999
- elseif mode == "u" then
- mode = 0.5
- end
- return math.floor(int/dez+mode)*dez
- end
- -----###-----improved functions-----###-----
- function dig()
- OreCounter()
- stats["dug"] = stats["dug"] + 1
- return turtle.dig()
- end
- function digUp()
- OreCounter()
- stats["dug"] = stats["dug"] + 1
- return turtle.digUp()
- end
- function digDown()
- OreCounter()
- stats["dug"] = stats["dug"] + 1
- return turtle.digDown()
- end
- function face(int)
- if int == direction then
- return
- elseif (int + direction)%2 == 0 then
- turn()
- elseif int - direction == 1 then
- if direction < int then
- left()
- else
- right()
- end
- else
- if direction < int then
- right()
- else
- left()
- end
- end
- end
- function right()
- turtle.turnRight()
- direction = direction - 1
- if direction == 0 then
- direction = 4
- end
- end
- function left()
- turtle.turnLeft()
- direction = direction + 1
- if direction == 5 then
- direction = 1
- end
- end
- function turn()
- left()
- left()
- end
- function Freeway()
- searching = false
- while not turtle.forward() do
- if turtle.getFuelLevel == 0 then
- Fuel()
- elseif dig() == false then
- turtle.attack()
- end
- end
- stats["moves"] = stats["moves"] + 1
- end
- function FreewayUp()
- searching = false
- level = level + 1
- while not turtle.up() do
- if turtle.getFuelLevel == 0 then
- Fuel()
- elseif digUp() == false then
- turtle.attackUp()
- end
- end
- stats["moves"] = stats["moves"] + 1
- end
- function FreewayDown()
- searching = false
- level = level - 1
- while not turtle.down() do
- if turtle.getFuelLevel == 0 then
- Fuel()
- elseif digDown() == false then
- turtle.attackDown()
- end
- end
- stats["moves"] = stats["moves"] + 1
- end
- function FreewayBack()
- searching = false
- while not turtle.back() do
- if turtle.getFuelLevel == 0 then
- Fuel()
- else
- turn()
- if dig() == false then
- for i = 1, 20 do
- turtle.attack()
- os.sleep(0.05)
- end
- end
- turn()
- end
- end
- stats["moves"] = stats["moves"] + 1
- end
- -----###-----drawMenus-----###-----
- function notificationCenter()
- local advice = {
- lang.adv(variables.language, 1, ErrorSlot),
- lang.adv(variables.language, 2, 1),
- lang.adv(variables.language, 3, chestSlot),
- lang.adv(variables.language, 4, chestSlot),
- lang.adv(variables.language, 5, chestSlot),
- lang.adv(variables.language, 6, chestSlot),
- lang.adv(variables.language, 7, 1),
- lang.adv(variables.language, 8, 1)
- }
- if vars["notificationCenter"].time > 5 then
- for i = 1, #errors do
- if errors[i] ~= false then
- printWrapped(Splitter(advice[i], " "), 1, objects[8], w - 10)
- return
- end
- end
- end
- for i = 1, 4 do
- printLeft(lang.layout(variables.language, i), objects[i+7])
- end
- vars["notificationCenter"].time = vars["notificationCenter"].time + 0.5
- end
- function drawPopup(event, p1, p2, p3)
- local errorMessages = {
- lang.popup(variables.language, 1, ErrorSlot),
- lang.popup(variables.language, 2),
- lang.popup(variables.language, 1, chestSlot),
- lang.popup(variables.language, 3),
- lang.popup(variables.language, 1, chestSlot),
- lang.popup(variables.language, 4),
- lang.popup(variables.language, 5),
- lang.popup(variables.language, 6)
- }
- local leftBorder = round(w/9, "u")
- local rightBorder = round(w+1-w/9, "u")
- local winWidth = rightBorder-leftBorder-1
- vars["drawPopup"].lastscroll = vars["drawPopup"].scroll
- if event == "mouse_scroll" then
- vars["drawPopup"].scroll = vars["drawPopup"].scroll - p1
- elseif event == "mouse_click" and p1 == 1 then
- if p2 == leftBorder+winWidth then
- if p3 == 6 then
- vars["drawPopup"].scroll = vars["drawPopup"].scroll + 1
- elseif p3 == h-3 then
- vars["drawPopup"].scroll = vars["drawPopup"].scroll - 1
- end
- end
- elseif event == "key" then
- if p1 == 208 then
- vars["drawPopup"].scroll = vars["drawPopup"].scroll - 1
- elseif p1 == 200 then
- vars["drawPopup"].scroll = vars["drawPopup"].scroll + 1
- end
- end
- if vars["drawPopup"].scroll < -(vars["drawPopup"].ypos-vars["drawPopup"].lastscroll-(math.ceil((h-6)/10)+6)) then
- vars["drawPopup"].scroll = -(vars["drawPopup"].ypos-vars["drawPopup"].lastscroll-(math.ceil((h-6)/10)+6))
- elseif vars["drawPopup"].scroll > 0 then
- vars["drawPopup"].scroll = 0
- end
- printLine(leftBorder, 4, h-1, "+")
- printLine(rightBorder, 4, h-1, "+")
- vars["drawPopup"].ypos = math.ceil((h-6)/10)+5+vars["drawPopup"].scroll
- for i = 1, #errors do
- if errors[i] == true then
- vars["drawPopup"].ypos = printWrapped(Splitter("- "..errorMessages[i]), leftBorder+1, vars["drawPopup"].ypos+1, winWidth, " ")
- end
- end
- printCentered(string.rep("-", winWidth), 4)
- printCentered(string.rep("-", winWidth), h-1)
- printCentered(string.rep(" ", winWidth), 5)
- printCentered(string.rep(" ", winWidth), 6)
- printWrapped(Splitter(lang.popup(variables.language, 7, label)), leftBorder+1, math.ceil((h-6)/10)+4, winWidth, " ")
- printCentered(string.rep(" ", winWidth), h-3)
- printCentered(string.rep(" ", winWidth), 3)
- drawHeader()
- printLine(rightBorder-1, 6, h-3, "^", "v")
- if select == 1 then
- printB({">"..lang.popup(variables.language, 8).."<"," "..lang.popup(variables.language, 9).." ", " "..lang.popup(variables.language, 10).." "}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
- elseif select == 2 then
- printB({" "..lang.popup(variables.language, 8).." ",">"..lang.popup(variables.language, 9).."<", " "..lang.popup(variables.language, 10).." "}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
- else
- printB({" "..lang.popup(variables.language, 8).." "," "..lang.popup(variables.language, 9).." ", ">"..lang.popup(variables.language, 10).."<"}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
- end
- end
- function drawHeader()
- printCentered("ORE SEARCHING STRIP MINER by BrunoZockt", 1)
- printLeft(string.rep("-", w), 2)
- end
- function drawUpdate(event, p1, p2, p3)
- local leftBorder = round(w/6, "u")
- local rightBorder = round(w/6*5, "u")
- local winWidth = rightBorder-leftBorder-1
- local space = round(winWidth-13, "u")
- if event == "mouse_click" and p1 == 1 then
- if p2 == leftBorder+3 and p3 == math.ceil((h-6)/2)+5 then
- checkbox = not checkbox
- elseif p3 == math.ceil((h-6)/10*9)+4 then
- if p2 >= leftBorder+round(0.25*space, "u")+1 and p2 <= leftBorder+round(0.25*space, "u")+11 then
- if select == 1 then
- menustate = menu[menustate].options[select]
- else
- select = 1
- end
- elseif leftBorder+round(0.75*space, "u")+12 <= p2 and p2 <= leftBorder+round(0.75*space, "u")+13 then
- if select == 2 then
- menustate = menu[menustate].options[select]
- else
- select = 2
- end
- end
- end
- elseif event == "key" then
- if p1 == 203 and select > 1 then
- select = select - 1
- elseif p1 == 205 and select < #menu[menustate].options then
- select = select + 1
- elseif p1 == 28 then
- menustate = menu[menustate].options[select]
- end
- end
- printCentered(lang.layout(variables.language, 5), math.ceil((h-6)/6.9)+4)
- printCentered(string.rep("-", math.floor(w/3*2)), 4)
- printCentered(string.rep("-", math.floor(w/3*2)), 12)
- printLine(leftBorder, 4, 12, "+")
- printLine(rightBorder, 4, 12, "+")
- Sprint("_", leftBorder+3, math.ceil((h-6)/2)+4)
- Sprint("|_|"..lang.layout(variables.language, 6), leftBorder+2, math.ceil((h-6)/2)+5)
- if select == 1 then
- printB({">"..lang.layout(variables.language, 7).."<", " "..lang.layout(variables.language, 8).." "}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
- elseif select == 2 then
- printB({" "..lang.layout(variables.language, 7).." ", ">"..lang.layout(variables.language, 8).."<"}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
- end
- if checkbox == true then
- Sprint("X", leftBorder+3, math.ceil((h-6)/2)+5)
- end
- end
- function drawNews(event, p1, p2, p3)
- if event == "mouse_scroll" then
- vars["drawNews"].scroll = vars["drawNews"].scroll - p1
- elseif event == "key" then
- if p1 == 28 then
- menustate = menu[menustate].options[select]
- select = 1
- vars["drawNews"].scroll = 0
- elseif p1 == 208 then
- vars["drawNews"].scroll = vars["drawNews"].scroll - 1
- elseif p1 == 200 then
- vars["drawNews"].scroll = vars["drawNews"].scroll + 1
- end
- elseif event == "mouse_click" then
- if p1 == 1 then
- if p2 == w then
- if p3 == 3 then
- vars["drawNews"].scroll = vars["drawNews"].scroll + 1
- elseif p3 == h then
- vars["drawNews"].scroll = vars["drawNews"].scroll - 1
- end
- elseif p2 >= w/2-2 and p2 <= w/2+2 and p3 == h then
- menustate = menu[menustate].options[select]
- select = 1
- vars["drawNews"].scroll = 0
- end
- end
- end
- if vars["drawNews"].scroll > 0 then
- vars["drawNews"].scroll = 0
- elseif vars["drawNews"].scroll < -183 then
- vars["drawNews"].scroll = -183
- end
- Sprint("Patch 2.5", 1, 3+vars["drawNews"].scroll)
- Sprint("---------", 1, 4+vars["drawNews"].scroll)
- Sprint("1.NEW FEATURES", 3, 6+vars["drawNews"].scroll)
- local ypos = printWrapped(Splitter("- If you are using ComputerCraft Version 1.64 or higher, the turtle won't determine whether to mine a block or not by comparing it to the Ignor-slots but by comparing it with the new Ignor-list, which you can add blocks to. This is not only easier and more flexible but also a lot faster."), 5, 7+vars["drawNews"].scroll, w-5, " ")
- ypos = printWrapped(Splitter("- If you want to, the turtle will now throw away items contained on the Ignor-list."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- The decision whether to empty the inventory into a chest, also takes the length of the lateral tunnel into account now, to prevent the loss of items."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Torches will now be placed immediatly after digging the tunnel and not only after searching through the tunnel, to prevent mobspawns."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Torches will now be placed under all circumstances, even if a block for the torch to hold on to has to be placed."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- As soon as torch-slots become free because all its torches have been placed, it changes to an empty slot now, which makes it available for ores."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- The program wont throw an error and terminate, when it doesn't have blocks it wants to place, it simply doesn't place them."), 5, ypos+1, w-5, " ")
- Sprint("2.OPTIMIZATIONS", 3, ypos+2)
- ypos = printWrapped(Splitter("- The turtle will also search right and left at the very first two blocks of the tunnel, just in case you are lazy."), 5, ypos+3, w-5, " ")
- ypos = printWrapped(Splitter("- When you decide to use no chest, the chest-slot will now be converted to an empty slot, available as inventory."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- The floor will now be placed after digging out ores, so that there will definitly be no holes in the ground."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- The inventory will now be cleared after finishing."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Optimized the dig() function to run faster, increasing the overall speed of the program drasticly."), 5, ypos+1, w-5, " ")
- Sprint("3.Bug fixes", 3, ypos+2)
- ypos = printWrapped(Splitter("- There was a 25% chance that the block a torch was just placed on gets destroyed a second after, and thereby losing the torch."), 5, ypos+3, w-5, " ")
- ypos = printWrapped(Splitter("- In rare cases when selected normal chest, the turtle would try to return to its chest after the program had finished, resulting in the turtle vanishing to Australia."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Asking for fuel and taking that fuel wasn't always sync."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- The turtle would sometimes put the coal it needs to fuel itself into the chest."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- When a tunnellength <= 4 was chosen the turtle placed way too much torches."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Many variables weren't refreshed after changing some options, messing up the preparation page."), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- When running out of fuel the turtle would think that it encountered an obstacle, constantly digging and hitting the air in front."), 5, ypos+1, w-5, " ")
- Sprint("Patch 2.4", 1, ypos+2)
- Sprint("---------", 1, ypos+3)
- Sprint("1.NEW FEATURES", 3, ypos+5)
- ypos = printWrapped(Splitter("- Option to place a floor, if needed"), 5, ypos+6, w-5, " ")
- ypos = printWrapped(Splitter("- Option to change language. Currently available: english, german"), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Added a scrollbar to the options page, too"), 5, ypos+1, w-5, " ")
- Sprint("2.OPTIMIZATIONS", 3, ypos+2)
- ypos = printWrapped(Splitter("- The positions of the Buttons are determined more intelligent now, therefore being evenly spaced on every possible monitor size"), 5, ypos+3, w-5, " ")
- ypos = printWrapped(Splitter("- The structure of code is more centralized now, which results in faster processing and less blocked storage"), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- The Buttons of the options page won't slide up anymore when there is enough space, was a stupid feature anyways..."), 5, ypos+1, w-5, " ")
- Sprint("3.Bug fixes", 3, ypos+2)
- ypos = printWrapped(Splitter("- When more than 12 stacks torches were needed the ignore slots were overwritten, and wouldn't reset even when the options were changed to need less torches"), 5, ypos+3, w-5, " ")
- ypos = printWrapped(Splitter("- Fixed a bug that caused the turtle to claim having found an ore, even though it had not"), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Fixed a bug where the turtle would place torches at wrong positions when the options were changed before start"), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- Everytime after placing a torch the turtle would freeze for a few seconds (related to the bug above), this precious time is being saved now"), 5, ypos+1, w-5, " ")
- Sprint("Patch 2.3", 1, ypos+2)
- Sprint("---------", 1, ypos+3)
- Sprint("1.LAYOUT", 3, ypos+5)
- ypos = printWrapped(Splitter("- Popup on execution in case of Errors"), 5, ypos+6, w-5, " ")
- ypos = printWrapped(Splitter("- Tiny optical improvement on the scrollbar"), 5, ypos+1, w-5, " ")
- Sprint("2.NEW FEATURES", 3, ypos+2)
- ypos = printWrapped(Splitter("- Option to make the turtle place the floor when it's missing"), 5, ypos+3, w-5, " ")
- ypos = printWrapped(Splitter("- Captions in the startmenu are visible for at least 5 seconds now"), 5, ypos+1, w-5, " ")
- Sprint("3.Bug fixes", 3, ypos+2)
- ypos = printWrapped(Splitter("- Autofuel would always refuel 5 coal, no matter how much was needed"), 5, ypos+3, w-5, " ")
- ypos = printWrapped(Splitter("- Options sometimes couldn't be selected or the layout got ugly"), 5, ypos+1, w-5, " ")
- ypos = printWrapped(Splitter("- In the startmenu the displayed amount of necessary torches was wrong"), 5, ypos+1, w-5, " ")
- Sprint("Patch 2.2", 1, ypos+2)
- Sprint("---------", 1, ypos+3)
- Sprint("1.NEW LAYOUT", 3, ypos+5)
- ypos = printWrapped(Splitter("- The awesome update window!"), 5, ypos+6, w-6, " ")
- ypos = printWrapped(Splitter("-> Anti-Annoying-Checkbox ;)"), 7, ypos+1, w-8, " ")
- ypos = printWrapped(Splitter("- This awesome news window!"), 5, ypos+1, w-6, " ")
- ypos = printWrapped(Splitter("-> Very functional scrollbar (mouse_wheel, arrow-keys or arrow-buttons can be used)"), 7, ypos+1, w-8, " ")
- Sprint("2.NEW FEATURES", 3, ypos+2)
- ypos = printWrapped(Splitter("- Favorite options are now savable"), 5, ypos+3, w-6, " ")
- ypos = printWrapped(Splitter("- There is a new function that, when activated, places torches automatically: Perfectly spaced so no mobs can spawn!!!"), 5, ypos+1, w-6, " ")
- ypos = printWrapped(Splitter("- Torches on the main floor are placed instantly now, to prevent mobs from spawning"), 5, ypos+1, w-6, " ")
- Sprint("3.Bug fixes", 3, ypos+2)
- ypos = printWrapped(Splitter("- Putting wrong items into a torchslot resulted in a wrong Errormessage"), 5, ypos+3, w-6, " ")
- ypos = printWrapped(Splitter("- When normal chest was selected, the program crashed trying to deploy the chest"), 5, ypos+1, w-6, " ")
- printLeft(string.rep(" ", w-2), h)
- printCentered(">Ok<", h)
- printLine(w, 3, h, "^", "v")
- drawHeader()
- end
- function drawHome(event, p1, p2, p3)
- for i = 1, 3 do
- printCentered(lang.layout(variables.language, i+8), round((h-5)*(i/4), "u")+i+2)
- end
- printCentered(string.rep("-", #lang.layout(variables.language, select+8)), round((h-5)*(select/4), "u")+select+3)
- end
- function drawStart(event, p1, p2, p3)
- --Fuellevel
- if turtle.getFuelLevel ~= "unlimited" then
- MoveObjects(3, 2)
- printLeft(lang.layout(variables.language, 12), objects[3])
- if variables.Autofuel then
- fuelLevel = turtle.getFuelLevel()
- if fuelLevel < 3*FuelDemand/variables.quantity then
- Fuellevel = "low"
- errors[8] = true
- printCentered(lang.layout(variables.language, 13), objects[3])
- elseif fuelLevel >= FuelDemand then
- Fuellevel = "perfect"
- errors[8] = false
- elseif fuelLevel > FuelDemand*0.5 then
- Fuellevel = "ready"
- errors[8] = false
- else
- Fuellevel = "risky"
- errors[8] = false
- end
- else
- if fuelLevel >= FuelDemand*1.5 then
- Fuellevel = "perfect"
- elseif fuelLevel >= FuelDemand*1 then
- Fuellevel = "ready"
- else
- Fuellevel = "low"
- printCentered(lang.layout(variables.language, 13), objects[3])
- end
- end
- if help[1] == false then
- help[1] = fuelLevel
- end
- if Color() then
- if Fuellevel == "perfect" then
- term.setBackgroundColor(colors.lime)
- elseif Fuellevel == "ready" or Fuellevel == "risky" then
- term.setBackgroundColor(colors.yellow)
- elseif Fuellevel == "low" then
- term.setBackgroundColor(colors.red)
- end
- printRight(fuelLevel.."/"..FuelDemand, objects[3])
- term.setBackgroundColor(colors.black)
- else
- if Fuellevel == "perfect" then
- printRight("+ "..fuelLevel.."/"..FuelDemand, objects[3])
- elseif Fuellevel == "ready" or Fuellevel == "risky" then
- printRight("+/- "..fuelLevel.."/"..FuelDemand, objects[3])
- elseif Fuellevel == "low" then
- printRight("- "..fuelLevel.."/"..FuelDemand, objects[3])
- end
- end
- else
- MoveObjects(3, 1)
- end
- --Torches
- local TorchAmount = 0
- ErrorSlot = 0
- for i = 1, #slots do
- if slots[i] == "T" then
- if ItemCount("minecraft:torch", i) ~= false then
- TorchAmount = TorchAmount + ItemCount("minecraft:torch", i)
- else
- ErrorSlot = i
- end
- end
- end
- if ErrorSlot ~= 0 then
- errors[1] = true
- else
- errors[1] = false
- end
- if TorchDemand ~= 0 then
- MoveObjects(4, 2)
- printLeft(lang.layout(variables.language, 14), objects[4])
- if TorchAmount < TorchDemand then
- Check.torch = false
- if Color() then
- term.setBackgroundColor(colors.red)
- end
- else
- Check.torch = true
- if Color() then
- term.setBackgroundColor(colors.lime)
- end
- end
- printRight(TorchAmount.."/"..TorchDemand, objects[4])
- if Check.torch == false then
- errors[7] = true
- else
- errors[7] = false
- end
- term.setBackgroundColor(colors.black)
- else
- MoveObjects(4, 1)
- errors[7] = false
- end
- --Chest
- errors[2] = false
- errors[3] = false
- errors[4] = false
- errors[5] = false
- errors[6] = false
- Check.chest = false
- if variables.chestSelect == 1 then
- MoveObjects(5, 2)
- printLeft(lang.layout(variables.language, 15), objects[5])
- if Version < 1.64 then
- if turtle.getItemCount(chestSlot) == 0 then
- errors[4] = true
- else
- Check.chest = true
- end
- else
- if ItemCount("minecraft:ender_chest", chestSlot) ~= false and ItemCount("minecraft:ender_chest", chestSlot) > 0 then
- errors[2] = true
- elseif ItemCount("EnderStorage:enderChest", chestSlot) == false then
- errors[3] = true
- elseif ItemCount("EnderStorage:enderChest", chestSlot) == 0 then
- errors[4] = true
- else
- Check.chest = true
- end
- end
- elseif variables.chestSelect == 2 then
- MoveObjects(5, 2)
- printLeft(lang.layout(variables.language, 18), objects[5])
- if ItemCount("minecraft:chest", chestSlot) == false then
- errors[5] = true
- elseif ItemCount("minecraft:chest", chestSlot) == 0 then
- errors[6] = true
- else
- Check.chest = true
- end
- else
- Check.chest = true
- MoveObjects(5, 1)
- end
- if Check.chest == false then
- if Color() then
- term.setBackgroundColor(colors.red)
- end
- printRight(lang.layout(variables.language, 16), objects[5])
- else
- if Color() then
- term.setBackgroundColor(colors.lime)
- end
- printRight(lang.layout(variables.language, 17), objects[5])
- end
- term.setBackgroundColor(colors.black)
- --Autofuel
- if variables.Autofuel == true then
- MoveObjects(6, 2)
- printLeft(lang.layout(variables.language, 19), objects[6])
- term.setBackgroundColor(colors.lime)
- printRight(lang.layout(variables.language, 17), objects[6])
- term.setBackgroundColor(colors.black)
- if help[4] == false then
- help[4] = turtle.getItemCount(AutofuelSlot)
- end
- else
- MoveObjects(6, 1)
- end
- printLeft(string.rep("-", w), objects[7])
- --Inventory
- if Version < 1.64 then
- for i = 1, #slots do
- if slots[i] == "I" then
- slots[i] = "_"
- end
- end
- for i = 1, variables.ignor do
- slots[i] = "I"
- end
- end
- for k, v in ipairs(SlotCalculator("T", "empty")) do
- slots[v] = "_"
- end
- local stupid = SlotCalculator("_", "empty")
- for k, v in ipairs(stupid) do
- if k > #stupid-math.ceil(TorchDemand/64) then
- slots[v] = "T"
- end
- end
- notificationCenter()
- printRight("|"..slots[1].."|"..slots[2].."|"..slots[3].."|"..slots[4].."|", objects[8])
- printRight("|"..slots[5].."|"..slots[6].."|"..slots[7].."|"..slots[8].."|", objects[9])
- printRight("|"..slots[9].."|"..slots[10].."|"..slots[11].."|"..slots[12].."|", objects[10])
- printRight("|"..slots[13].."|"..slots[14].."|"..slots[15].."|"..slots[16].."|", objects[11])
- if objects[11] < 12 then
- printLeft(string.rep("-", w), 12)
- end
- --Buttons
- if select == 1 then
- printB({">"..lang.layout(variables.language, 20).."<", " "..lang.layout(variables.language, 10).." ", " "..lang.layout(variables.language, 21).." "}, objects[13])
- elseif select == 2 then
- printB({" "..lang.layout(variables.language, 20).." ", ">"..lang.layout(variables.language, 10).."<", " "..lang.layout(variables.language, 21).." "}, objects[13])
- elseif select == 3 then
- printB({" "..lang.layout(variables.language, 20).." ", " "..lang.layout(variables.language, 10).." ", ">"..lang.layout(variables.language, 21).."<"}, objects[13])
- end
- --Action
- if fuelLevel < 3*FuelDemand/variables.quantity then
- local FuelAmount = math.ceil((3*FuelDemand/variables.quantity-fuelLevel)/80)
- for i = 1, #SlotCalculator("_", "minecraft:coal") do
- turtle.select(SlotCalculator("_", "minecraft:coal")[i])
- local output = refuel(FuelAmount, true)
- if output == true then
- errors[8] = false
- Fuellevel = "risky"
- else
- FuelAmount = FuelAmount - output
- end
- end
- end
- end
- function drawOptions(event, p1, p2, p3)
- if focus == 100 then
- calculateFuelDemand()
- TorchCalculator()
- if vars["drawOptions"].saved == true and select == 3 then
- select = 2
- end
- end
- if event == "mouse_scroll" then
- if focus == 100 then
- vars["drawOptions"].scroll = vars["drawOptions"].scroll - p1
- elseif focus == 13+vars["drawOptions"].scroll+vars["drawOptions"].shift and ((p1 < 0 and vars["drawOptions"].scroll2 < 0) or (p1 >= 0 and h < vars["drawOptions"].ypos)) then
- vars["drawOptions"].scroll2 = vars["drawOptions"].scroll2 - p1
- end
- elseif event == "mouse_click" and p1 == 1 and focus == 100 then
- if p2 == w then
- if p3 == 3 then
- vars["drawOptions"].scroll = vars["drawOptions"].scroll + 1
- elseif p3 == h then
- vars["drawOptions"].scroll = vars["drawOptions"].scroll - 1
- end
- else
- focus = p3
- if focus > 14+vars["drawOptions"].shift+vars["drawOptions"].shift2 or focus > h-3 or focus < 3 then
- focus = 100
- end
- end
- elseif event == "key" then
- if p1 == 28 and focus ~= 0 then
- vars["drawOptions"].saved = false
- focus = 100
- elseif p1 == 208 and focus == 100 then
- vars["drawOptions"].scroll = vars["drawOptions"].scroll - 1
- elseif p1 == 200 and focus == 100 then
- vars["drawOptions"].scroll = vars["drawOptions"].scroll + 1
- else
- if variables.torches == false then
- if focus == 8+vars["drawOptions"].scroll then
- if p1 == 203 and variables.mainTorches == false then
- variables.mainTorches = true
- elseif p1 == 205 and variables.mainTorches == true then
- variables.mainTorches = false
- end
- end
- end
- vars["drawOptions"].shift2 = 0
- if Version >= 1.64 then
- if focus == 14+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- if p1 == 203 and variables.trash == false then
- variables.trash = true
- elseif p1 == 205 and variables.trash == true then
- variables.trash = false
- end
- end
- else
- vars["drawOptions"].shift2 = vars["drawOptions"].shift2-1
- end
- if focus == 3+vars["drawOptions"].scroll then
- if p1 == 203 and variables.language == "de" then
- variables.language = "en"
- elseif p1 == 205 and variables.language == "en" then
- variables.language = "de"
- end
- elseif focus == 4+vars["drawOptions"].scroll then
- if p1 == 203 and variables.tunnelspace == 4 then
- variables.tunnelspace = 3
- elseif p1 == 205 and variables.tunnelspace == 3 then
- variables.tunnelspace = 4
- end
- elseif focus == 7+vars["drawOptions"].scroll then
- if p1 == 203 and variables.chestSelect > 1 then
- variables.chestSelect = variables.chestSelect - 1
- elseif p1 == 205 and variables.chestSelect < #chest then
- variables.chestSelect = variables.chestSelect + 1
- end
- for k, v in ipairs(chest) do
- if k == variables.chestSelect then
- v = true
- else
- v = false
- end
- end
- elseif focus == 8+vars["drawOptions"].scroll then
- if p1 == 203 and variables.torches == false then
- variables.torches = true
- elseif p1 == 205 and variables.torches == true then
- variables.torches = false
- end
- elseif focus == 11+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- if p1 == 203 and variables.Autofuel == false then
- variables.Autofuel = true
- elseif p1 == 205 and variables.Autofuel == true then
- variables.Autofuel = false
- end
- elseif focus == 12+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- if p1 == 203 and variables.floor == false then
- variables.floor = true
- elseif p1 == 205 and variables.floor == true then
- variables.floor = false
- end
- elseif focus == 13+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- if p1 == 200 and vars["drawOptions"].scroll2 < 0 then
- vars["drawOptions"].scroll2 = vars["drawOptions"].scroll2+1
- elseif p1 == 208 and h < vars["drawOptions"].ypos then
- vars["drawOptions"].scroll2 = vars["drawOptions"].scroll2-1
- elseif Version >= 1.64 then
- if p1 == 57 or p1 == 14 then
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- for k, v in ipairs(variables.ignor) do
- if v == data.name then
- table.remove(variables.ignor, k)
- end
- end
- if p1 == 57 then
- table.insert(variables.ignor, data.name)
- end
- end
- end
- end
- end
- end
- end
- end
- if vars["drawOptions"].scroll > 0 then
- vars["drawOptions"].scroll = 0
- elseif vars["drawOptions"].scroll < -(4+vars["drawOptions"].shift+vars["drawOptions"].shift2) then
- vars["drawOptions"].scroll = -(4+vars["drawOptions"].shift+vars["drawOptions"].shift2)
- end
- if variables.torches == false then
- if focus == 9+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 31), focus)
- if variables.mainTorches == true then
- printRight(">"..lang.layout(variables.language, 29).."< "..lang.layout(variables.language, 30).." ", focus)
- else
- printRight(lang.layout(variables.language, 29).." >"..lang.layout(variables.language, 30).."<", focus)
- end
- elseif focus == 10+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 32), focus)
- term.setCursorPos(w-2, focus)
- variables.lateralTorches = tonumber(read())
- term.clear()
- drawHeader()
- return drawOptions("key", 28)
- end
- vars["drawOptions"].shift = 0
- else
- vars["drawOptions"].shift = -2
- end
- if Version >= 1.64 then
- if focus == 14+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- printLeft(lang.layout(variables.language, 39), focus)
- if variables.trash == true then
- printRight(">"..lang.layout(variables.language, 29).."< "..lang.layout(variables.language, 30).." ", focus)
- else
- printRight(lang.layout(variables.language, 29).." >"..lang.layout(variables.language, 30).."<", focus)
- end
- end
- end
- if focus == 3+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 34), focus)
- if variables.language == "en" then
- printRight(">en< de ", focus)
- else
- printRight("en >de<", focus)
- end
- elseif focus == 4+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 22), focus)
- if variables.tunnelspace == 3 then
- printRight(">2< 3 ", focus)
- else
- printRight("2 >3<", focus)
- end
- elseif focus == 5+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 23), focus)
- term.setCursorPos(w-2, focus)
- variables.quantity = tonumber(read())
- term.clear()
- drawHeader()
- return drawOptions("key", 28)
- elseif focus == 6+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 24), focus)
- term.setCursorPos(w-2, focus)
- variables.length = tonumber(read())
- term.clear()
- drawHeader()
- return drawOptions("key", 28)
- elseif focus == 7+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 18), focus)
- slots[16] = "C"
- if variables.chestSelect == 1 then
- printRight(">"..lang.layout(variables.language, 25).."< "..lang.layout(variables.language, 26).." "..lang.layout(variables.language, 27).." ", focus)
- elseif variables.chestSelect == 2 then
- printRight(lang.layout(variables.language, 25).." >"..lang.layout(variables.language, 26).."< "..lang.layout(variables.language, 27).." ", focus)
- else
- printRight(lang.layout(variables.language, 25).." "..lang.layout(variables.language, 26).." >"..lang.layout(variables.language, 27).."<", focus)
- if slots[16] == "C" then
- slots[16] = "_"
- end
- end
- elseif focus == 8+vars["drawOptions"].scroll then
- printLeft(lang.layout(variables.language, 28), focus)
- if variables.torches == true then
- printRight(">"..lang.layout(variables.language, 29).."< "..lang.layout(variables.language, 30).." ", focus)
- else
- printRight(" "..lang.layout(variables.language, 29).." >"..lang.layout(variables.language, 30).."<", focus)
- end
- elseif focus == 11+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- printLeft(lang.layout(variables.language, 19), focus)
- if variables.Autofuel == true then
- printRight(">"..lang.layout(variables.language, 29).."< "..lang.layout(variables.language, 30).." ", focus)
- else
- printRight(lang.layout(variables.language, 29).." >"..lang.layout(variables.language, 30).."<", focus)
- end
- elseif focus == 12+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- printLeft(lang.layout(variables.language, 33), focus)
- if variables.floor == true then
- printRight(">"..lang.layout(variables.language, 29).."< "..lang.layout(variables.language, 30).." ", focus)
- else
- printRight(lang.layout(variables.language, 29).." >"..lang.layout(variables.language, 30).."<", focus)
- end
- elseif focus == 13+vars["drawOptions"].scroll+vars["drawOptions"].shift then
- if Version >= 1.64 then
- printLeft(lang.layout(variables.language, 36), 3)
- local ypos = printWrapped(textutils.unserialize(string.gsub(textutils.serialize(variables.ignor), "minecraft:(%a+)", function(q) return q.."," end)), 1, 4, w)
- vars["drawOptions"].ypos = printWrapped(Splitter(lang.layout(variables.language, 37, label)), 1, ypos+2+vars["drawOptions"].scroll2, w-1)
- for i = 1, ypos+1 do
- printLeft(string.rep(" ", w), i)
- end
- drawHeader()
- printLeft(lang.layout(variables.language, 36), 3)
- printWrapped(textutils.unserialize(string.gsub(textutils.serialize(variables.ignor), "minecraft:(%a+_*%a*)", function(q) return q.."," end)), 1, 4, w)
- printLine(w, ypos+2, h, "^", "v")
- else
- printLeft(lang.layout(variables.language, 38), focus)
- term.setCursorPos(w-2, focus)
- variables.ignor = tonumber(read())
- term.clear()
- drawHeader()
- return drawOptions("key", 28)
- end
- elseif focus == 100 then
- printLeft(lang.layout(variables.language, 34), 3+vars["drawOptions"].scroll)
- printLeft(lang.layout(variables.language, 22), 4+vars["drawOptions"].scroll)
- printLeft(lang.layout(variables.language, 23), 5+vars["drawOptions"].scroll)
- printLeft(lang.layout(variables.language, 24), 6+vars["drawOptions"].scroll)
- printLeft(lang.layout(variables.language, 18), 7+vars["drawOptions"].scroll)
- printLeft(lang.layout(variables.language, 28), 8+vars["drawOptions"].scroll)
- if variables.torches == false then
- printLeft(lang.layout(variables.language, 31), 9+vars["drawOptions"].scroll)
- printLeft(lang.layout(variables.language, 32), 10+vars["drawOptions"].scroll)
- end
- printLeft(lang.layout(variables.language, 19), 11+vars["drawOptions"].scroll+vars["drawOptions"].shift)
- printLeft(lang.layout(variables.language, 33), 12+vars["drawOptions"].scroll+vars["drawOptions"].shift)
- printLeft("#"..lang.layout(variables.language, 36), 13+vars["drawOptions"].scroll+vars["drawOptions"].shift)
- printLeft(lang.layout(variables.language, 39), 14+vars["drawOptions"].scroll+vars["drawOptions"].shift)
- printRight(variables.language, 3+vars["drawOptions"].scroll, 1)
- printRight(tostring(variables.tunnelspace-1), 4+vars["drawOptions"].scroll, 1)
- printRight(tostring(variables.quantity), 5+vars["drawOptions"].scroll, 1)
- printRight(tostring(variables.length), 6+vars["drawOptions"].scroll, 1)
- printRight(translate(chest[tonumber(variables.chestSelect)], "layout"), 7+vars["drawOptions"].scroll, 1)
- printRight(translate(tostring(variables.torches), "layout"), 8+vars["drawOptions"].scroll, 1)
- if variables.torches == false then
- printRight(translate(tostring(variables.mainTorches), "layout"), 9+vars["drawOptions"].scroll, 1)
- printRight(tostring(variables.lateralTorches), 10+vars["drawOptions"].scroll, 1)
- end
- printRight(translate(tostring(variables.Autofuel), "layout"), 11+vars["drawOptions"].scroll+vars["drawOptions"].shift, 1)
- printRight(translate(tostring(variables.floor), "layout"), 12+vars["drawOptions"].scroll+vars["drawOptions"].shift, 1)
- if Version >= 1.64 then
- printRight(tostring(#variables.ignor-4), 13+vars["drawOptions"].scroll+vars["drawOptions"].shift, 1)
- else
- printRight(tostring(variables.ignor), 13+vars["drawOptions"].scroll+vars["drawOptions"].shift, 1)
- end
- printRight(translate(tostring(variables.trash), "layout"), 14+vars["drawOptions"].scroll+vars["drawOptions"].shift, 1)
- printLeft(string.rep(" ", w-1), h)
- printLeft(string.rep(" ", w-1), h-1)
- printLeft(string.rep(" ", w-1), h-2)
- printB({lang.layout(variables.language, 9), lang.layout(variables.language, 21), lang.layout(variables.language, 35)}, 12)
- if select == 1 then
- printB({string.rep("_", #lang.layout(variables.language, 9)), string.rep(" ", #lang.layout(variables.language, 21)), string.rep(" ", #lang.layout(variables.language, 35))}, 13)
- elseif select == 2 then
- printB({string.rep(" ", #lang.layout(variables.language, 9)), string.rep("_", #lang.layout(variables.language, 21)), string.rep(" ", #lang.layout(variables.language, 35))}, 13)
- else
- printB({string.rep(" ", #lang.layout(variables.language, 9)), string.rep(" ", #lang.layout(variables.language, 21)), string.rep("_", #lang.layout(variables.language, 35))}, 13)
- end
- printLine(w, 3, h, "^", "v")
- drawHeader()
- end
- end
- menu = {
- ["Update"] = {
- options = {"News", "Home"},
- orientation = "horizontal",
- draw = drawUpdate
- },
- ["News"] = {
- options = {"Home"},
- orientation = "horizontal",
- draw = drawNews
- },
- ["Home"] = {
- options = {"Start", "Options", "Quit"},
- orientation = "vertical",
- draw = drawHome
- },
- ["Start"] = {
- options = {"Go!", "Options", "Home"},
- orientation = "horizontal",
- draw = drawStart
- },
- ["Options"] = {
- options = {"Start", "Home", "Save as default"},
- orientation = "horizontal",
- draw = drawOptions
- },
- ["Popup"] = {
- options = {"Go!", "Start", "Quit"},
- orientation = "horizontal",
- draw = drawPopup
- }
- }
- -----###-----sequences-----###-----
- function Return()
- face(1)
- if #cache == 0 then
- table.remove(toDoList, #toDoList)
- return
- end
- if cache[#cache] == 5 then
- FreewayDown()
- elseif cache[#cache] == 6 then
- FreewayUp()
- else
- FreewayBack()
- direction = cache[#cache]
- end
- face(1)
- table.remove(cache, #cache)
- table.remove(toDoList, #toDoList)
- end
- function search()
- while #toDoList > 0 do
- searching = true
- toDoList[#toDoList]()
- end
- end
- function compare(direction, slotNum)
- turtle.select(slotNum)
- if direction == "down" then
- return turtle.compareDown()
- elseif direction == "up" then
- return turtle.compareUp()
- elseif direction == "front" then
- return turtle.compare()
- end
- end
- function CompareDown()
- table.remove(toDoList, #toDoList)
- if Version >= 1.64 then
- local boolean, data = turtle.inspectDown()
- if boolean then
- for k, v in pairs(variables.ignor) do
- if v == data.name then
- return
- end
- end
- else
- return
- end
- elseif turtle.detectDown() then
- for k, v in pairs(SlotCalculator("I")) do
- if compare("down", k) == true then
- return
- end
- end
- else
- return
- end
- turtle.select(SlotCalculator("_", "empty")[1])
- digDown()
- FreewayDown()
- table.insert(cache, 6)
- CompareAll(CompareUp)
- end
- function CompareUp()
- table.remove(toDoList, #toDoList)
- if Version >= 1.64 then
- local boolean, data = turtle.inspectUp()
- if boolean then
- for k, v in pairs(variables.ignor) do
- if v == data.name then
- return
- end
- end
- else
- return
- end
- elseif turtle.detectUp() then
- for k, v in pairs(SlotCalculator("I")) do
- if compare("up", k) == true then
- return
- end
- end
- else
- return
- end
- turtle.select(SlotCalculator("_", "empty")[1])
- digUp()
- FreewayUp()
- table.insert(cache, 5)
- CompareAll(CompareDown)
- end
- function CompareRight()
- Compare(4)
- end
- function CompareBack()
- Compare(3)
- end
- function CompareLeft()
- Compare(2)
- end
- function Compare(facing)
- if facing == nil then
- facing = 1
- end
- face(facing)
- table.remove(toDoList, #toDoList)
- if Version >= 1.64 then
- local boolean, data = turtle.inspect()
- if boolean then
- for k, v in pairs(variables.ignor) do
- if v == data.name then
- return
- end
- end
- else
- return
- end
- elseif turtle.detect() then
- for k, v in pairs(SlotCalculator("I")) do
- if compare("front", k) == true then
- return
- end
- end
- else
- return
- end
- turtle.select(SlotCalculator("_", "empty")[1])
- dig()
- Freeway()
- table.insert(cache, direction)
- direction = 1
- CompareAll(CompareBack)
- end
- function CompareAll(...)
- local exceptions = {...}
- table.insert(toDoList, Return)
- table.insert(toDoList, CompareDown)
- table.insert(toDoList, CompareUp)
- table.insert(toDoList, CompareRight)
- table.insert(toDoList, CompareBack)
- table.insert(toDoList, CompareLeft)
- table.insert(toDoList, Compare)
- for i = 1, #exceptions do
- for j = #toDoList, 1, -1 do
- for k, v in ipairs(exceptions) do
- if v == toDoList[j] then
- table.remove(toDoList, j)
- table.remove(exceptions, k)
- end
- end
- end
- end
- end
- function trash()
- for k, v in ipairs(SlotCalculator("_")) do
- local data = turtle.getItemDetail(v)
- for k2, v2 in pairs(variables.ignor) do
- if v2 == data.name then
- turtle.select(v)
- turtle.drop()
- end
- end
- end
- end
- function Enderchest(ok)
- if ok == nil then
- ok = false
- end
- if (#SlotCalculator("_") >= #SlotCalculator("_", "empty")-1-math.floor(variables.length/16) or ok == true) and #SlotCalculator("C", "check") ~= 0 then
- turtle.select(SlotCalculator("C", "check")[1])
- if level == 1 then
- FreewayDown()
- end
- FreewayBack()
- while not turtle.place() do
- turtle.attack()
- end
- for k, v in ipairs(SlotCalculator("_")) do
- if variables.Autofuel and ok == false and Version >= 1.64 and turtle.getItemDetail(v).name == "minecraft:coal" then
- ok = true
- else
- turtle.select(v)
- while not turtle.drop() do
- print(lang.status(variables.language, 3))
- sleep(10)
- end
- end
- end
- turtle.select(SlotCalculator("C", "empty")[1])
- dig()
- Freeway()
- turtle.select(SlotCalculator("_", "empty")[1])
- print(lang.status(variables.language, 4))
- end
- end
- function NormalChest(ok, finished)
- if ok == nil then
- ok = false
- end
- if finished then
- for k, v in ipairs(SlotCalculator("_")) do
- if turtle.getItemCount(v) > 0 then
- turtle.select(v)
- while not turtle.dropDown() and turtle.getItemCount() ~= 0 do
- print(lang.status(variables.language, 3))
- sleep(10)
- end
- end
- end
- elseif not setup and #SlotCalculator("C", "check") == 0 then
- return
- elseif #SlotCalculator("_") >= #SlotCalculator("_", "empty")-1-math.floor(variables.length/8) and #SlotCalculator("C", "check") ~= 0 then
- turn()
- if level == 1 then
- FreewayDown()
- end
- for Way_Back = 1, CrosswayAmount*variables.tunnelspace do
- Freeway()
- end
- turn()
- if not setup then
- turtle.select(SlotCalculator("C", "check")[1])
- while not turtle.placeDown() do
- digDown()
- end
- end
- setup = true
- for k, v in ipairs(SlotCalculator("_")) do
- if variables.Autofuel and ok == false and Version >= 1.64 and turtle.getItemDetail(v).name == "minecraft:coal" then
- ok = true
- elseif turtle.getItemCount(v) > 0 then
- turtle.select(v)
- while not turtle.dropDown() and turtle.getItemCount() ~= 0 do
- print(lang.status(variables.language, 3))
- sleep(10)
- end
- end
- end
- for Way_Back = 1, CrosswayAmount*variables.tunnelspace do
- Freeway()
- end
- print(lang.status(variables.language, 4))
- end
- end
- function Fuel()
- local FuelAmount = math.ceil(3*FuelDemand/variables.quantity/80)
- fuelLevel = turtle.getFuelLevel()
- if fuelLevel < 3*FuelDemand/variables.quantity then
- while true do
- while #SlotCalculator("_", "minecraft:coal") > 0 do
- turtle.select(SlotCalculator("_", "minecraft:coal")[1])
- local output = refuel(FuelAmount, true)
- if output == true then
- print(lang.status(variables.language, 5))
- return
- else
- FuelAmount = FuelAmount - output
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print(lang.status(variables.language, 6))
- write(lang.status(variables.language, 7))
- for k, v in ipairs(SlotCalculator("_", "empty")) do
- if k == #SlotCalculator("_", "empty") then
- print(v)
- else
- write(v..", ")
- end
- end
- os.pullEvent()
- end
- end
- end
- -----###-----Processing-----###-----
- function TorchCalculator()
- local Tspace
- if variables.torches == true then
- if (variables.tunnelspace == 4 and variables.length <= 8) or (variables.tunnelspace == 3 and variables.length <= 10) then
- variables.lateralTorches = 1
- else
- variables.lateralTorches = math.floor((variables.length-math.floor(16/variables.tunnelspace))/12)+1
- end
- if (variables.tunnelspace == 4 and variables.length <= 3) or (variables.tunnelspace == 3 and variables.length <= 4) then
- variables.mainTorches = true
- variables.lateralTorches = 0
- elseif (variables.tunnelspace == 4 and ((variables.length+2)%12 <= 5 or variables.length == 9)) or (variables.tunnelspace == 3 and (variables.length+1)%12 <= 5) then
- variables.mainTorches = true
- else
- variables.mainTorches = false
- end
- end
- if variables.lateralTorches >= 1 then
- if variables.mainTorches == true then
- Tspace = round((variables.length+(variables.tunnelspace-1)-variables.lateralTorches)/(variables.lateralTorches+0.5), "u")
- else
- Tspace = (variables.length+(variables.tunnelspace-1)-variables.lateralTorches)/variables.lateralTorches
- end
- if Tspace == 11 then
- maxSpace = true
- else
- maxSpace = false
- end
- local done = false
- while not done do
- torchPositions = {}
- table.insert(torchPositions, round(Tspace/2, "d")+1)
- for i = 2, variables.lateralTorches do
- table.insert(torchPositions, round(Tspace+1+torchPositions[i-1], "d"))
- end
- if torchPositions[#torchPositions] > variables.length then
- Tspace = Tspace - 0.1
- else
- done = true
- end
- end
- else
- maxSpace = false
- torchPositions = {}
- end
- TorchDemand = 2*(variables.lateralTorches*variables.quantity)
- if variables.mainTorches == true then
- TorchDemand = TorchDemand + variables.quantity
- end
- for k, v in ipairs(SlotCalculator("T", "empty")) do
- slots[v] = "_"
- end
- local stupid = SlotCalculator("_", "empty")
- for k, v in ipairs(stupid) do
- if k > #stupid-math.ceil(TorchDemand/64) then
- slots[v] = "T"
- end
- end
- end
- function calculateFuelDemand()
- if variables.chestSelect == 1 then
- FuelDemand = ((variables.length*2+variables.tunnelspace)*3+3)*variables.quantity
- elseif variables.chestSelect == 2 then
- FuelDemand = math.ceil(((variables.length*2+variables.tunnelspace)*3+2)*variables.quantity+variables.tunnelspace*(variables.quantity/2)^2)
- else
- FuelDemand = ((variables.length*2+variables.tunnelspace)*3+2)*variables.quantity
- end
- if maxSpace == true then
- FuelDemand = FuelDemand + #torchPositions
- end
- end
- -----###-----Core functions-----###-----
- function update()
- local programName = shell.getRunningProgram()
- if not fs.exists("database/OCM2/state") then
- save("database/OCM2/state", "0")
- end
- save("database/OCM2/programName", programName)
- file = fs.open("database/OCM2/state", "r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData, line)
- line = file.readLine()
- until line == nil
- file.close()
- updated = fileData[1]
- if updated == "0" then
- kill = true
- term.clear()
- print("loading...")
- shell.run("pastebin get cR9vEiTc database/OCM2/lang")
- term.clear()
- if shell.run("database/OCM2/updater") == false then
- term.clear()
- print("loading...")
- shell.run("pastebin get pknHDKNd database/OCM2/updater")
- term.clear()
- shell.run("database/OCM2/updater")
- end
- end
- end
- function getVariables()
- if fs.exists("database/OCM2/variables") then
- file = fs.open("database/OCM2/variables", "r")
- local line = Splitter(file.readLine(), " = ")
- repeat
- if line[2] == "{" then
- local str = "{"
- repeat
- local tline = file.readLine()
- if tline ~= nil then
- str = str..tline
- end
- until tline == "}"
- extVar[line[1]] = textutils.unserialize(str)
- elseif (line[1] == "ignor" and Version >= 1.64) == false then
- extVar[line[1]] = line[2]
- end
- line = Splitter(file.readLine(), " = ")
- until line == nil
- file.close()
- for k, v in pairs(extVar) do
- if type(extVar[k]) ~= "table" then
- if not tonumber(extVar[k]) then
- if extVar[k] == "true" or extVar[k] == "false" then
- extVar[k] = extVar[k] == "true"
- end
- else
- extVar[k] = tonumber(extVar[k])
- end
- end
- variables[k] = extVar[k]
- end
- end
- if fs.exists("database/OCM2/updateCheckbox/V2.5") then
- local file = fs.open("database/OCM2/updateCheckbox/V2.5", "r")
- checkbox = file.readLine() == "true"
- file.close()
- end
- if checkbox == true then
- menustate = "Home"
- else
- menustate = "Update"
- end
- calculateFuelDemand()
- TorchCalculator()
- end
- function saveVars()
- edit("database/OCM2/variables", variables)
- end
- function compStep(n)
- if n == nil then
- n = 1
- else
- n = tonumber(n)
- end
- for i = 1, n do
- turtle.select(SlotCalculator("T", "empty")[1])
- Freeway()
- if level == 0 then
- CompareAll(Compare, CompareBack, CompareUp)
- search()
- if variables.floor == true and turtle.detectDown() == false and #SlotCalculator("_", "minecraft:cobblestone") ~= 0 then
- turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
- turtle.placeDown()
- end
- turtle.select(SlotCalculator("T", "empty")[1])
- FreewayUp()
- CompareAll(Compare, CompareBack, CompareDown)
- search()
- elseif level == 1 then
- CompareAll(Compare, CompareBack, CompareDown)
- search()
- turtle.select(SlotCalculator("T", "empty")[1])
- FreewayDown()
- CompareAll(Compare, CompareBack, CompareUp)
- search()
- if variables.floor == true and turtle.detectDown() == false and #SlotCalculator("_", "minecraft:cobblestone") ~= 0 then
- turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
- turtle.placeDown()
- end
- end
- end
- end
- function mainStep(n, first)
- if n == nil then
- n = 1
- else
- n = tonumber(n)
- end
- turtle.select(SlotCalculator("_", "empty")[1])
- for i = 1, n do
- searching = false
- dig()
- Freeway()
- if level == 0 then
- if variables.floor == true and turtle.detectDown() == false and #SlotCalculator("_", "minecraft:cobblestone") ~= 0 then
- turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
- turtle.placeDown()
- end
- digUp()
- if first and i == 1 then
- CompareAll(Compare, CompareBack, CompareUp)
- else
- table.insert(toDoList, CompareDown)
- end
- search()
- FreewayUp()
- if first and i == 1 then
- CompareAll(Compare, CompareBack, CompareDown)
- else
- table.insert(toDoList, CompareUp)
- end
- search()
- elseif level == 1 then
- digDown()
- if first and i == 1 then
- CompareAll(Compare, CompareBack, CompareDown)
- else
- table.insert(toDoList, CompareUp)
- end
- search()
- if i == 2 and variables.mainTorches then
- searching = false
- while dig() == true do
- os.sleep(0.05)
- end
- end
- FreewayDown()
- if first and i == 1 then
- CompareAll(Compare, CompareBack, CompareUp)
- else
- table.insert(toDoList, CompareDown)
- end
- search()
- if variables.floor == true and turtle.detectDown() == false and #SlotCalculator("_", "minecraft:cobblestone") ~= 0 then
- turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
- turtle.placeDown()
- end
- end
- if variables.mainTorches == true then
- if i == 2 and #SlotCalculator("T", "check") ~= 0 then
- turtle.select(SlotCalculator("T", "check")[1])
- if level == 1 then
- FreewayDown()
- end
- if not turtle.placeUp() then
- FreewayUp()
- turtle.turnLeft()
- turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
- dig()
- turtle.place()
- turtle.turnRight()
- FreewayDown()
- turtle.select(SlotCalculator("T", "check")[1])
- turtle.placeUp()
- end
- for k, v in ipairs(SlotCalculator("T", "empty")) do
- slots[v] = "_"
- end
- local stupid = SlotCalculator("_", "empty")
- for k, v in ipairs(stupid) do
- if k > #stupid-math.ceil(TorchDemand/64) then
- slots[v] = "T"
- end
- end
- TorchDemand = TorchDemand - 1
- end
- end
- end
- end
- function stepAside(n)
- if n == nil then
- n = 1
- else
- n = tonumber(n)
- end
- for i = 1, n do
- searching = false
- dig()
- Freeway()
- if level == 1 then
- digDown()
- elseif level == 0 then
- if variables.floor == true and turtle.detectDown() == false and #SlotCalculator("_", "minecraft:cobblestone") ~= 0 then
- turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
- turtle.placeDown()
- end
- digUp()
- end
- end
- end
- function youJustGotLittUp(steps, func, left)
- if left == nil then
- left = false
- end
- for Steprepeat = 1, steps do
- if func == stepAside then
- func()
- end
- for k, v in ipairs(torchPositions) do
- if ((func == stepAside and variables.length-v+1 == Steprepeat) or (func == compStep and v == Steprepeat)) and #SlotCalculator("T", "check") > 0 then
- turtle.select(SlotCalculator("T", "check")[1])
- if maxSpace == true then
- if variables.mainTorches == false and left == true then
- if k%2 == #torchPositions%2 then
- if level == 1 then
- FreewayDown()
- end
- else
- if level == 0 then
- FreewayUp()
- end
- end
- else
- if k%2 == #torchPositions%2 then
- if level == 0 then
- FreewayUp()
- end
- else
- if level == 1 then
- FreewayDown()
- end
- end
- end
- end
- if level == 1 then
- turtle.placeDown()
- elseif level == 0 then
- if not turtle.placeUp() then
- FreewayUp()
- turtle.turnLeft()
- turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
- dig()
- turtle.place()
- turtle.turnRight()
- FreewayDown()
- turtle.select(SlotCalculator("T", "check")[1])
- turtle.placeUp()
- end
- end
- for k, v in ipairs(SlotCalculator("T", "empty")) do
- slots[v] = "_"
- end
- local stupid = SlotCalculator("_", "empty")
- for k, v in ipairs(stupid) do
- if k > #stupid-math.ceil(TorchDemand/64) then
- slots[v] = "T"
- end
- end
- if func == compStep then
- TorchDemand = TorchDemand - 1
- end
- turtle.select(SlotCalculator("_", "empty")[1])
- end
- end
- if func == compStep then
- if Steprepeat == variables.length then
- Freeway()
- else
- func()
- end
- end
- end
- end
- function Tunnel()
- if variables.Autofuel == true then
- Fuel()
- end
- if variables.trash == true then
- trash()
- end
- if variables.chestSelect == 1 then
- Enderchest()
- elseif variables.chestSelect == 2 then
- NormalChest()
- end
- mainStep(variables.tunnelspace, true)
- turtle.turnRight()
- youJustGotLittUp(variables.length, stepAside)
- if level == 1 then
- CompareAll(CompareBack, CompareDown)
- search()
- FreewayDown()
- CompareAll(CompareBack, CompareUp)
- else
- CompareAll(CompareBack, CompareUp)
- search()
- FreewayUp()
- CompareAll(CompareBack, CompareDown)
- end
- search()
- face(3)
- direction = 1
- youJustGotLittUp(variables.length, compStep)
- youJustGotLittUp(variables.length, stepAside, true)
- if level == 1 then
- CompareAll(CompareBack, CompareDown)
- search()
- FreewayDown()
- CompareAll(CompareBack, CompareUp)
- else
- CompareAll(CompareBack, CompareUp)
- search()
- FreewayUp()
- CompareAll(CompareBack, CompareDown)
- end
- search()
- face(3)
- direction = 1
- youJustGotLittUp(variables.length, compStep, true)
- turtle.turnLeft()
- end
- function Go()
- local startDay = os.day()
- local startTime = os.time()
- CrosswayAmount = 0
- for Tunnelrepeat = 1, variables.quantity do
- Tunnel()
- CrosswayAmount = CrosswayAmount + 1
- print(lang.status(variables.language, 8, CrosswayAmount, variables.quantity))
- end
- print(lang.status(variables.language, 9))
- turn()
- if level == 1 then
- FreewayDown()
- end
- for Way_Back = 1, variables.quantity*variables.tunnelspace do
- Freeway()
- end
- if variables.trash == true then
- trash()
- end
- if variables.chestSelect == 1 then
- Enderchest(true)
- elseif variables.chestSelect == 2 then
- NormalChest(true, true)
- end
- local endDay = os.day()
- local endTime = os.time()
- stats["time"] = (endDay-startDay)*24.000+(endTime-startTime)
- end
- function Navigation()
- table.insert(timer, os.startTimer(0.05))
- while true do
- local tempState = menustate
- local event, p1, p2, p3 = os.pullEvent()
- while (event == "timer" and p1 ~= timer[#timer]) or event == "key_up" do
- event, p1, p2, p3 = os.pullEvent()
- end
- if focus == 100 then
- basicInputHandler(menu[menustate].orientation, event, p1)
- end
- if menustate == "Quit" then
- break
- elseif menustate == "Save as default" then
- saveVars()
- vars["drawOptions"].saved = true
- menustate = "Options"
- elseif menustate == "Go!" then
- menustate = "Popup"
- local ready = true
- for i = 1, #errors do
- if errors[i] == true then
- ready = false
- end
- end
- if (Fuellevel ~= "low" and ready == true) or tempState == "Popup" then
- return Go()
- end
- end
- term.clear()
- drawHeader()
- if tempState == menustate then
- menu[menustate].draw(event, p1, p2, p3)
- else
- menu[menustate].draw()
- end
- if tempState == "Update" then
- save("database/OCM2/updateCheckbox/V2.5", checkbox)
- end
- table.insert(timer, os.startTimer(0.5))
- end
- end
- function extractStats()
- save("database/OCM2/stats", stats)
- end
- function close()
- term.clear()
- term.setCursorPos(1,1)
- if Color() then
- term.setTextColor(colors.yellow)
- print(os.version())
- term.setTextColor(colors.white)
- else
- print(os.version())
- end
- term.setCursorPos(1, 2)
- end
- -----###-----Executive-----###------
- function main()
- if kill == true then
- return
- end
- os.loadAPI("database/OCM2/lang")
- save("database/OCM2/state", "0")
- getVariables()
- Navigation()
- --extractStats()
- close()
- end
- main()
Add Comment
Please, Sign In to add comment