Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Vector3 = {}
- Vector3.__index = Vector3
- Vector3.__add = function(a, b)
- return Vector3.new(
- a.x + b.x,
- a.y + b.y,
- a.z + b.z
- )
- end
- Vector3.__sub = function(a, b)
- return Vector3.new(
- a.x - b.x,
- a.y - b.y,
- a.z - b.z
- )
- end
- Vector3.__eq = function(a, b)
- return a.x == b.x and a.y == b.y and a.z == b.z
- end
- Vector3.__tostring = function(self)
- return self.x .. ", " .. self.y .. ", " .. self.z
- end
- function Vector3.new(x, y, z)
- return setmetatable({
- x = x or 0,
- y = y or 0,
- z = z or 0
- }, Vector3)
- end
- function Vector3:length()
- return math.abs(self.x) + math.abs(self.y) + math.abs(self.z)
- end
- function Vector3:clone()
- return Vector3.new(self.x, self.y, self.z)
- end
- local dir = Vector3.new(0, 0, 1)
- local pos = Vector3.new()
- local pathcost = 0
- local debounce = false
- local maxSteps = 63
- local steps = 0
- local maxTunnels = 16
- local tunnels = 1
- local fuel = turtle.getFuelLevel()
- local wantedOres = {
- "minecraft:diamond_ore",
- "minecraft:gold_ore",
- "minecraft:iron_ore",
- "minecraft:lapis_ore",
- "minecraft:redstone_ore",
- "minecraft:coal_ore",
- "minecraft:emerald_ore",
- "appliedenergistics2:quartz_ore",
- "appliedenergistics2:charged_quartz_ore",
- "thermal:apatite_ore",
- "thermal:cinnabar_ore",
- "thermal:niter_ore",
- "thermal:sulfur_ore",
- "thermal:copper_ore",
- "thermal:tin_ore",
- "thermal:lead_ore",
- "thermal:silver_ore",
- "thermal:nickel_ore",
- "mekanism:osmium_ore",
- "mekanism:uranium_ore",
- "mekanism:fluorite_ore"
- }
- local inventoryWhitelist = {
- "minecraft:diamond",
- "minecraft:gold_ore",
- "minecraft:iron_ore",
- "minecraft:lapis_lazuli",
- "minecraft:redstone",
- "minecraft:coal",
- "minecraft:emerald",
- "appliedenergistics2:certus_quartz_crystal",
- "appliedenergistics2:charged_certus_quartz_crystal",
- "thermal:apatite",
- "thermal:cinnabar",
- "thermal:niter",
- "thermal:sulfur",
- "thermal:copper_ore",
- "thermal:tin_ore",
- "thermal:lead_ore",
- "thermal:silver_ore",
- "thermal:nickel_ore",
- "mekanism:osmium_ore",
- "mekanism:uranium_ore",
- "mekanism:fluorite_gem"
- }
- local function contains(t, item)
- for i = 1, #t do
- if item == t[i] then return true end
- end
- return false
- end
- local function refuel()
- for i = 1, 16 do
- local detail = turtle.getItemDetail(i)
- if detail then
- if detail.name == "minecraft:coal" then
- if turtle.getFuelLevel() < 1000 then
- turtle.select(i)
- repeat
- turtle.refuel(1)
- if not turtle.getItemDetail(i) then
- break
- end
- until turtle.getFuelLevel() > 1000
- end
- elseif not contains(inventoryWhitelist, detail.name) then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- fuel = turtle.getFuelLevel()
- turtle.select(1)
- end
- local function shouldReturn()
- if debounce then return true end
- debounce = fuel <= pathcost
- refuel()
- return fuel <= pathcost
- end
- local function forward()
- if shouldReturn() then return false end
- if turtle.forward() then
- pos = pos + dir
- pathcost = pathcost + 1
- fuel = fuel - 1
- return true
- end
- return false
- end
- local function back()
- if shouldReturn() then return false end
- if turtle.back() then
- pos = pos - dir
- pathcost = pathcost + 1
- fuel = fuel - 1
- return true
- end
- return false
- end
- local function up()
- if shouldReturn() then return false end
- if turtle.up() then
- pos.y = pos.y + 1
- pathcost = pathcost + 1
- fuel = fuel - 1
- return true
- end
- return false
- end
- local function down()
- if shouldReturn() then return false end
- if turtle.down() then
- pos.y = pos.y - 1
- pathcost = pathcost + 1
- fuel = fuel - 1
- return true
- end
- return false
- end
- local function turnRight()
- turtle.turnRight()
- dir = Vector3.new(dir.z, 0, -dir.x)
- end
- local function turnLeft()
- turtle.turnLeft()
- dir = Vector3.new(-dir.z, 0, dir.x)
- end
- local function mineUp()
- if shouldReturn() then return false end
- if turtle.digUp() then
- fuel = fuel - 1
- return true
- end
- return false
- end
- local function mineDown()
- if shouldReturn() then return false end
- if turtle.digDown() then
- fuel = fuel - 1
- return true
- end
- return false
- end
- local function mineForward()
- if shouldReturn() then return false end
- if turtle.dig() then
- fuel = fuel - 1
- return true
- end
- return false
- end
- local function dump()
- for i = 16, 1, -1 do
- turtle.select(i)
- turtle.drop(64)
- end
- end
- local function mineVein()
- local upsuc, updat = turtle.inspectUp()
- if upsuc and contains(wantedOres, updat.name) then
- if mineUp() then
- up()
- if shouldReturn() then
- pathcost = pathcost - 1
- down()
- return false
- end
- if not mineVein() then
- return false
- end
- pathcost = pathcost - 1
- down()
- else
- return false
- end
- end
- local dwsuc, dwdat = turtle.inspectDown()
- if dwsuc and contains(wantedOres, dwdat.name) then
- if mineDown() then
- down()
- if shouldReturn() then
- pathcost = pathcost - 1
- up()
- return false
- end
- if not mineVein() then
- return false
- end
- pathcost = pathcost - 1
- up()
- else
- return false
- end
- end
- local d0suc, d0dat = turtle.inspect()
- if d0suc and contains(wantedOres, d0dat.name) then
- if mineForward() then
- forward()
- if shouldReturn() then
- pathcost = pathcost - 1
- back()
- return false
- end
- if not mineVein() then
- return false
- end
- pathcost = pathcost - 1
- back()
- else
- return false
- end
- end
- turnRight()
- local d1suc, d1dat = turtle.inspect()
- if d1suc and contains(wantedOres, d1dat.name) then
- if mineForward() then
- forward()
- if shouldReturn() then
- pathcost = pathcost - 1
- back()
- return false
- end
- if not mineVein() then
- return false
- end
- pathcost = pathcost - 1
- back()
- else
- return false
- end
- end
- turnRight()
- local d2suc, d2dat = turtle.inspect()
- if d2suc and contains(wantedOres, d2dat.name) then
- if mineForward() then
- forward()
- if shouldReturn() then
- pathcost = pathcost - 1
- back()
- return false
- end
- if not mineVein() then
- return false
- end
- pathcost = pathcost - 1
- back()
- else
- return false
- end
- end
- turnRight()
- local d3suc, d3dat = turtle.inspect()
- if d3suc and contains(wantedOres, d3dat.name) then
- if mineForward() then
- forward()
- if shouldReturn() then
- pathcost = pathcost - 1
- back()
- return false
- end
- if not mineVein() then
- return false
- end
- pathcost = pathcost - 1
- back()
- else
- return false
- end
- end
- turnRight()
- return true
- end
- local function step()
- print("Path: ", pathcost, "Fuel: ", fuel)
- if shouldReturn() then return false end
- if forward() then
- local canContinue = mineVein()
- if not canContinue then
- print("Forced to exit mining vein...")
- return false
- end
- else
- if mineForward() then
- if shouldReturn() then return false end
- return step()
- else
- return false
- end
- end
- return true
- end
- repeat
- while true do
- if not step() then break end
- steps = steps + 1
- if (steps >= maxSteps) then
- break
- end
- end
- if debounce then
- print("Ran out of fuel, returning...")
- repeat
- turnRight()
- print(dir)
- until dir == Vector3.new(0, 0, -1)
- while pos.z > 0 do forward() end
- break
- else
- print("Reached max steps, returning to start")
- end
- repeat
- turnRight()
- print(dir)
- until dir == Vector3.new(0, 0, -1)
- while pos.z > 0 do forward() end
- print("Tunnel complete")
- dump()
- if tunnels >= maxTunnels then break end
- turnRight()
- mineForward()
- forward()
- mineForward()
- forward()
- mineForward()
- forward()
- turnRight()
- debounce = false
- if shouldReturn() then break end
- steps = 0
- pathcost = tunnels * 3
- tunnels = tunnels + 1
- print("Tunnel: ", tunnels, "/", maxTunnels)
- until tunnels > maxTunnels
- if tunnels > 1 then
- turnLeft()
- while pos.x ~= 0 do forward() end
- end
- turnRight()
- print("Process completed")
Add Comment
Please, Sign In to add comment