Turtles & mining

Mining turtle

A turtle digs a tunnel underground, mines the ores it finds in the walls and brings them back to a chest.

Likes
0
Views
0
In-game installs
0

Capabilities

  • Turtle program

Licence

MIT

startup.lua 1696 bytes Raw
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
6local DEPTH = 4 -- how far down the tunnel is
7local LENGTH = 12 -- how long it is
8
9local mined = 0
10
11local function isOre(inspect)
12 local ok, block = inspect()
13 return ok and block.name:find("_ore$") ~= nil
14end
15
16-- Digs until the way is clear: gravel and sand fall into the gap.
17local function clear(detect, dig)
18 while detect() do
19 if dig() then mined = mined + 1 end
20 end
21end
22
23local function forward()
24 clear(turtle.detect, turtle.dig)
25 assert(turtle.forward(), "Can't move forward")
26end
27
28local 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
36end
37
38print(("Fuel: %d"):format(turtle.getFuelLevel()))
39print("Digging down...")
40for _ = 1, DEPTH do
41 clear(turtle.detectDown, turtle.digDown)
42 turtle.down()
43end
44
45print("Tunnelling...")
46for _ = 1, LENGTH do
47 forward()
48 mineOres()
49end
50
51print("Coming back...")
52turtle.turnLeft()
53turtle.turnLeft()
54for _ = 1, LENGTH do forward() end
55for _ = 1, DEPTH do
56 clear(turtle.detectUp, turtle.digUp)
57 turtle.up()
58end
59
60-- Facing back the way it came, the chest is in front.
61for slot = 1, 16 do
62 turtle.select(slot)
63 turtle.drop()
64end
65turtle.select(1)
66print(("Done: dug %d blocks. Fuel left: %d"):format(mined, turtle.getFuelLevel()))

Install in your world

wget run https://ccbin.dev/i/CkVVHwEF
wget https://ccbin.dev/raw/CkVVHwEF startup.lua
Embed on your site
<iframe src="https://ccbin.dev/CkVVHwEF/embed" width="800" height="520" style="border:0" loading="lazy" allow="autoplay" title="Mining turtle on ccbin.dev"></iframe>

Sites that understand oEmbed, such as Discord and many forums, make the embed from the program's link.

A 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.