added fibo miner
This commit is contained in:
parent
6f888d184b
commit
b2403d976a
254
src/main/programs/turtle-miner-fibo.lua
Normal file
254
src/main/programs/turtle-miner-fibo.lua
Normal file
@ -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 <distance> 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<state[dataGoalRows]-1 do
|
||||||
|
while not turtle.detect() do
|
||||||
|
turtle.forward()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--go to next row
|
||||||
|
for j=0, 2 do
|
||||||
|
turtle.dig()
|
||||||
|
turtle.forward()
|
||||||
|
turtle.digUp()
|
||||||
|
turtle.digDown()
|
||||||
|
end
|
||||||
|
turtle.turnLeft()
|
||||||
|
turtle.dig()
|
||||||
|
turtle.forward()
|
||||||
|
|
||||||
|
state["dataCurrentRow"] = i+1
|
||||||
|
state["dataCurrentPathProgress"] = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function mineFibo()
|
||||||
|
state = getState()
|
||||||
|
|
||||||
|
while true do
|
||||||
|
mineChunk(state["dataCurrentFibo"])
|
||||||
|
|
||||||
|
--go to next chunk
|
||||||
|
turtle.turnRight()
|
||||||
|
for j=1, 2 do
|
||||||
|
turtle.dig()
|
||||||
|
turtle.forward()
|
||||||
|
turtle.digUp()
|
||||||
|
turtle.digDown()
|
||||||
|
end
|
||||||
|
turtle.turnRight()
|
||||||
|
|
||||||
|
--get next fibo number
|
||||||
|
state["dataCurrentFibo"] = math.floor((state["dataCurrentFibo"] * (1+math.sqrt(5))/2) + 0.5)
|
||||||
|
end
|
||||||
|
end
|
@ -56,4 +56,20 @@ local function digComplete(a)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
height = 120
|
||||||
|
|
||||||
|
120/16=7.5
|
||||||
|
|
||||||
|
15*4=60
|
||||||
|
14*4=56
|
||||||
|
12*4=48
|
||||||
|
10*4=40
|
||||||
|
8*4=32
|
||||||
|
6*4=24
|
||||||
|
4*4=16
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
digComplete(5)
|
digComplete(5)
|
Loading…
Reference in New Issue
Block a user