Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local facing = "N" -- variables ( don't change pls =[ )
- local whitelist = {"minecraft:coal_ore", "", "", "", "", "", "", "", "", "", "", ""}
- local position = {0, 0, 0}
- local nodes = {}
- local moveHistory = {}
- local NNode = false
- local loc
- local lastTorch = 10
- local install = false
- local minerPath = "miner.lua"
- local whitelistPath = "programs/assetsMiner/whitelist"
- local uninstallPath = "programs/assetsMiner/uninstaller.lua"
- local assetsPath = "programs/assetsMiner/"
- local scroll = 1
- local distance = 50
- local key
- local event
- local points = 1
- local chestD = 0
- -- 1 refueling and misc
- -- 1.1 refueling
- function refuel()
- if turtle.getFuelLevel() < 10 then
- for i=1,16 do
- local itemD = turtle.getItemDetail(i)
- if not (itemD==nil) then
- if itemD.name=="minecraft:coal" or itemD.name=="minecraft:coal_block" or itemD.name=="minecraft:charcoal" or itemD.name=="minecraft:lava_bucket" then
- while turtle.getFuelLevel() < 1000 and itemD.count > 0 do
- turtle.select(i)
- turtle.refuel()
- end
- turtle.select(1)
- break
- end
- end
- end
- end
- end
- -- 1.2 torch placing
- function placeTorch()
- lastTorch = lastTorch+1
- if lastTorch>=11 then
- lastTorch=0
- for i=1,16 do
- local itemD = turtle.getItemDetail(i)
- if not (itemD==nil) then
- if itemD.name=="minecraft:torch" then
- turtle.select(i)
- South()
- turtle.place()
- North()
- turtle.select(1)
- break
- end
- end
- end
- end
- end
- function readWhitelist() -- 1.3 for reading the whitelist file
- if fs.exists("disk/whitelist") then
- local file = fs.open("disk/whitelist", "r")
- whitelist = textutils.unserialise(file.readAll())
- file.close()
- else
- local file = fs.open(whitelistPath, "r")
- whitelist = textutils.unserialise(file.readAll())
- file.close()
- end
- end
- function writeWhitelist() -- 1.4 for writing the whitelist file
- local file = fs.open(whitelistPath, "w")
- file.write(textutils.serialise(whitelist))
- file.close()
- end
- function inventoryManag()
- local filledSlots = 0
- for i=1,16 do
- if turtle.getItemCount(i)>0 then
- filledSlots = filledSlots + 1
- end
- end
- if filledSlots == 16 then
- South()
- digDown()
- downward()
- for i=1,chestD do
- forward()
- end
- local block, data = turtle.inspect()
- while not block do
- block, data = turtle.inspect()
- inventoryFull()
- end
- for i=1,16 do
- local itemD = turtle.getItemDetail(i)
- if not (itemD==nil) then
- if not(itemD.name=="minecraft:torch" or itemD.name=="minecraft:coal" or itemD.name=="minecraft:coal_block" or itemD.name=="minecraft:charcoal" or itemD.name=="minecraft:lava_bucket") then
- while turtle.getItemCount(i) > 0 do
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- turtle.select(1)
- end
- North()
- for i=1,chestD do
- forward()
- end
- upward()
- end
- end
- -- 2 movement
- -- 2.1 facing
- function North()
- if facing == "E" then
- turtle.turnLeft()
- elseif facing == "S" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing == "W" then
- turtle.turnRight()
- end
- facing = "N"
- end
- function East()
- if facing == "S" then
- turtle.turnLeft()
- elseif facing == "W" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing == "N" then
- turtle.turnRight()
- end
- facing = "E"
- end
- function South()
- if facing == "W" then
- turtle.turnLeft()
- elseif facing == "N" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing == "E" then
- turtle.turnRight()
- end
- facing = "S"
- end
- function West()
- if facing == "N" then
- turtle.turnLeft()
- elseif facing == "E" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing == "S" then
- turtle.turnRight()
- end
- facing = "W"
- end
- -- 2.2 move commands so it doesn't get confused
- function forward()
- while not turtle.forward() do
- refuel()
- turtle.attack()
- end
- end
- function upward()
- while not turtle.up() do
- refuel()
- turtle.attackUp()
- end
- end
- function downward()
- while not turtle.down() do
- refuel()
- turtle.attackDown()
- end
- end
- -- 2.3dig commands so it's gravel and sand safe
- function dig()
- while turtle.detect() do
- turtle.dig()
- miningAnimation()
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- miningAnimation()
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- miningAnimation()
- end
- end
- -- 3.0 the DFS stuff (depth first search https://en.wikipedia.org/wiki/Depth-first_search#:~:text=Depth%2Dfirst%20search%20(DFS),along%20each%20branch%20before%20backtracking.)
- function addNode(Npos) -- 3.1 adds the coords of an ore if there aren't any double's
- for i=1,#nodes do
- if sameList(Npos, nodes[i]) then
- return
- end
- end
- table.insert(nodes, #nodes+1, Npos)
- end
- function inspect() -- 3.2 checks if the turtle can see a whitelisted ore/ block
- local block, data = turtle.inspectUp()
- if block then
- for i=1,#whitelist do
- if data.name==whitelist[i] then
- addNode({position[1], position[2]+1, position[3]})
- end
- end
- end
- local block, data = turtle.inspectDown()
- if block then
- for i=1,#whitelist do
- if data.name==whitelist[i] then
- addNode({position[1], position[2]-1, position[3]})
- end
- end
- end
- North()
- miningAnimation()
- local block, data = turtle.inspect()
- if block then
- for i=1,#whitelist do
- if data.name==whitelist[i] then
- addNode({position[1]+1, position[2], position[3]})
- end
- end
- end
- East()
- miningAnimation()
- local block, data = turtle.inspect()
- if block then
- for i=1,#whitelist do
- if data.name==whitelist[i] then
- addNode({position[1], position[2], position[3]+1})
- end
- end
- end
- South()
- miningAnimation()
- local block, data = turtle.inspect()
- if block then
- for i=1,#whitelist do
- if data.name==whitelist[i] then
- addNode({position[1]-1, position[2], position[3]})
- end
- end
- end
- West()
- miningAnimation()
- local block, data = turtle.inspect()
- if block then
- for i=1,#whitelist do
- if data.name==whitelist[i] then
- addNode({position[1], position[2], position[3]-1})
- end
- end
- end
- end
- function sameList(a, b) -- 3.3 checks if 2 lists have the same value
- return textutils.serialise(a)==textutils.serialise(b)
- end
- function besidesNode() -- 3.4 checks if the turtle is beside a whitelisted ore / block
- if #nodes>0 then
- if sameList(position,{nodes[#nodes][1], nodes[#nodes][2]-1, nodes[#nodes][3]}) then
- return true, "U"
- elseif sameList(position, {nodes[#nodes][1], nodes[#nodes][2]+1, nodes[#nodes][3]}) then
- return true, "D"
- elseif sameList(position, {nodes[#nodes][1]-1, nodes[#nodes][2], nodes[#nodes][3]}) then
- return true, "N"
- elseif sameList(position, {nodes[#nodes][1], nodes[#nodes][2], nodes[#nodes][3]-1}) then
- return true, "E"
- elseif sameList(position, {nodes[#nodes][1]+1, nodes[#nodes][2], nodes[#nodes][3]}) then
- return true, "S"
- elseif sameList(position, {nodes[#nodes][1], nodes[#nodes][2], nodes[#nodes][3]+1}) then
- return true, "W"
- else
- return false
- end
- else
- return false
- end
- end
- -- 4 gui
- function whitelistEditor() -- 4.1 the whitelist gui
- if not fs.exists(whitelistPath) then
- term.clear()
- term.setCursorPos(5, 2)
- term.write("Install the necessary things?")
- term.setCursorPos(15, 5)
- term.write(" install ")
- term.setCursorPos(16, 6)
- term.write(">cancel<")
- term.setCursorPos(1, 10)
- while not fs.exists(whitelistPath) do
- event, key = os.pullEvent("key")
- if key==keys.up then
- term.clear()
- term.setCursorPos(5, 2)
- term.write("Install the necessary things?")
- term.setCursorPos(15, 5)
- term.write(">install<")
- term.setCursorPos(16, 6)
- term.write(" cancel ")
- install = true
- elseif key==keys.down then
- term.clear()
- term.setCursorPos(5, 2)
- term.write("Install the necessary things?")
- term.setCursorPos(15, 5)
- term.write(" install ")
- term.setCursorPos(16, 6)
- term.write(">cancel<")
- install = false
- elseif key==keys.enter then
- if install==true then
- local file = fs.open(whitelistPath, "w")
- file.write(textutils.serialise(whitelist))
- file.close()
- local file = fs.open(uninstallPath, "w")
- file.write('shell.run("delete '..whitelistPath..'")')
- file.write('shell.run("delete '..minerPath..'")')
- file.write('shell.run("delete '..uninstallPath..'")')
- file.close()
- elseif install==false then
- local file = fs.open(uninstallPath, "w")
- file.write('shell.run("delete '..minerPath..'")')
- file.write('shell.run("delete '..uninstallPath..'")')
- file.close()
- shell.run(uninstallPath)
- end
- end
- end
- end
- readWhitelist()
- while true do
- if key==keys.up then
- scroll = scroll-1
- elseif key==keys.down then
- scroll = scroll+1
- elseif key==keys.enter then
- end
- if scroll>14 then
- scroll=1
- elseif scroll<1 then
- scroll=14
- end
- term.setBackgroundColor(colors.gray)
- term.clear()
- term.setCursorPos(1, 13)
- term.setTextColour(colors.white)
- term.setBackgroundColor(colors.red)
- term.write(" exit ")
- term.setCursorPos(33, 13)
- term.setBackgroundColor(colors.green)
- term.write(" start ")
- for i=1,12 do
- term.setBackgroundColor(colors.gray)
- if i%2==0 then
- paintutils.drawLine(1, i, 39, i, colors.lightGray)
- term.setBackgroundColor(colors.lightGray)
- end
- term.setCursorPos(1, i)
- term.write(whitelist[i])
- end
- if scroll>0 and scroll<13 then
- paintutils.drawLine(1, scroll, 39, scroll, colors.lime)
- term.setBackgroundColor(colors.lime)
- term.setCursorPos(1, scroll)
- term.write(whitelist[scroll])
- if key==keys.enter then
- term.setCursorPos(1, scroll)
- term.clearLine(scroll)
- whitelist[scroll] = read()
- end
- end
- if scroll==13 then
- term.setCursorPos(1, 13)
- term.setBackgroundColor(colors.lime)
- term.write(" exit ")
- if key==keys.enter then
- writeWhitelist()
- os.reboot()
- end
- end
- if scroll==14 then
- term.setCursorPos(33, 13)
- term.setBackgroundColor(colors.lime)
- term.write(" start ")
- if key==keys.enter then
- return
- end
- end
- event, key = os.pullEvent("key")
- print(key)
- end
- end
- function distanceEditor() -- 4.2 menu to specify the distance menu
- key=keys.numPad9
- while true do
- if key==keys.up then
- distance = distance + 10
- elseif key==keys.down then
- distance = distance - 10
- elseif key==keys.enter then
- break
- end
- if distance<10 then
- distance=10
- end
- term.clear()
- paintutils.drawFilledBox(1, 1, 39, 19, colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(10, 3)
- term.write("specify the distance")
- term.setCursorPos(18, 4)
- term.write(">"..distance.."<")
- if distance==420 then
- term.setCursorPos(5, 7)
- term.clearLine(7)
- term.setCursorPos(8, 7)
- term.setTextColor(colors.red)
- term.write("420... nice")
- elseif distance>2000 then
- term.setCursorPos(5, 7)
- term.setTextColor(colors.red)
- term.write("why do I even try")
- elseif distance>1000 then
- term.setCursorPos(5, 7)
- term.setTextColor(colors.red)
- term.write("dude chill!!!")
- elseif distance>50 then
- term.setCursorPos(5, 7)
- term.setTextColor(colors.red)
- term.write("! caution for unloaded chunks !")
- else
- term.setCursorPos(5, 7)
- term.clearLine(7)
- end
- event, key = os.pullEvent("key")
- end
- end
- function miningAnimation() -- 4.3 a (somewhat) nice mining animation
- term.setBackgroundColor(colors.lime)
- points = points + 1
- if points>3 then
- points = 1
- end
- term.clear()
- term.setCursorPos(16, 7)
- term.write("mining")
- for i=1,points do
- term.write(".")
- end
- end
- function inventoryFull() -- 4.4 displays if your inventory is full and can't find a sotrage thingy
- paintutils.drawFilledBox(1, 1, 39, 19, colors.red)
- term.setBackgroundColor(colors.red)
- term.setCursorPos(12, 7)
- term.write("inventory full")
- end
- function finished()
- term.clear()
- paintutils.drawFilledBox(1, 1, 39, 19, colors.orange)
- term.setCursorPos(12, 7)
- term.write("finished")
- os.pullEvent()
- os.reboot()
- end
- -- 5 the main code
- whitelistEditor()
- writeWhitelist()
- distanceEditor()
- upward()
- for length=1,distance do
- digUp() --does basic mining stuff
- digDown()
- dig()
- forward()
- chestD = chestD+1
- placeTorch()
- inventoryManag()
- inspect() -- checks for whitelisted ores
- if #nodes>0 then
- while not (sameList(position, {0, 0, 0}) and #nodes==0) do
- inspect()
- NNode, loc = besidesNode()
- if NNode then
- if loc=="U" then --digs nearby nodes/ores
- digUp()
- upward()
- position[2] = position[2] + 1
- table.insert(moveHistory, #moveHistory+1, "U")
- elseif loc=="D" then
- digDown()
- downward()
- position[2] = position[2] - 1
- table.insert(moveHistory, #moveHistory+1, "D")
- elseif loc=="N" then
- North()
- dig()
- forward()
- position[1] = position[1] + 1
- table.insert(moveHistory, #moveHistory+1, "N")
- elseif loc=="E" then
- East()
- dig()
- forward()
- position[3] = position[3] + 1
- table.insert(moveHistory, #moveHistory+1, "E")
- elseif loc=="S" then
- South()
- dig()
- forward()
- position[1] = position[1] - 1
- table.insert(moveHistory, #moveHistory+1, "S")
- elseif loc=="W" then
- West()
- dig()
- forward()
- position[3] = position[3] - 1
- table.insert(moveHistory, #moveHistory+1, "W")
- end
- table.remove(nodes, #nodes)
- else
- while (not NNode) and (not sameList(position, {0, 0, 0})) do -- backtracks to last node or starting position
- NNode, loc = besidesNode()
- if moveHistory[#moveHistory] == "U" then
- downward()
- position[2] = position[2] - 1
- elseif moveHistory[#moveHistory] == "D" then
- upward()
- position[2] = position[2] + 1
- elseif moveHistory[#moveHistory] == "N" then
- South()
- forward()
- position[1] = position[1] - 1
- elseif moveHistory[#moveHistory] == "E" then
- West()
- forward()
- position[3] = position[3] - 1
- elseif moveHistory[#moveHistory] == "S" then
- North()
- forward()
- position[1] = position[1] + 1
- elseif moveHistory[#moveHistory] == "W" then
- East()
- forward()
- position[3] = position[3] + 1
- end
- table.remove(moveHistory, #moveHistory)
- NNode, loc = besidesNode()
- end
- end
- end
- end
- North()
- end
- South()
- digDown()
- downward()
- for length=1,distance do
- forward()
- end
- finished()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement