ComputerCraft/Mining_Things/digtunnel.lua

104 lines
2.2 KiB
Lua

--[[digtunnel program from Sascha
Dig a tunnel until bedrock]]
os.loadAPI('hare')
isBedrock = false
level = 0
function comming_back(distance)
for i = 1, distance do
turtle.up()
end
end
function dig_around()
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnLeft()
if is_bedrock() == true then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnRight()
turtle.turnRight()
if is_bedrock() then
print('Found Bedrock comming back')
comming_back(level)
error('done')
end
turtle.dig()
turtle.turnLeft()
end
function is_bedrock()
-- Check if we have Bedrock in Front
-- or underneath of us
local success, item = turtle.inspect()
if success == true and item['name'] == 'minecraft:bedrock' then
isBedrock = true
return true
else
return false
end
local success, item = turtle.inspectDown()
if success == true and item['name'] == 'minecraft;bedrock' then
isBedrock = true
else
return false
end
end
while isBedrock == false do
-- Dig one level down
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.digDown()
turtle.down()
level = level + 1
-- Dig a 3x3 Tunnel
dig_around()
turtle.forward()
dig_around()
turtle.forward()
turtle.turnLeft()
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnRight()
turtle.turnRight()
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnLeft()
-- place a ladder
local success, item = turtle.inspect()
if not success then
hare.selectItem('minecraft:cobblestone')
turtle.place()
end
turtle.back()
hare.selectItem('minecraft:ladder')
turtle.place()
hare.selectEmptySlot()
-- Go back to Start Position
turtle.back()
end