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_lighting = 7
branch_current = 0
return_dist = 0
function mine()
while turtle.detect() do
@ -27,11 +28,10 @@ function check_fuel()
term.setCursorPos(1,1)
if turtle.getFuelLevel() <= 0 then
print("Looking for fuel...")
i = 1
while i ~= 16 do
for i = 1,16 do
turtle.select(i)
turtle.refuel()
i = i + 1
break
end
end
if turtle.getFuelLevel() <= 0 then
@ -43,7 +43,19 @@ end
function forward()
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
function backwards()
@ -54,18 +66,17 @@ end
function torch()
s = false
i = 1
while i ~= 17 do
for i = 1,16 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
break
end
end
i = i + 1
end
if not s then
print("Could not place a torch...")
@ -86,6 +97,59 @@ function torch_branch()
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()
mine()
forward()
@ -101,16 +165,15 @@ function create_stump()
end
function return_stump()
branch_current = 0
while branch_current ~= branch_dist do
while branch_current ~= 0 do
backwards()
branch_current = branch_current + 1
branch_current = branch_current - 1
end
branch_current = 0
end
function mine_branch()
while branch_current ~= branch_dist do
check_inventory()
mine()
forward()
mine_up()
@ -122,6 +185,7 @@ function mine_branch()
turtle.turnRight()
forward()
while branch_current ~= branch_dist do
check_inventory()
mine()
forward()
mine_up()