Skip to content

Instantly share code, notes, and snippets.

@xotonic
Created February 17, 2019 19:52
Show Gist options
  • Save xotonic/f2f2aa7ea2cc561d673e4488d66fedd3 to your computer and use it in GitHub Desktop.
Save xotonic/f2f2aa7ea2cc561d673e4488d66fedd3 to your computer and use it in GitHub Desktop.
Computercraft script for turtle to make a quarry-like mine. Tags: minecraft computercraft
function Set(list)
local set = {}
for _, l in ipairs(list)
do set[l] = true end
return set
end
trash = Set {
"minecraft:dirt",
"minecraft:cobblestone"
}
function round(n)
return n % 1 >= 0.5
and math.ceil(n)
or math.floor(n)
end
function healthCheck()
i = 1
while turtle.getFuelLevel() < 1000
and i < 16
do
turtle.select(i)
turtle.refuel()
i = i + 1
end
if turtle.getFuelLevel() == 0 then
print("NO FUEL")
exit()
end
end
function sanitize()
for i = 1, 16, 1 do
turtle.select(i)
item = turtle.getItemDetail()
if item then
if trash[item.name]
and item.count > 20 then
turtle.dropDown(item.count)
end
end
end
end
function dig(n)
for i = 0, n, 1 do
turtle.digUp()
turtle.digDown()
turtle.dig()
healthCheck()
turtle.forward()
turtle.digDown()
turtle.digUp()
end
sanitize()
end
function digLine(n)
dig(n)
for i = 0, n, 1 do
turtle.back()
end
end
function semiCircle(r)
for x = -r, r, 1 do
y = round(math.sqrt(r*r - x*x))
digLine(y)
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
end
end
function circle(r)
semiCircle(r)
turtle.turnLeft()
turtle.turnLeft()
semiCircle(r)
end
function digCircle(r)
turtle.digDown()
turtle.down()
turtle.digDown()
turtle.down()
turtle.digDown()
turtle.down()
turtle.turnRight()
dig(r)
turtle.turnLeft()
circle(r)
turtle.turnRight()
dig(r - 1)
turtle.turnLeft()
end
digCircle(5)
digCircle(4)
digCircle(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment