Mining turtle
A turtle digs a tunnel underground, mines the ores it finds in the walls and brings them back to a chest.
| 1 | -- A small strip miner. The turtle digs down, tunnels forward, mines any ore |
| 2 | -- it sees above, below or beside it, then comes back and empties itself |
| 3 | -- into the chest behind its starting spot. |
| 4 | -- Press "Instant" above the turtle world to skip the waiting. |
| 5 | |
| 6 | local DEPTH = 4 -- how far down the tunnel is |
| 7 | local LENGTH = 12 -- how long it is |
| 8 | |
| 9 | local mined = 0 |
| 10 | |
| 11 | local function isOre(inspect) |
| 12 | local ok, block = inspect() |
| 13 | return ok and block.name:find("_ore$") ~= nil |
| 14 | end |
| 15 | |
| 16 | -- Digs until the way is clear: gravel and sand fall into the gap. |
| 17 | local function clear(detect, dig) |
| 18 | while detect() do |
| 19 | if dig() then mined = mined + 1 end |
| 20 | end |
| 21 | end |
| 22 | |
| 23 | local function forward() |
| 24 | clear(turtle.detect, turtle.dig) |
| 25 | assert(turtle.forward(), "Can't move forward") |
| 26 | end |
| 27 | |
| 28 | local function mineOres() |
| 29 | if isOre(turtle.inspectUp) then turtle.digUp() mined = mined + 1 end |
| 30 | if isOre(turtle.inspectDown) then turtle.digDown() mined = mined + 1 end |
| 31 | for _ = 1, 2 do |
| 32 | turtle.turnLeft() |
| 33 | if isOre(turtle.inspect) then turtle.dig() mined = mined + 1 end |
| 34 | turtle.turnLeft() |
| 35 | end |
| 36 | end |
| 37 | |
| 38 | print(("Fuel: %d"):format(turtle.getFuelLevel())) |
| 39 | print("Digging down...") |
| 40 | for _ = 1, DEPTH do |
| 41 | clear(turtle.detectDown, turtle.digDown) |
| 42 | turtle.down() |
| 43 | end |
| 44 | |
| 45 | print("Tunnelling...") |
| 46 | for _ = 1, LENGTH do |
| 47 | forward() |
| 48 | mineOres() |
| 49 | end |
| 50 | |
| 51 | print("Coming back...") |
| 52 | turtle.turnLeft() |
| 53 | turtle.turnLeft() |
| 54 | for _ = 1, LENGTH do forward() end |
| 55 | for _ = 1, DEPTH do |
| 56 | clear(turtle.detectUp, turtle.digUp) |
| 57 | turtle.up() |
| 58 | end |
| 59 | |
| 60 | -- Facing back the way it came, the chest is in front. |
| 61 | for slot = 1, 16 do |
| 62 | turtle.select(slot) |
| 63 | turtle.drop() |
| 64 | end |
| 65 | turtle.select(1) |
| 66 | print(("Done: dug %d blocks. Fuel left: %d"):format(mined, turtle.getFuelLevel())) |
Press Run to boot a computer.
- This runs on a mining turtle with fuel, a chest behind it and ore in the ground, in an approximate world of colored blocks with simplified rules.
Network
Every request the program makes, and how the sandbox answered it. The program's own mocks answer first. Pastebin, GitHub and ccbin downloads go through ccbin. Anything else gets a placeholder, or an error if the scene says so. Nothing else leaves your browser unless you turn on live network.
Install in your world
wget run https://ccbin.dev/i/CkVVHwEFwget https://ccbin.dev/raw/CkVVHwEF startup.luaA turtle digs a tunnel underground, mines the ores it finds in the walls and brings them back to a chest.
This is one of the examples in the Workbench. Run it here, or open it in the Workbench to change it.
Comments
No comments yet.
Sign in to comment.