Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- v1.7
- -- This program should be saved to "/VeinMiner/VeinMiner.lua"
- -- Run the following commands before running this program:
- -- > pastebin get ggZ3tdXW /API/tAddOn.lua
- -- > pastebin get 0C6LyNES /VeinMiner/VeinMiner.lua
- dofile("/API/tAddOn.lua")
- function startMine()
- local function loadData(path)
- path = "/VeinMiner/" .. path .. ".txt"
- if fs.exists(path) then
- local f = fs.open(path, "r")
- local data = textutils.unserialize(f.readAll())
- f.close()
- return data
- end
- return {}
- end
- local tasks = loadData("tasks")
- local whitelist = loadData("whitelist")
- local blacklist = loadData("blacklist")
- local function saveData(data, path)
- local f = fs.open("/VeinMiner/" .. path .. ".txt", "w")
- f.write(textutils.serialise(data))
- f.close()
- end
- local function checkList(block, list)
- for i = 1, #list do
- if block.name == list[i].name and textutils.serialize(block.state) == textutils.serialize(list[i].state) then
- return true
- end
- end
- return false
- end
- local function queueInspect()
- table.insert(tasks, 1, "inspectDown")
- table.insert(tasks, 1, "inspectUp")
- for i = 1, 4 do
- table.insert(tasks, 1, "right")
- table.insert(tasks, 1, "inspectForward")
- end
- end
- local function isDir(dir)
- if dir == "up" then return true
- elseif dir == "down" then return true
- elseif dir == "forward" then return true
- elseif dir == "back" then return true
- elseif dir == "left" then return true
- elseif dir == "right" then return true
- else error("Invalid direction", 3) end
- end
- local function revDir(dir)
- if isDir(dir) then
- if dir == "up" then return "down"
- elseif dir == "down" then return "up"
- elseif dir == "forward" then return "back"
- elseif dir == "back" then return "forward"
- elseif dir == "left" then return "right"
- elseif dir == "right" then return "left"
- else error("Invalid direction", 2) end
- end
- end
- local function mineBlock(block, dir)
- local whiteCheck = checkList(block, whitelist)
- local blackCheck = checkList(block, blacklist)
- if whiteCheck then
- table.remove(tasks, 1)
- table.insert(tasks, 1, revDir(dir))
- queueInspect()
- table.insert(tasks, 1, dir)
- saveData(tasks, "tasks")
- elseif blackCheck then
- table.remove(tasks, 1)
- saveData(tasks, "tasks")
- else
- print("\nAdd "..block.name.." to the whitelist?")
- print('Press "Y" or "N"\n')
- while true do
- local _, key = os.pullEvent("key")
- if key == keys.y then
- table.insert(whitelist,1,{name = block.name, state = block.state})
- saveData(whitelist, "whitelist")
- return
- elseif key == keys.n then
- table.insert(blacklist,1,{name = block.name, state = block.state})
- saveData(blacklist, "blacklist")
- return
- end
- end
- end
- end
- local function inspectBlock(dir)
- if isDir(dir) then
- if dir == "up" then return turtle.inspectUp()
- elseif dir == "down" then return turtle.inspectDown()
- elseif dir == "forward" then return turtle.inspect()
- else return false end
- end
- end
- queueInspect()
- repeat
- local invSpace = true
- local xPos, yPos = term.getCursorPos()
- term.setCursorPos(1, 1)
- term.clearLine()
- write("Remaining Tasks: "..#tasks)
- term.setCursorPos(xPos, yPos)
- repeat
- local invCheck = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- invCheck = invCheck + 1
- end
- end
- if invSpace and invCheck == 16 then
- print("\nOut of inventory space.\n")
- invSpace = false
- end
- sleep()
- until invCheck < 16
- if tasks[1]:sub(1, 7) == "inspect" then
- local dir = string.lower(tasks[1]:sub(8))
- local check, block = inspectBlock(dir)
- if check then mineBlock(block, dir)
- else
- table.remove(tasks, 1)
- saveData(tasks, "tasks")
- end
- elseif isDir(tasks[1]) then
- local dir = tasks[1]
- local check, block = inspectBlock(dir)
- tMove[dir]()
- if check then
- print("Mined " .. block.name .. ".")
- end
- table.remove(tasks, 1)
- saveData(tasks, "tasks")
- end
- until #tasks == 0
- fs.delete("/VeinMiner/tasks.txt")
- end
- if arg[1] == "startMine" then
- startMine()
- elseif arg[1] == "clearTasks" and fs.exists("/VeinMiner/tasks.txt") then
- fs.delete("/VeinMiner/tasks.txt")
- end
- --[[ Changelog
- 2025/12/13 - v1.7:
- • Swapped task order so inspecting forward is done first.
- 2025/12/12 - v1.6:
- • Added arguments that can be passed to the program without needing to run
- another program.
- • "startMine" will start the vein mining program.
- • "clearTasks" will delete the save file for queued tasks.
- • Added comment with command that can be copy pasted to download this
- program.
- 2025/12/08 - v1.5:
- I don't know what the hell happened since the last time I updated this program.
- This hasn't been edited since the last time I updated it but it feels like
- someone is messing with me with how messed up this is. This was all working fine
- last time I used it, but now all of a sudden all of this code was wrong.
- • Fixed typo at line 109: 'queueInpsect()' → 'queueInspect()'.
- • Fixed missing argument for 'isDir(dir)' in 'inspectBlock(dir)'.
- • Fixed missing argument for 'isDir(dir)' in 'revDir(dir)'.
- • Fixed file path string being wrong when loading data.
- • Fixed turtle only mining forward when not inspecting forward at line 136.
- • Fixed queueInspect adding tasks to the end of the tasks list instead of the
- start.
- Maybe I trolled myself somehow.
- 2023/05/04 - v1.4:
- • Fixed a bug caused by a typo in the isDir function.
- 2023/04/18 - v1.3:
- • Code has been cleaned up a lot. Similar instructions have been grouped into
- functions.
- • 'dofile()' can be used to do the same thing as 'require()' and is backwards
- compatible.
- • Added a requirement for a new API to control turtle movement.
- • Task list, whitelist, and blacklist are now saved to '/VeinMiner/'. This
- program should also be saved to this directory.
- • Reformatted the changelog to comply with the formatting convention used in my
- other programs.
- 2022/06/20 - v1.2:
- • Encapsulated the program into a function that can be called in other programs
- when using os.loadAPI() or require().
- • Blacklist and Whitelist now only saves the blocks' name and state, ignoring
- nbt tags.
- ]]
Advertisement
Add Comment
Please, Sign In to add comment