.
This commit is contained in:
parent
692049a22d
commit
0fe33c2aa0
89
src/brulijam/lib/tutel.lua
Normal file
89
src/brulijam/lib/tutel.lua
Normal file
@ -0,0 +1,89 @@
|
||||
--secure digging wrappers
|
||||
local function secureDig()
|
||||
while turtle.detect() do
|
||||
turtle.dig()
|
||||
end
|
||||
end
|
||||
local function secureDigUp()
|
||||
while turtle.detectUp() do
|
||||
turtle.digUp()
|
||||
end
|
||||
end
|
||||
local function secureDigDown()
|
||||
while turtle.detectDown() do
|
||||
turtle.digDown()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--location returning move wrapper
|
||||
--https://www.youtube.com/watch?v=bZe5J8SVCYQ
|
||||
local function forward(x, y, z, rotation)
|
||||
if turtle.forward() then
|
||||
if roation == 0 then
|
||||
z = z + 1
|
||||
elseif rotation == 1 then
|
||||
x = x - 1
|
||||
elseif rotation == 2 then
|
||||
z = z - 1
|
||||
else
|
||||
x = x + 1
|
||||
end
|
||||
end
|
||||
return x,y,z,rotation
|
||||
end
|
||||
|
||||
local function back(x, y, z, rotation)
|
||||
if turtle.back() then
|
||||
if roation == 0 then
|
||||
z = z - 1
|
||||
elseif rotation == 1 then
|
||||
x = x + 1
|
||||
elseif rotation == 2 then
|
||||
z = z + 1
|
||||
else
|
||||
x = x - 1
|
||||
end
|
||||
end
|
||||
return x,y,z,rotation
|
||||
end
|
||||
|
||||
local function up(x, y, z, rotation)
|
||||
if turtle.up() then
|
||||
y = y + 1
|
||||
end
|
||||
return x,y,z,rotation
|
||||
end
|
||||
|
||||
local function down(x, y, z, rotation)
|
||||
if turtle.down() then
|
||||
y = y - 1
|
||||
end
|
||||
return x,y,z,rotation
|
||||
end
|
||||
|
||||
local function left()
|
||||
rotation = (rotation-1) % 4
|
||||
return x,y,z,rotation
|
||||
end
|
||||
|
||||
local function right()
|
||||
rotation = (rotation+1) % 4
|
||||
return x,y,z,rotation
|
||||
end
|
||||
|
||||
|
||||
|
||||
return
|
||||
{
|
||||
secureDig=secureDig,
|
||||
secureDigUp=secureDigUp,
|
||||
secureDigDown=secureDigDown,
|
||||
forward=forward,
|
||||
back=back,
|
||||
up=up,
|
||||
down=down,
|
||||
left=left,
|
||||
right=right,
|
||||
}
|
@ -24,6 +24,8 @@ local copyList = {
|
||||
[16] = "/brulijam/files/shape-hex-64.svg",
|
||||
[17] = "/brulijam/t-farmer.lua",
|
||||
[18] = "/brulijam/t-path-miner.lua",
|
||||
[19] = "/brulijam/lib/tutel.lua",
|
||||
[20] = "/brulijam/t-fiboMiner.lua",
|
||||
}
|
||||
|
||||
|
||||
|
324
src/brulijam/t-fiboMiner.lua
Normal file
324
src/brulijam/t-fiboMiner.lua
Normal file
@ -0,0 +1,324 @@
|
||||
-- This version does not use the gps module because it sometimes fails on servers when no one is online
|
||||
|
||||
|
||||
|
||||
basic = require("lib.basic")
|
||||
tutel = require("lib.tutel")
|
||||
networking = require("lib.networking")
|
||||
|
||||
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:lapis_ore",
|
||||
[7] = "minecraft:deepslate_lapis_ore",
|
||||
[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:nether_quartz_ore",
|
||||
[15] = "minecraft:nether_gold_ore",
|
||||
[16] = "minecraft:copper_ore",
|
||||
[17] = "minecraft:deepslate_copper_ore",
|
||||
[18] = "minecraft:ancient_debris",
|
||||
}
|
||||
|
||||
keepList = {
|
||||
[0] = "computercraft:wireless_modem_advanced",
|
||||
[1] = "minecraft:chest",
|
||||
[2] = "minecraft:barrel",
|
||||
[3] = "minecraft:raw_gold",
|
||||
[4] = "minecraft:raw_iron",
|
||||
[5] = "minecraft:coal",
|
||||
[6] = "minecraft:lapis_lazuli",
|
||||
[7] = "minecraft:diamond",
|
||||
[8] = "minecraft:redstone",
|
||||
[9] = "minecraft:emerald",
|
||||
[10] = "minecraft:quartz",
|
||||
[11] = "minecraft:gold_nugget",
|
||||
[12] = "minecraft:ancient_debris",
|
||||
[13] = "minecraft:raw_copper",
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local function setState()
|
||||
basic.writeToFile("brulijam/files/state-t-fiboMiner.txt", textutils.serialize(state))
|
||||
end
|
||||
|
||||
local function getState()
|
||||
if not fs.exists "brulijam/files/state-t-fiboMiner.txt" then
|
||||
turtleState = {}
|
||||
turtleState["dataCurrentFibo"] = 2
|
||||
turtleState["dataGoalRows"] = 0
|
||||
turtleState["dataGoalPathProgress"] = 0
|
||||
turtleState["dataCurrentRow"] = 0
|
||||
turtleState["dataCurrentPathProgress"] = 0
|
||||
turtleState["posX"] = 0
|
||||
turtleState["posY"] = 0
|
||||
turtleState["posZ"] = 0
|
||||
turtleState["rotation"] = 0 --towards south (pos Z)
|
||||
turtleState["startX"] = 0
|
||||
turtleState["startY"] = 0
|
||||
turtleState["startZ"] = 0
|
||||
|
||||
|
||||
basic.writeToFile("brulijam/files/state-t-fiboMiner.txt", textutils.serialize(turtleState))
|
||||
else
|
||||
turtleState = basic.readFileAll("brulijam/files/state-t-fiboMiner.txt")
|
||||
turtleState = textutils.unserialize(turtleState)
|
||||
end
|
||||
return turtleState
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
turtle.select(i)
|
||||
itemDetail = turtle.getItemDetail()
|
||||
|
||||
if itemDetail ~= nil then
|
||||
if itemDetail.name == "computercraft:wireless_modem_advanced" then
|
||||
turtle.equipRight()
|
||||
posZ, posY, posX = gps.locate()
|
||||
sleep(1)
|
||||
if prefix == "Chest placed at " 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" or itemDetail.name == "minecraft:barrel" 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 at ")
|
||||
|
||||
for k=1, 16 do
|
||||
turtle.select(k)
|
||||
itemDetail = turtle.getItemDetail()
|
||||
if itemDetail ~= nil then
|
||||
if itemDetail.name ~= "minecraft:chest" and itemDetail.name ~= "minecraft:barrel" 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 isOre(blockData)
|
||||
for i=0, #oreList do
|
||||
if blockData["name"] == oreList[i] then
|
||||
inventoryRework()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function recursiveOreMining()
|
||||
for i=0, 3 do
|
||||
turtle.turnLeft()
|
||||
blockFound, blockData = turtle.inspect()
|
||||
if isOre(blockData) then
|
||||
tutel.secureDig()
|
||||
turtle.forward()
|
||||
recursiveOreMining()
|
||||
turtle.back()
|
||||
end
|
||||
end
|
||||
|
||||
blockFound, blockData = turtle.inspectUp()
|
||||
if isOre(blockData) then
|
||||
tutel.secureDigUp()
|
||||
turtle.up()
|
||||
recursiveOreMining()
|
||||
turtle.down()
|
||||
end
|
||||
|
||||
blockFound, blockData = turtle.inspectDown()
|
||||
if isOre(blockData) then
|
||||
tutel.secureDigDown()
|
||||
turtle.down()
|
||||
recursiveOreMining()
|
||||
turtle.up()
|
||||
end
|
||||
end
|
||||
|
||||
local function mineRow()
|
||||
--mine a 3 Block high Tunnel for <distance> Blocks
|
||||
for i=state["dataCurrentPathProgress"], state["dataGoalPathProgress"]-2 do
|
||||
print("row: " .. state["dataCurrentRow"]+1 .. "/" .. state["dataGoalRows"] .. ", pathProgress: " .. state["dataCurrentPathProgress"]+1 .. "/" .. state["dataGoalPathProgress"])
|
||||
|
||||
tutel.secureDig()
|
||||
turtle.forward()
|
||||
tutel.secureDigUp()
|
||||
tutel.secureDigDown()
|
||||
|
||||
--clearInventory()
|
||||
--inventoryRework()
|
||||
|
||||
--check current mining step for ore
|
||||
turtle.up()
|
||||
recursiveOreMining()
|
||||
turtle.down()
|
||||
recursiveOreMining()
|
||||
turtle.down()
|
||||
recursiveOreMining()
|
||||
turtle.up()
|
||||
|
||||
inventoryRework()
|
||||
--clearInventory()
|
||||
--checkInventory()
|
||||
|
||||
--save path progress
|
||||
state["dataCurrentPathProgress"] = i+1
|
||||
setState(state)
|
||||
end
|
||||
print("row: " .. state["dataCurrentRow"]+1 .. "/" .. state["dataGoalRows"] .. ", pathProgress: " .. state["dataCurrentPathProgress"]+1 .. "/" .. state["dataGoalPathProgress"])
|
||||
end
|
||||
|
||||
local function mineChunk()
|
||||
state = getState()
|
||||
|
||||
state["dataGoalRows"] = state["dataCurrentFibo"]
|
||||
state["dataGoalPathProgress"] = 3*(state["dataCurrentFibo"]-1)+1
|
||||
setState(state)
|
||||
|
||||
for i=state["dataCurrentRow"], state["dataGoalRows"]-1 do
|
||||
sleep(0.5)
|
||||
mineRow(state["dataGoalPathProgress"])
|
||||
|
||||
--turn back and return to start of row if not last row
|
||||
if i<state["dataGoalRows"]-1 then
|
||||
turtle.turnLeft()
|
||||
turtle.turnLeft()
|
||||
|
||||
for j=1, state["dataGoalPathProgress"]-1 do
|
||||
turtle.forward()
|
||||
end
|
||||
|
||||
--go to next row
|
||||
turtle.turnLeft()
|
||||
for j=0, 2 do
|
||||
tutel.secureDig()
|
||||
turtle.forward()
|
||||
tutel.secureDigUp()
|
||||
tutel.secureDigDown()
|
||||
end
|
||||
turtle.turnLeft()
|
||||
end
|
||||
|
||||
state["dataCurrentRow"] = i+1
|
||||
state["dataCurrentPathProgress"] = 0
|
||||
end
|
||||
|
||||
--reset row progress
|
||||
state["dataCurrentRow"] = 0
|
||||
end
|
||||
|
||||
local function mineFibo()
|
||||
state = getState()
|
||||
|
||||
while true do
|
||||
mineChunk()
|
||||
|
||||
--go to next chunk
|
||||
turtle.turnRight()
|
||||
for j=1, 2 do
|
||||
tutel.secureDig()
|
||||
turtle.forward()
|
||||
tutel.secureDigUp()
|
||||
tutel.secureDigDown()
|
||||
end
|
||||
|
||||
--get next fibo number
|
||||
state["dataCurrentFibo"] = math.floor((state["dataCurrentFibo"] * (1+math.sqrt(5))/2) + 0.5)
|
||||
setState(state)
|
||||
end
|
||||
end
|
||||
|
||||
if fs.exists "brulijam/files/state-t-fiboMiner.txt" then
|
||||
--setup()
|
||||
mineFibo()
|
||||
else
|
||||
state = getState()
|
||||
|
||||
write("x: ")
|
||||
startX = read()
|
||||
write("y: ")
|
||||
startY = read()
|
||||
write("z: ")
|
||||
startZ = read()
|
||||
write("rotation (S=0,W=1,N=2,E=3):")
|
||||
rotation = read()
|
||||
|
||||
turtleState["posX"] = startX
|
||||
turtleState["posY"] = startY
|
||||
turtleState["posZ"] = startZ
|
||||
turtleState["rotation"] = rotation
|
||||
|
||||
turtleState["startX"] = startX
|
||||
turtleState["startY"] = startY
|
||||
turtleState["startZ"] = startZ
|
||||
end
|
||||
|
@ -3,6 +3,7 @@
|
||||
local function mineStraightLine(length)
|
||||
slot = 1
|
||||
for i=1, length do
|
||||
print(i)
|
||||
turtle.digUp()
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
|
Loading…
Reference in New Issue
Block a user