add canemine script
This commit is contained in:
parent
656a14c2a2
commit
2af22cdd07
126
dominic/canemine.lua
Normal file
126
dominic/canemine.lua
Normal file
@ -0,0 +1,126 @@
|
||||
args = {...}
|
||||
|
||||
function noop() end
|
||||
|
||||
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)
|
||||
print("Digging to rel. coord ("..tostring(x)..", "..tostring(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
|
||||
|
||||
-- dig all the way down to bedrock, collect ores
|
||||
-- Parameters:
|
||||
-- * moveAction: the **vertical** move action, eg turtle.down
|
||||
-- * digAction: the **vertical** dig action, eg turtle.digDown
|
||||
-- * inpectAction: the **vertical** inspect action, eg turtle.inspectDown
|
||||
-- * limit: if >= 0 * the number of blocks to dig
|
||||
-- * dig until bedrock is hit
|
||||
--
|
||||
--
|
||||
-- Returns: the depth dug
|
||||
function digDeep(moveAction, digAction, inspectAction, limit)
|
||||
local depth = 0
|
||||
while true do
|
||||
-- termination condition:
|
||||
-- * if limit != -1: limit > 0
|
||||
-- * otherwise : bedrock beneath
|
||||
if limit < 0 then
|
||||
local nextblock = inspectAction()
|
||||
if nextblock and nextblock["name"] == "minecraft:bedrock" then
|
||||
return depth
|
||||
end
|
||||
else
|
||||
if limit == 0 then
|
||||
return depth
|
||||
end
|
||||
end
|
||||
-- Limit not reached: keep digging
|
||||
depth = depth + 1
|
||||
limit = limit - 1
|
||||
digAction()
|
||||
moveAction()
|
||||
-- TODO
|
||||
-- grabOres() -- inspect block in front of turtle, take if neccessary
|
||||
end
|
||||
end
|
||||
|
||||
function selectCobble()
|
||||
for i = 1,16 do
|
||||
turtle.select(i)
|
||||
item = turtle.getItemDetail()
|
||||
if item["name"] == "minecraft:cobblestone" then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function digShaft()
|
||||
print("Starting to dig shaft")
|
||||
depth = digDeep(turtle.down, turtle.digDown, turtle.inspectDown, 3)
|
||||
print("Dug the first shaft (depth = "..tostring(depth)..")")
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.up, noop, noop, depth - 1)
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.down, noop, noop, depth - 1)
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.up, noop, noop, depth - 1)
|
||||
turtle.turnLeft()
|
||||
selectCobble()
|
||||
turtle.placeDown()
|
||||
turtle.up()
|
||||
end
|
||||
|
||||
spotNum = tonumber(args[1])
|
||||
if spotNum then
|
||||
x, z = ithSpot(spotNum)
|
||||
digTo(x,z)
|
||||
digShaft()
|
||||
end
|
@ -1,5 +1,7 @@
|
||||
args = {...}
|
||||
|
||||
function noop() end
|
||||
|
||||
function pair(x, y)
|
||||
return math.floor((x + y) * (x + y + 1)/2 + y)
|
||||
end
|
||||
@ -38,6 +40,7 @@ function ithSpot(i)
|
||||
end
|
||||
|
||||
function digTo(x, z)
|
||||
print("Digging to rel. coord ("..tostring(x)..", "..tostring(z)..")")
|
||||
while z > 0 do
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
@ -53,14 +56,71 @@ function digTo(x, z)
|
||||
end
|
||||
end
|
||||
|
||||
function digSpot(i)
|
||||
x, z = ithSpot(i)
|
||||
digTo(x, z)
|
||||
turtle.digDown()
|
||||
turtle.down()
|
||||
-- dig all the way down to bedrock, collect ores
|
||||
-- Parameters:
|
||||
-- * moveAction: the **vertical** move action, eg turtle.down
|
||||
-- * digAction: the **vertical** dig action, eg turtle.digDown
|
||||
-- * inpectAction: the **vertical** inspect action, eg turtle.inspectDown
|
||||
-- * limit: if >= 0 * the number of blocks to dig
|
||||
-- * dig until bedrock is hit
|
||||
--
|
||||
--
|
||||
-- Returns: the depth dug
|
||||
function digDeep(moveAction, digAction, inspectAction, limit)
|
||||
local depth = 0
|
||||
while true do
|
||||
-- termination condition:
|
||||
-- * if limit != -1: limit > 0
|
||||
-- * otherwise : bedrock beneath
|
||||
if limit < 0 then
|
||||
local nextblock = inspectAction()
|
||||
if nextblock and nextblock["name"] == "minecraft:bedrock" then
|
||||
return depth
|
||||
end
|
||||
else
|
||||
if limit == 0 then
|
||||
return depth
|
||||
end
|
||||
end
|
||||
-- Limit not reached: keep digging
|
||||
depth = depth + 1
|
||||
limit = limit - 1
|
||||
digAction()
|
||||
moveAction()
|
||||
-- TODO
|
||||
-- grabOres() -- inspect block in front of turtle, take if neccessary
|
||||
end
|
||||
end
|
||||
|
||||
function selectCobble()
|
||||
for i = 1,16 do
|
||||
turtle.select(i)
|
||||
item = turtle.getItemDetail()
|
||||
if item["name"] == "minecraft:cobblestone" then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function digShaft()
|
||||
print("Starting to dig shaft")
|
||||
depth = digDeep(turtle.down, turtle.digDown, turtle.inspectDown, 3)
|
||||
print("Dug the first shaft (depth = "..tostring(depth)..")")
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.up, noop, noop, depth - 1)
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.down, noop, noop, depth - 1)
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.up, noop, noop, depth - 1)
|
||||
turtle.turnLeft()
|
||||
selectCobble()
|
||||
turtle.placeDown()
|
||||
turtle.up()
|
||||
end
|
||||
|
||||
spotNum = tonumber(args[1])
|
||||
if spotNum then
|
||||
digSpot(spotNum)
|
||||
x, z = ithSpot(spotNum)
|
||||
digTo(x,z)
|
||||
digShaft()
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user