Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local blacklist = {
- "minecraft:stone",
- "minecraft:dirt",
- "minecraft:diorite",
- "minecraft:andesite",
- "minecraft:granite",
- "minecraft:gravel",
- "quark:slate"
- }
- local function check_ore(direction)
- if direction == "up" then
- _, j = turtle.inspectUp()
- if not _ then return false end
- for i,v in pairs(blacklist) do
- if j.name == v then
- return false
- end
- end
- return true
- elseif direction == "down" then
- _, j = turtle.inspectDown()
- if not _ then return false end
- for i,v in pairs(blacklist) do
- if _ and j.name == v then
- return false
- end
- end
- return true
- elseif direction == "forward" then
- _, j = turtle.inspect()
- if not _ then return false end
- for i,v in pairs(blacklist) do
- if _ and j.name == v then
- return false
- end
- end
- return true
- end
- end
- local function veinmine()
- turtle.dig()
- turtle.forward()
- local rotation = 0
- local tx, ty, tz = 0,0,1
- local positions = {0}
- local turns = {}
- local shortcuts = 0
- local skips = 0
- local omega_skips = 0
- local mined = {}
- local function check_around()
- if mined[tostring(tx - 1) .. tostring(ty) .. tostring(tz)] and mined[tostring(tx + 1) .. tostring(ty) .. tostring(tz)] and mined[tostring(tx) .. tostring(ty - 1) .. tostring(tz)] and mined[tostring(tx) .. tostring(ty + 1) .. tostring(tz)] and mined[tostring(tx) .. tostring(ty) .. tostring(tz - 1)] and mined[tostring(tx) .. tostring(ty) .. tostring(tz + 1)] then
- return true
- end
- return false
- end
- while #positions ~= 0 do
- local found_ore = false
- local old_rot = rotation
- if not check_around() then
- if not check_ore("up") then
- mined[tostring(tx) .. tostring(ty+1) .. tostring(tz)] = true
- end
- if not check_ore("down") then
- mined[tostring(tx) .. tostring(ty - 1) .. tostring(tz)] = true
- end
- if check_ore("up") then
- table.insert(positions, "down")
- turtle.digUp()
- turtle.up()
- found_ore = true
- ty = ty + 1
- elseif check_ore("down") then
- table.insert(positions, "up")
- turtle.digDown()
- turtle.down()
- found_ore = true
- ty = ty - 1
- else
- if not turns[tostring(tx) .. tostring(ty) .. tostring(tz)] or turns[tostring(tx) .. tostring(ty) .. tostring(tz)] <= 1 then
- for i = 1,4 do
- if check_ore("forward") then
- table.insert(positions, rotation)
- turns[tostring(tx) .. tostring(ty) .. tostring(tz)] = i - 1
- turtle.dig()
- turtle.forward()
- if rotation % 4 == 1 then
- tx = tx + 1
- elseif rotation % 4 == 2 then
- tz = tz - 1
- elseif rotation % 4 == 3 then
- tx = tx - 1
- elseif rotation % 4 == 0 then
- tz = tz + 1
- end
- found_ore = true
- mined[tostring(tx) .. tostring(ty) .. tostring(tz)] = true
- break
- else
- local qx, qy, qz = tx, ty, tz
- if rotation % 4 == 1 then
- qx = qx + 1
- elseif rotation % 4 == 2 then
- qz = qz - 1
- elseif rotation % 4 == 3 then
- qx = qx - 1
- elseif rotation % 4 == 0 then
- qz = qz + 1
- end
- mined[tostring(qx) .. tostring(qy) .. tostring(qz)] = true
- end
- turtle.turnRight()
- rotation = rotation + 1
- end
- elseif turns[tostring(tx) .. tostring(ty) .. tostring(tz)] == 2 then
- shortcuts = shortcuts + 1
- turtle.turnLeft()
- if check_ore("forward") then
- rotation = rotation + 3
- table.insert(positions, rotation)
- turns[tostring(tx) .. tostring(ty) .. tostring(tz)] = 3
- found_ore = true
- turtle.dig()
- turtle.forward()
- if rotation % 4 == 1 then
- tx = tx + 1
- elseif rotation % 4 == 2 then
- tz = tz - 1
- elseif rotation % 4 == 3 then
- tx = tx - 1
- elseif rotation % 4 == 0 then
- tz = tz + 1
- end
- mined[tostring(tx) .. tostring(ty) .. tostring(tz)] = true
- else
- local qx, qy, qz = tx, ty, tz
- if rotation % 4 == 1 then
- qx = qx + 1
- elseif rotation % 4 == 2 then
- qz = qz - 1
- elseif rotation % 4 == 3 then
- qx = qx - 1
- elseif rotation % 4 == 0 then
- qz = qz + 1
- end
- mined[tostring(qx) .. tostring(qy) .. tostring(qz)] = true
- turtle.turnRight()
- end
- elseif turns[tostring(tx) .. tostring(ty) .. tostring(tz)] >= 3 then
- skips = skips + 1
- end
- end
- else
- omega_skips = omega_skips + 1
- end
- if not found_ore then
- rotation = old_rot
- turns[tostring(tx) .. tostring(ty) .. tostring(tz)] = 3
- end
- if not found_ore then
- if positions[#positions] == "up" then
- turtle.up()
- ty = ty + 1
- elseif positions[#positions] == "down" then
- turtle.down()
- ty = ty - 1
- else
- if rotation - 3 == positions[#positions] then
- turtle.turnRight()
- rotation = positions[#positions]
- else
- for i = 1, math.abs(rotation - positions[#positions]) do
- turtle.turnLeft()
- end
- rotation = positions[#positions]
- end
- if rotation % 4 == 1 then
- tx = tx - 1
- elseif rotation % 4 == 2 then
- tz = tz + 1
- elseif rotation % 4 == 3 then
- tx = tx + 1
- elseif rotation % 4 == 0 then
- tz = tz - 1
- end
- turtle.back()
- end
- table.remove(positions)
- end
- end
- print("Shortcuts used:", shortcuts)
- print("Skips used:", skips)
- print("Omega skips used:", omega_skips)
- end
- veinmine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement