Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- directions pretends turtle looks north when placed down,
- -- that means the z axis is forward and back, and the x axis is left and right
- local blocksToMine = {
- ["minecraft:diamond_ore"] = true,
- ["minecraft:iron_ore"] = true,
- ["minecraft:coal_ore"] = true,
- ["minecraft:gold_ore"] = true,
- ["minecraft:redstone_ore"] = true,
- ["minecraft:lapis_ore"] = true,
- ["minecraft:emerald_ore"] = true,
- ["minecraft:copper_ore"] = true,
- -- Add deepslate variants
- ["minecraft:deepslate_diamond_ore"] = true,
- ["minecraft:deepslate_iron_ore"] = true,
- ["minecraft:deepslate_coal_ore"] = true,
- ["minecraft:deepslate_gold_ore"] = true,
- ["minecraft:deepslate_redstone_ore"] = true,
- ["minecraft:deepslate_lapis_ore"] = true,
- ["minecraft:deepslate_emerald_ore"] = true,
- ["minecraft:deepslate_copper_ore"] = true
- }
- local currentPosition = {
- x = 0,
- y = 0,
- z = 0
- }
- local startingY = 124
- local minY = -52
- local maxY = 16
- local currentBranch = 0
- local function descend()
- local blocksToDescend = startingY - minY
- for _ = 1, blocksToDescend do
- turtle.digDown()
- turtle.down()
- currentPosition.y = currentPosition.y - 1
- end
- end
- local function shouldMine(blockName)
- return blocksToMine[blockName] or false
- end
- local function checkAndMineAround()
- -- Check up
- local success, data = turtle.inspectUp()
- if success and shouldMine(data.name) then
- turtle.digUp()
- end
- -- Check down
- success, data = turtle.inspectDown()
- if success and shouldMine(data.name) then
- turtle.digDown()
- end
- -- Check left (need to turn)
- turtle.turnLeft()
- success, data = turtle.inspect()
- if success and shouldMine(data.name) then
- turtle.dig()
- end
- turtle.turnRight()
- -- Check right
- turtle.turnRight()
- success, data = turtle.inspect()
- if success and shouldMine(data.name) then
- turtle.dig()
- end
- turtle.turnLeft()
- end
- local function mineBranch()
- for i = 1, 16 do
- checkAndMineAround()
- if i < 16 then
- turtle.dig()
- turtle.forward()
- if currentBranch % 2 == 1 then
- currentPosition.x = currentPosition.x + 1 -- facing right (east) is positive x
- else
- currentPosition.x = currentPosition.x - 1 -- facing left (west) is negative x
- end
- end
- end
- end
- local function moveToNextBranch()
- if currentBranch % 2 == 1 then
- -- Odd branch, turn left
- turtle.turnLeft()
- for _ = 1, 2 + 1 do
- checkAndMineAround()
- turtle.dig()
- turtle.forward()
- currentPosition.z = currentPosition.z - 1 -- negative z is north
- end
- turtle.turnLeft()
- else
- -- Even branch, turn right
- turtle.turnRight()
- for _ = 1, 2 + 1 do
- checkAndMineAround()
- turtle.dig()
- turtle.forward()
- currentPosition.z = currentPosition.z - 1 -- negative z is north
- end
- turtle.turnRight()
- end
- end
- local function main()
- descend()
- turtle.turnRight()
- while currentPosition.y < maxY do
- -- do all branches on a level
- for branch = 1, 6 do
- currentBranch = branch
- mineBranch()
- if branch < 6 then
- moveToNextBranch()
- end
- end
- -- if we end on an odd branch, turn around and come back
- if 6 % 2 == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- for _ = 1, (16 - 1) do
- turtle.forward()
- currentPosition.x = currentPosition.x - 1 -- moving west toward starting point
- end
- end
- -- face south
- turtle.turnLeft()
- -- move to the starting point
- while currentPosition.z < 0 do
- turtle.forward()
- currentPosition.z = currentPosition.z + 1 -- moving south to starting point
- end
- -- turn back forward
- turtle.turnLeft()
- turtle.turnLeft()
- -- go up to the next y level
- for _ = 1, 3 do
- if currentPosition.y < maxY then
- turtle.up()
- currentPosition.y = currentPosition.y + 1
- end
- end
- end
- -- move back to the starting point
- while currentPosition.y < 0 do
- turtle.up()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement