From b2403d976a55adf67b3283de3e89c0b9dca07c01 Mon Sep 17 00:00:00 2001 From: brulijam Date: Sun, 2 Jun 2024 01:19:51 +0200 Subject: [PATCH] added fibo miner --- src/main/programs/turtle-miner-fibo.lua | 254 ++++++++++++++++++ .../programs/turtle-miner-stupidExcavate.lua | 16 ++ 2 files changed, 270 insertions(+) create mode 100644 src/main/programs/turtle-miner-fibo.lua diff --git a/src/main/programs/turtle-miner-fibo.lua b/src/main/programs/turtle-miner-fibo.lua new file mode 100644 index 0000000..069d2b3 --- /dev/null +++ b/src/main/programs/turtle-miner-fibo.lua @@ -0,0 +1,254 @@ +basic = require("lib.basic") + +oreList = { + [0] = "minecraft:gold_ore", + [1] = "minecraft:deepslate_gold_ore", + [2] = "minecraft:iron_ore", + [3] = "minecraft:deepslate_iron_ore", + [4] = "minecraft:coal_ore", + [5] = "minecraft:deepslate_coal_ore", + [6] = "minecraft:lapisOre", + [7] = "minecraft:deepslate_lapisOre", + [8] = "minecraft:diamond_ore", + [9] = "minecraft:deepslate_diamond_ore", + [10] = "minecraft:redstone_ore", + [11] = "minecraft:deepslate_redstone_ore", + [12] = "minecraft:emerald_ore", + [13] = "minecraft:deepslate_emerald_ore", + [14] = "minecraft:quartz_ore", + [15] = "minecraft:deepslate_quartz_ore", + [16] = "minecraft:copper_ore", + [17] = "minecraft:deepslate_copper_ore", + [18] = "minecraft:ancient_debris", +} + +throwAwayList = { + [0] = "minecraft:cobblestone", + [1] = "minecraft:dirt", + [2] = "minecraft:gravel", + [3] = "minecraft:andesite", + [4] = "minecraft:cobbled_deepslate", + [5] = "minecraft:diorite", + [6] = "minecraft:tuff", + [7] = "minecraft:netherrack", +} + + +local function setState() + basic.writeToFile("main/files/state-turtle-miner-fibo.txt", textutils.serialize(state)) +end + +local function getState() + if not fs.exists "main/files/state-turtle-miner-fibo.txt" then + turtleState = {} + turtleState["script"] = "main/programs/turtle-miner-fibo.lua" + turtleState["info"] = "" + turtleState["fuelLevel"] = turtle.getFuelLevel() + trutleState["dataCurrentFibo"] = 2 + turtleState["dataGoalRows"] = 0 + turtleState["dataGoalPathProgress"] = 0 + turtleState["dataCurrentRow"] = 0 + turtleState["dataCurrentPathProgress"] = 0 + basic.write_to_file("main/files/state-turtle-miner-fibo.txt", textutils.serialize(turtleState)) + else + turtleState = basic.readFileAll("main/files/state-turtle-miner-fibo.txt") + turtleState = textutils.unserialize(turtleState) + end + return turtleState +end + + + +local function clearInventory() + for i=1, 16 do + turtle.select(i) + item_datail = turtle.getItemDetail() + + for j=0, #throwAwayList do + itemDetail = turtle.getItemDetail() + if itemDetail ~= nil then + if itemDetail.name == throwAwayList[j] then + turtle.dropDown() + end + end + end + end + turtle.select(1) +end + +local function storeItems() + --refuel all + shell.run("refuel all") + + --check inv for chest and place it + chestAvailable = false + for i=1, 16 do + turtle.select(i) + itemDetail = turtle.getItemDetail() + if itemDetail ~= nil then + if itemDetail.name == "minecraft:chest" then + turtle.up() + turtle.digUp() + turtle.up() + turtle.digUp() + turtle.placeUp() + --TODO save in list, where chest is placed + chestAvailable = true + break + elseif i == 16 then + --TODO save in state that no chests are available + end + end + end + + --drop items in chest + if chestAvailable then + for i=1, 16 do + turtle.select(i) + itemDetail = turtle.getItemDetail() + if itemDetail ~= nil then + if itemDetail.name ~= "minecraft:torch" and itemDetail.name ~= "minecraft:chest" then + turtle.dropUp() + turtle.down() + turtle.down() + end + end + end + end +end + +local function checkInventory() + for i=1, 16 do + turtle.select(i) + itemCount = turtle.getItemCount() + if itemCount == 0 then + turtle.select(1) + return + end + end + + storeItems() + turtle.select(1) +end + + +local function isOre(block_data) + for i=0, #ore_list do + if block_data["name"] == ore_list[i] then + return true + end + end + return false +end + +local function recursiveOreMining() + for i=0, 3 do + turtle.turnLeft() + block_found, block_data = turtle.inspect() + if isOre(block_data) then + turtle.dig() + turtle.forward() + recursiveOreMining() + turtle.back() + end + end + + block_found, block_data = turtle.inspectUp() + if isOre(block_data) then + turtle.digUp() + turtle.up() + recursiveOreMining() + turtle.down() + end + + block_found, block_data = turtle.inspectDown() + if isOre(block_data) then + turtle.digDown() + turtle.down() + recursiveOreMining() + turtle.up() + end +end + +local function mineRow(distance) + --mine a 3 Block high Tunnel for Blocks + for i=state["dataCurrentPathProgress"], distance-2 do + print("row: " .. state["dataCurrentRow"]+1 .. "/" .. state["dataGoalRows"] .. ", pathProgress: " .. state["dataCurrentPathProgress"]+1 .. "/" .. state["dataGoalPathProgress"]) + + turtle.dig() + turtle.forward() + turtle.digUp() + turtle.digDown() + + --check current mining step for ore + turtle.up() + recursiveOreMining() + turtle.down() + recursiveOreMining() + turtle.down() + recursiveOreMining() + turtle.up() + + checkInventory() + clearInventory() + + --save path progress + state["dataCurrentPathProgress"] = i+1 + state["fueLevel"] = turtle.getFuelLevel() + setState(state) + end + print("row: " .. state["dataCurrentRow"]+1 .. "/" .. state["dataGoalRows"] .. ", pathProgress: " .. state["dataCurrentPathProgress"]+1 .. "/" .. state["dataGoalPathProgress"]) +end + +local function mineChunk(size) + state = getState() + + state["dataGoalRows"] = size + state["dataGoalPathProgress"] = 3*(size-1)+1 + + for i=state["dataCurrentRow"], state[dataGoalRows]-1 do + mineRow(state["dataGoalPathProgress"]) + + --turn back and return to start of row if not last row + if i