refactored mining

This commit is contained in:
Julian Brammer 2024-06-08 18:33:01 +02:00
parent 00e6e045cf
commit fdf83cfdaa
2 changed files with 75 additions and 7 deletions

View File

@ -65,7 +65,7 @@ local function getState()
end
local function savePositionToFile()
local function savePos(prefix)
--swap modem with Pickaxe
--by convention the chunkloader is always left, so that Tools are right
for i=1, 16 do
@ -77,14 +77,79 @@ local function savePositionToFile()
turtle.equipRight()
posZ, posY, posX = gps.locate()
sleep(1)
basic.appendToFileNl("/brulijam/files/chests-turtle-miner-fibo.txt", "Chest at: " .. posX .. ", " .. posY .. ", " .. posZ)
networking.sendLog("all", "/brulijam/logs/chests-to-collect.txt", posX .. ", " .. posY .. ", " .. posZ)
if prefix == "Chest placed" then
posY = posY + 1
end
basic.appendToFileNl("/brulijam/files/chests-turtle-miner-fibo.txt", "[" .. prefix .. "] " .. posX .. ", " .. posY .. ", " .. posZ)
networking.sendLog("all", "/brulijam/logs/chests-to-collect.txt", "[" .. prefix .. "] " .. posX .. ", " .. posY .. ", " .. posZ)
turtle.equipRight()
end
end
end
end
local function inventoryRework()
chestAvailable = false
chestSlot = 0
spaceAvailable = false
for i=1, 16 do
turtle.select(i)
itemDetail = turtle.getItemDetail()
if itemDetail ~= nil then
if itemDetail.name == "minecraft:coal" then
turtle.refuel()
spaceAvailable = true
elseif itemDetail.name == "minecraft:chest" then
chestAvailable = true
chestSlot = i
else --check if item can be thrown away
keepItem = false
for j=0, #keepList do
if itemDetail.name == keepList[j] then
keepItem = true
end
end
if not keepItem then
turtle.dropDown()
spaceAvailable = true
end
end
else --at least one slot of space remaining
spaceAvailable = true
end
end
--store items away
if not spaceAvailable and chestAvailable then
turtle.up()
basic.secureDigUp()
turtle.up()
basic.secureDigUp()
turtle.select(chestSlot)
turtle.placeUp()
savePos("Chest placed")
for k=1, 16 do
turtle.select(i)
itemDetail = turtle.getItemDetail()
if itemDetail ~= nil then
if itemDetail.name ~= "minecraft:chest" and itemDetail.name ~= "computercraft:wireless_modem_advanced" then
turtle.dropUp()
end
end
end
turtle.down()
turtle.down()
end
if not spaceAvailable and not chestAvailable then
savePos("Turtle stopped")
shell.run("delete /brulijam/task.lua")
shell.run("reboot")
end
end
local function clearInventory()
for i=1, 16 do
@ -134,7 +199,7 @@ local function storeItems()
turtle.up()
basic.secureDigUp()
turtle.placeUp()
savePositionToFile()
savePos()
chestAvailable = true
break
elseif i == 16 then
@ -224,7 +289,8 @@ local function mineRow()
basic.secureDigUp()
basic.secureDigDown()
clearInventory()
--clearInventory()
--inventoryRework()
--check current mining step for ore
turtle.up()
@ -235,8 +301,9 @@ local function mineRow()
recursiveOreMining()
turtle.up()
clearInventory()
checkInventory()
inventoryRework()
--clearInventory()
--checkInventory()
--save path progress
state["dataCurrentPathProgress"] = i+1

View File

@ -54,6 +54,7 @@ local function placeTree()
if itemDetail.name == "minecraft:spruce_sapling" then
local blockFound, blockData = turtle.inspect()
if not blockFound then
sleep(3)
turtle.up()
turtle.forward()
turtle.suckDown()