Added digtunnel Script

This commit is contained in:
Sascha Martens 2020-11-07 23:44:09 +01:00
parent fdcc4f3eba
commit df7f7bbb7e

103
Mining_Things/digtunnel.lua Normal file
View File

@ -0,0 +1,103 @@
--[[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