Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- things not to veinmine
- local blacklist = {
- "minecraft:stone",
- "minecraft:dirt",
- "minecraft:diorite",
- "minecraft:andesite",
- "minecraft:granite",
- "minecraft:gravel",
- "quark:slate",
- "minecraft:grass",
- "chisel:limestone",
- "chisel:limestone2",
- "minecraft:lava",
- "minecraft:water",
- "minecraft:flowing_water",
- "minecraft:flowing_lava",
- "minecraft:clay",
- "chisel:marble",
- "chisel:marble2",
- "chisel:basalt",
- "chisel:basalt2",
- "quark:biome_cobblestone"
- }
- -- vars to identify the current pos relative to start point
- local x = 0
- local y = 0
- local z = 0
- local rotation = 0
- -- params
- local x_size, y_size, depth, increment = ...
- x_size, y_size, depth, increment = tonumber(x_size), tonumber(y_size) - 1, tonumber(depth), tonumber(increment)
- --checking ore
- 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
- print(j.name)
- 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
- print(j.name)
- 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
- print(j.name)
- return true
- end
- end
- --this is mostly for gravel/confirming if ore
- local function better_forward()
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- if check_ore("forward") then return "forward" end
- if check_ore("up") then return "up" end
- if check_ore("down") then return "down" end
- end
- --veinmine
- local function veinmine(direction)
- local rot, positions, tx,ty,tz
- -- initializing vars and kickstarting based on where ore was found
- if direction == "forward" then
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- rot = 0
- tx, ty, tz = 0,0,1
- positions = {0}
- elseif direction == "up" then
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- end
- rot = 0
- tx, ty, tz = 0,1,0
- positions = {"down"}
- elseif direction == "down" then
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- end
- rot = 0
- tx, ty, tz = 0,-1,0
- positions = {"up"}
- end
- local shortcuts = 0
- local skips = 0
- local mined = {}
- --checks if blocks around turtle are already cleared
- 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) .. tostring(tz - 1)] and mined[tostring(tx) .. tostring(ty) .. tostring(tz + 1)] then
- return true
- end
- return false
- end
- local function check_left()
- --checking if the block to left is checked
- if rot % 4 == 0 and mined[tostring(tx-1) .. tostring(ty).. tostring(tz)] then
- return false
- elseif rot % 4 == 2 and mined[tostring(tx+1) .. tostring(ty).. tostring(tz)] then
- return false
- elseif rot % 4 == 1 and mined[tostring(tx) .. tostring(ty).. tostring(tz+1)] then
- return false
- elseif rot % 4 == 3 and mined[tostring(tx) .. tostring(ty).. tostring(tz-1)] then
- return false
- end
- --checking if the other blocks around are mined/checked
- if rot % 4 == 0 and (not mined[tostring(tx) .. tostring(ty).. tostring(tz+1)] or not mined[tostring(tx+1) .. tostring(ty).. tostring(tz)] or mined[tostring(tx) .. tostring(ty).. tostring(tz-1)]) then
- return false
- elseif rot % 4 == 2 and (not mined[tostring(tx) .. tostring(ty).. tostring(tz - 1)] or not mined[tostring(tx - 1) .. tostring(ty).. tostring(tz)] or not mined[tostring(tx) .. tostring(ty).. tostring(tz + 1)]) then
- return false
- elseif rot % 4 == 1 and (not mined[tostring(tx+1) .. tostring(ty).. tostring(tz)] or not mined[tostring(tx) .. tostring(ty).. tostring(tz - 1)] or not mined[tostring(tx - 1) .. tostring(ty).. tostring(tz)]) then
- return false
- elseif rot % 4 == 3 and (not mined[tostring(tx - 1) .. tostring(ty).. tostring(tz)] or not mined[tostring(tx) .. tostring(ty).. tostring(tz + 1)] or not mined[tostring(tx + 1) .. tostring(ty).. tostring(tz)]) then
- return false
- end
- return true
- end
- --the veinmine part
- while #positions ~= 0 do
- print("Local position:", tx, ty, tz)
- print("Local rotation:", rot)
- local found_ore = false
- 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")
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- end
- found_ore = true
- ty = ty + 1
- mined[tostring(tx) .. tostring(ty) .. tostring(tz)] = true
- elseif check_ore("down") then
- table.insert(positions, "up")
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- end
- found_ore = true
- ty = ty - 1
- mined[tostring(tx) .. tostring(ty) .. tostring(tz)] = true
- elseif not check_around() then
- if check_left() then
- shortcuts = shortcuts + 1
- turtle.turnLeft()
- if check_ore("forward") then
- table.insert(positions, 3)
- rot = rot + 3
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- if rot % 4 == 1 then
- tx = tx + 1
- elseif rot % 4 == 2 then
- tz = tz - 1
- elseif rot % 4 == 3 then
- tx = tx - 1
- elseif rot % 4 == 0 then
- tz = tz + 1
- end
- found_ore = true
- mined[tostring(tx) .. tostring(ty) .. tostring(tz)] = true
- else
- local qx, qy, qz = tx, ty, tz
- if rot % 4 == 1 then
- qx = qx + 1
- elseif rot % 4 == 2 then
- qz = qz - 1
- elseif rot % 4 == 3 then
- qx = qx - 1
- elseif rot % 4 == 0 then
- qz = qz + 1
- end
- mined[tostring(qx) .. tostring(qy) .. tostring(qz)] = true
- turtle.turnRight()
- end
- else
- for i = 1,4 do
- if check_ore("forward") then
- table.insert(positions, i - 1)
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- if rot % 4 == 1 then
- tx = tx + 1
- elseif rot % 4 == 2 then
- tz = tz - 1
- elseif rot % 4 == 3 then
- tx = tx - 1
- elseif rot % 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 rot % 4 == 1 then
- qx = qx + 1
- elseif rot % 4 == 2 then
- qz = qz - 1
- elseif rot % 4 == 3 then
- qx = qx - 1
- elseif rot % 4 == 0 then
- qz = qz + 1
- end
- mined[tostring(qx) .. tostring(qy) .. tostring(qz)] = true
- end
- turtle.turnRight()
- rot = rot + 1
- end
- end
- else
- skips = skips + 1
- end
- if not found_ore then
- if positions[#positions] == "up" then
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- end
- ty = ty + 1
- elseif positions[#positions] == "down" then
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- end
- ty = ty - 1
- else
- if not turtle.back() then
- turtle.turnRight()
- turtle.turnRight()
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- if rot % 4 == 1 then
- tx = tx - 1
- elseif rot % 4 == 2 then
- tz = tz + 1
- elseif rot % 4 == 3 then
- tx = tx + 1
- elseif rot % 4 == 0 then
- tz = tz - 1
- end
- if positions[#positions] == 3 then
- turtle.turnRight()
- rot = rot - 3
- elseif positions[#positions] ~= 0 then
- for i = 1, positions[#positions] do
- turtle.turnLeft()
- end
- rot = rot - positions[#positions]
- end
- end
- table.remove(positions)
- end
- end
- print("Shortcuts used:", shortcuts)
- print("Skips used:", skips)
- end
- -- function that returns to start point
- local function return_to_origin(up)
- --switch for when something is blocking its way
- local offset = false
- -- rotating it to face the starting wall
- if rotation ~= 2 then
- if rotation > 2 then
- repeat turtle.turnLeft() rotation = rotation - 1 until rotation == 2
- elseif rotation < 2 then
- repeat turtle.turnRight() rotation = rotation + 1 until rotation == 2
- end
- end
- -- moving it out of the way if theres a block in front of it
- if turtle.detect() and x ~= 0 then
- offset = true
- turtle.turnRight()
- better_forward()
- turtle.turnLeft()
- end
- -- returning to start
- for i = 1,y do
- better_forward()
- end
- turtle.turnRight()
- if offset then
- for i = 1,x-1 do
- better_forward()
- end
- else
- for i = 1,x do
- better_forward()
- end
- end
- --rotating back to 0
- turtle.turnRight()
- -- going back to the top if desired
- if up then
- for i = 1, z do
- turtle.up()
- end
- end
- end
- --emptying storage
- local function empty_storage(finished)
- --checking if all slots have at least 1 item in them
- if not finished then
- for i = 1,16 do
- if turtle.getItemCount(i) == 0 then
- return
- end
- end
- end
- local old_rotation = rotation
- --returning to top
- return_to_origin(true)
- turtle.turnRight()
- turtle.turnRight()
- --emptying inv
- for i = 1,16 do
- turtle.select(i)
- turtle.drop(64)
- end
- turtle.turnRight()
- turtle.turnRight()
- --going back down to where it was if need be
- if not finished then
- for i = 1, z do
- turtle.down()
- end
- for i = 1, y do
- better_forward()
- end
- turtle.turnRight()
- for i = 1, x do
- better_forward()
- end
- if old_rotation == 0 then
- turtle.turnLeft()
- elseif old_rotation == 2 then
- turtle.turnRight()
- end
- end
- end
- local function mine_sector()
- -- switch to alternate digging left/right
- local left = false
- for i = 1, x_size do
- --digging forward
- for i = 1, y_size do
- local result = better_forward()
- if result then
- if result == "forward" then
- veinmine("forward")
- elseif result == "up" then
- veinmine("up")
- elseif result == "down" then
- veinmine("down")
- end
- end
- if not left then y = y + 1
- else y = y - 1 end
- if y ~= y_size then
- empty_storage()
- end
- end
- --turning using switch
- if x ~= x_size - 1 then
- if not left then
- turtle.turnRight()
- local result = better_forward()
- if result then
- if result == "forward" then
- veinmine("forward")
- elseif result == "up" then
- veinmine("up")
- elseif result == "down" then
- veinmine("down")
- end
- end
- turtle.turnRight()
- left = true
- rotation = 2
- x = x + 1
- else
- turtle.turnLeft()
- local result = better_forward()
- if result then
- if result == "forward" then
- veinmine("forward")
- elseif result == "up" then
- veinmine("up")
- elseif result == "down" then
- veinmine("down")
- end
- end
- turtle.turnLeft()
- left = false
- rotation = 0
- x = x + 1
- end
- end
- end
- end
- local function dig_deeper()
- return_to_origin(false)
- for i = 1, increment do
- if z == depth then return end
- z = z + 1
- turtle.digDown()
- turtle.down()
- end
- end
- local function smart_fuel()
- local fuel_needed = (x_size * y_size) * math.floor(depth / increment) * 2
- term.clear()
- if turtle.getFuelLevel() <= fuel_needed then
- while turtle.getFuelLevel() <= fuel_needed do
- term.clear()
- term.setCursorPos(1,1)
- print("Fuel needed:", fuel_needed)
- term.setCursorPos(1,2)
- print("Current fuel:", turtle.getFuelLevel())
- turtle.refuel()
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Success, running quarry.")
- end
- local function quarry()
- smart_fuel()
- while true do
- dig_deeper()
- x,y,rotation = 0,0,0
- if z >= depth then break end
- mine_sector()
- end
- if depth % increment == 0 then
- mine_sector()
- end
- empty_storage(true)
- end
- quarry()
Add Comment
Please, Sign In to add comment