Updated StripMiner

Added support for chest and improved some codes.
This commit is contained in:
Jacob Stevens 2023-11-20 22:07:31 -06:00
parent f15bb5fffb
commit c0a61301c0
1 changed files with 75 additions and 11 deletions

View File

@ -7,6 +7,7 @@ stump_current = 0
branch_dist = 32 branch_dist = 32
branch_lighting = 7 branch_lighting = 7
branch_current = 0 branch_current = 0
return_dist = 0
function mine() function mine()
while turtle.detect() do while turtle.detect() do
@ -27,11 +28,10 @@ function check_fuel()
term.setCursorPos(1,1) term.setCursorPos(1,1)
if turtle.getFuelLevel() <= 0 then if turtle.getFuelLevel() <= 0 then
print("Looking for fuel...") print("Looking for fuel...")
i = 1 for i = 1,16 do
while i ~= 16 do
turtle.select(i) turtle.select(i)
turtle.refuel() turtle.refuel()
i = i + 1 break
end end
end end
if turtle.getFuelLevel() <= 0 then if turtle.getFuelLevel() <= 0 then
@ -43,7 +43,19 @@ end
function forward() function forward()
check_fuel() check_fuel()
turtle.forward() if not turtle.forward() then
for i = 1,16 do
turtle.select(i)
item = turtle.getItemDetail()
if item ~= nil then
if not string.find(item["name"], "torch") or not string.find(item["name"], "chest") then
turtle.placeDown()
break
end
end
forward()
end
end
end end
function backwards() function backwards()
@ -54,18 +66,17 @@ end
function torch() function torch()
s = false s = false
i = 1 i = 1
while i ~= 17 do for i = 1,16 do
turtle.select(i) turtle.select(i)
item = turtle.getItemDetail() item = turtle.getItemDetail()
if item ~= nil then if item ~= nil then
print(item["name"])
if string.find(item["name"], "torch") then if string.find(item["name"], "torch") then
turtle.select(i) turtle.select(i)
turtle.placeUp() turtle.placeUp()
s = true s = true
break
end end
end end
i = i + 1
end end
if not s then if not s then
print("Could not place a torch...") print("Could not place a torch...")
@ -86,6 +97,59 @@ function torch_branch()
end end
end end
function check_inventory()
for i = 1,16 do
if turtle.getItemSpace(i) > 0 then
return false
end
end
return true
end
function storage_check()
if not check_inventory() then
return_dist = branch_current
return_stump()
forward()
turtle.turnRight()
mine()
forward()
turtle.digDown()
for i = 1,16 do
turtle.select(i)
item = turtle.getItemDetail()
if item ~= nil then
if string.find(item["name"], "chest") then
if turtle.getItemCount() > 1 then
mine()
forward()
turtle.digDown()
turtle.placeDown()
backwards()
end
turtle.placeDown()
end
end
end
for i = 1,16 do
turtle.select(i)
item = turtle.getItemDetail()
if item ~= nil then
if not string.find(item["name"], "torch") or not string.find(item["name"], "chest") then
turtle.dropDown()
end
end
end
backwards()
turtle.turnRight()
branch_current = return_dist - 1
return_stump()
turtle.turnRight()
turtle.turnRight()
branch_current = return_dist
end
end
function create_stump() function create_stump()
mine() mine()
forward() forward()
@ -101,16 +165,15 @@ function create_stump()
end end
function return_stump() function return_stump()
branch_current = 0 while branch_current ~= 0 do
while branch_current ~= branch_dist do
backwards() backwards()
branch_current = branch_current + 1 branch_current = branch_current - 1
end end
branch_current = 0
end end
function mine_branch() function mine_branch()
while branch_current ~= branch_dist do while branch_current ~= branch_dist do
check_inventory()
mine() mine()
forward() forward()
mine_up() mine_up()
@ -122,6 +185,7 @@ function mine_branch()
turtle.turnRight() turtle.turnRight()
forward() forward()
while branch_current ~= branch_dist do while branch_current ~= branch_dist do
check_inventory()
mine() mine()
forward() forward()
mine_up() mine_up()