ComputerCraft-Codes/StripMiner

150 lines
2.5 KiB
Plaintext
Raw Normal View History

2023-11-20 21:14:19 -06:00
----
-- Parameters
----
stump_dist = 32
stump_lighting = 3
stump_current = 0
branch_dist = 32
branch_lighting = 7
branch_current = 0
function mine()
while turtle.detect() do
turtle.dig()
sleep(0.5)
end
end
function mine_up()
while turtle.detectUp() do
turtle.digUp()
sleep(0.5)
end
end
function check_fuel()
term.clear()
term.setCursorPos(1,1)
if turtle.getFuelLevel() <= 0 then
print("Looking for fuel...")
i = 1
while i ~= 16 do
turtle.select(i)
turtle.refuel()
i = i + 1
end
end
if turtle.getFuelLevel() <= 0 then
print("Could not fuel up...")
sleep(30)
check_fuel()
end
end
function forward()
check_fuel()
turtle.forward()
end
function backwards()
check_fuel()
turtle.back()
end
function torch()
s = false
i = 1
while i ~= 17 do
turtle.select(i)
item = turtle.getItemDetail()
if item ~= nil then
print(item["name"])
if string.find(item["name"], "torch") then
turtle.select(i)
turtle.placeUp()
s = true
end
end
i = i + 1
end
if not s then
print("Could not place a torch...")
end
end
function torch_stump()
if stump_current % stump_lighting == 0 or stump_current == 0 then
torch()
end
end
function torch_branch()
if branch_current % branch_lighting == 0 or branch_current == 0 then
turtle.turnRight()
torch()
turtle.turnLeft()
end
end
function create_stump()
mine()
forward()
mine_up()
turtle.turnRight()
mine()
forward()
mine_up()
torch_stump()
backwards()
turtle.turnLeft()
stump_current = stump_current + 1
end
function return_stump()
branch_current = 0
while branch_current ~= branch_dist do
backwards()
branch_current = branch_current + 1
end
branch_current = 0
end
function mine_branch()
while branch_current ~= branch_dist do
mine()
forward()
mine_up()
torch_branch()
branch_current = branch_current + 1
end
return_stump()
turtle.turnRight()
turtle.turnRight()
forward()
while branch_current ~= branch_dist do
mine()
forward()
mine_up()
torch_branch()
branch_current = branch_current + 1
end
return_stump()
backwards()
turtle.turnLeft()
end
function initialize_branch()
turtle.turnLeft()
mine_branch()
end
stump_branching = 2
while stump_current ~= stump_dist do
create_stump()
if stump_branching == 3 then
initialize_branch()
stump_branching = 0
end
stump_branching = stump_branching + 1
end