67 lines
1.2 KiB
Lua
67 lines
1.2 KiB
Lua
args = {...}
|
|
|
|
function pair(x, y)
|
|
return math.floor((x + y) * (x + y + 1)/2 + y)
|
|
end
|
|
|
|
function unpairX(z)
|
|
local j = math.floor(math.sqrt(0.25 + 2*z) - 0.5)
|
|
return j - (z - j*(j+1)/2)
|
|
end
|
|
|
|
|
|
function unpairZ(z)
|
|
local j = math.floor(math.sqrt(0.25 + 2*z) - 0.5)
|
|
return z - j * (j+1)/2;
|
|
end
|
|
|
|
lookup = {4, 1, 3, 0, 2}
|
|
local function isDiggingSpot(x, y)
|
|
local val = lookup[(y % 5) + 1]
|
|
return (x % 5) == val
|
|
end
|
|
|
|
offset = 10
|
|
function ithSpot(i)
|
|
j = offset
|
|
while true do
|
|
x, z = unpairX(j), unpairZ(j)
|
|
if isDiggingSpot(x, z) then
|
|
if i <= 1 then
|
|
return x, z
|
|
else
|
|
i = i - 1
|
|
end
|
|
end
|
|
j = j + 1
|
|
end
|
|
end
|
|
|
|
function digTo(x, z)
|
|
while z > 0 do
|
|
turtle.dig()
|
|
turtle.forward()
|
|
turtle.digUp()
|
|
z = z - 1
|
|
end
|
|
turtle.turnRight()
|
|
while x > 0 do
|
|
turtle.dig()
|
|
turtle.forward()
|
|
turtle.digUp()
|
|
x = x - 1
|
|
end
|
|
end
|
|
|
|
function digSpot(i)
|
|
x, z = ithSpot(i)
|
|
digTo(x, z)
|
|
turtle.digDown()
|
|
turtle.down()
|
|
end
|
|
|
|
spotNum = tonumber(args[1])
|
|
if spotNum then
|
|
digSpot(spotNum)
|
|
end
|