refactor
This commit is contained in:
parent
76b35697fa
commit
18abd20cbf
@ -2,25 +2,25 @@
|
||||
basic_functions = require("lib.basic-functions")
|
||||
hash = require("lib.hash")
|
||||
--aes = require("lib.aes") --aes does not yet work with require
|
||||
os.loadAPI("bos/lib/aes.lua")
|
||||
os.loadAPI("brulijam/lib/aes.lua")
|
||||
|
||||
function create_keyfile()
|
||||
basic_functions.clear_display()
|
||||
write("Please enter shared secret for networking: ")
|
||||
local pw_hash = hash.digestStr(read("*") .. "salty salt")
|
||||
basic_functions.write_to_file("bos/files/networking-key.txt", pw_hash)
|
||||
basic_functions.write_to_file("brulijam/files/networking-key.txt", pw_hash)
|
||||
basic_functions.clear_display()
|
||||
end
|
||||
|
||||
local function get_keyfile()
|
||||
local pw_hash = basic_functions.read_file_oneline("bos/files/networking-key.txt")
|
||||
local pw_hash = basic_functions.read_file_oneline("brulijam/files/networking-key.txt")
|
||||
return pw_hash
|
||||
end
|
||||
|
||||
local function setup()
|
||||
own_label = os.computerLabel()
|
||||
peripheral.find("modem", rednet.open)
|
||||
if not fs.exists "bos/files/networking-key.txt" then
|
||||
if not fs.exists "brulijam/files/networking-key.txt" then
|
||||
create_keyfile()
|
||||
end
|
||||
end
|
||||
|
@ -1,15 +1,15 @@
|
||||
local prefix = "https://git.brulijam.com/brulijam/Computercraft/raw/branch/main/src"
|
||||
local prefix = "https://git.brulijam.com/brulijam/Computercraft/raw/branch/brulijam/src"
|
||||
|
||||
local copyList = {
|
||||
[0] = "/main/programs/sync.lua",
|
||||
[0] = "/brulijam/programs/sync.lua",
|
||||
[1] = "/startup.lua",
|
||||
[2] = "/main/programs/lib/aes.lua",
|
||||
[3] = "/main/programs/lib/hash.lua",
|
||||
[4] = "/main/programs/lib/basic.lua",
|
||||
[5] = "/main/programs/turtle-roomCreator.lua",
|
||||
[6] = "/main/programs/turtle-miner-stupidExcavate.lua",
|
||||
[7] = "/main/programs/turtle-miner-fibo.lua",
|
||||
[8] = "/main/programs/turtle-treeFarmer.lua",
|
||||
[2] = "/brulijam/programs/lib/aes.lua",
|
||||
[3] = "/brulijam/programs/lib/hash.lua",
|
||||
[4] = "/brulijam/programs/lib/basic.lua",
|
||||
[5] = "/brulijam/programs/turtle-roomCreator.lua",
|
||||
[6] = "/brulijam/programs/turtle-miner-stupidExcavate.lua",
|
||||
[7] = "/brulijam/programs/turtle-miner-fibo.lua",
|
||||
[8] = "/brulijam/programs/turtle-treeFarmer.lua",
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
basic = require("lib.basic")
|
||||
|
||||
oreList = {
|
||||
keepList = {
|
||||
[0] = "minecraft:gold_ore",
|
||||
[1] = "minecraft:deepslate_gold_ore",
|
||||
[2] = "minecraft:iron_ore",
|
||||
@ -21,29 +21,17 @@ oreList = {
|
||||
[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:granite",
|
||||
[7] = "minecraft:tuff",
|
||||
[8] = "minecraft:netherrack",
|
||||
[9] = "minecraft:clay_ball",
|
||||
}
|
||||
|
||||
|
||||
|
||||
local function setState()
|
||||
basic.writeToFile("main/files/state-turtle-miner-fibo.txt", textutils.serialize(state))
|
||||
basic.writeToFile("brulijam/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
|
||||
if not fs.exists "brulijam/files/state-turtle-miner-fibo.txt" then
|
||||
turtleState = {}
|
||||
turtleState["script"] = "main/programs/turtle-miner-fibo.lua"
|
||||
turtleState["script"] = "brulijam/programs/turtle-miner-fibo.lua"
|
||||
turtleState["info"] = ""
|
||||
turtleState["fuelLevel"] = turtle.getFuelLevel()
|
||||
turtleState["dataCurrentFibo"] = 2
|
||||
@ -51,9 +39,9 @@ local function getState()
|
||||
turtleState["dataGoalPathProgress"] = 0
|
||||
turtleState["dataCurrentRow"] = 0
|
||||
turtleState["dataCurrentPathProgress"] = 0
|
||||
basic.writeToFile("main/files/state-turtle-miner-fibo.txt", textutils.serialize(turtleState))
|
||||
basic.writeToFile("brulijam/files/state-turtle-miner-fibo.txt", textutils.serialize(turtleState))
|
||||
else
|
||||
turtleState = basic.readFileAll("main/files/state-turtle-miner-fibo.txt")
|
||||
turtleState = basic.readFileAll("brulijam/files/state-turtle-miner-fibo.txt")
|
||||
turtleState = textutils.unserialize(turtleState)
|
||||
end
|
||||
return turtleState
|
||||
@ -65,15 +53,21 @@ local function clearInventory()
|
||||
for i=1, 16 do
|
||||
turtle.select(i)
|
||||
itemDetail = turtle.getItemDetail()
|
||||
local keepItem = false
|
||||
|
||||
for j=0, #throwAwayList do
|
||||
for j=0, #keepList do
|
||||
itemDetail = turtle.getItemDetail()
|
||||
if itemDetail ~= nil then
|
||||
if itemDetail.name == throwAwayList[j] then
|
||||
turtle.dropDown()
|
||||
if itemDetail.name == keepList[j] then
|
||||
--turtle.dropDown()
|
||||
keepItem = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not keepItem then
|
||||
turtle.dropDown()
|
||||
end
|
||||
end
|
||||
turtle.select(1)
|
||||
end
|
||||
@ -108,7 +102,7 @@ local function storeItems()
|
||||
break
|
||||
elseif i == 16 then
|
||||
--TODO save in state that no chests are available
|
||||
shell.run("delete /main/task.lua")
|
||||
shell.run("delete /brulijam/task.lua")
|
||||
shell.run("reboot")
|
||||
end
|
||||
end
|
||||
@ -146,8 +140,8 @@ end
|
||||
|
||||
|
||||
local function isOre(blockData)
|
||||
for i=0, #oreList do
|
||||
if blockData["name"] == oreList[i] then
|
||||
for i=0, #keepList do
|
||||
if blockData["name"] == keepList[i] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -1,11 +1,11 @@
|
||||
basic = require("lib.basic")
|
||||
|
||||
local function setState()
|
||||
basic.writeToFile("main/files/state-turtle-miner-stupidExcavate.txt", textutils.serialize(state))
|
||||
basic.writeToFile("brulijam/files/state-turtle-miner-stupidExcavate.txt", textutils.serialize(state))
|
||||
end
|
||||
|
||||
local function getState()
|
||||
state = basic.readFileAll("main/files/state-turtle-miner-stupidExcavate.txt")
|
||||
state = basic.readFileAll("brulijam/files/state-turtle-miner-stupidExcavate.txt")
|
||||
state = textutils.unserialize(state)
|
||||
return state
|
||||
end
|
||||
@ -57,19 +57,6 @@ local function digComplete(a)
|
||||
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)
|
@ -34,24 +34,24 @@ throw_away_list = {
|
||||
}
|
||||
|
||||
local function save_state()
|
||||
basic.write_to_file("main/files/turtle-state.txt", textutils.serialize(state))
|
||||
basic.write_to_file("brulijam/files/turtle-state.txt", textutils.serialize(state))
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function get_state()
|
||||
if not fs.exists "main/files/turtle-state.txt" then
|
||||
if not fs.exists "brulijam/files/turtle-state.txt" then
|
||||
turtle_state = {}
|
||||
turtle_state["script"] = "main/turtle-miner.lua"
|
||||
turtle_state["script"] = "brulijam/turtle-miner.lua"
|
||||
turtle_state["info"] = ""
|
||||
turtle_state["fuel_level"] = turtle.getFuelLevel()
|
||||
turtle_state["data_goal_rows"] = 0
|
||||
turtle_state["data_goal_path_progress"] = 0
|
||||
turtle_state["data_current_row"] = 0
|
||||
turtle_state["data_current_path_progress"] = 0
|
||||
basic.write_to_file("main/files/turtle-state.txt", textutils.serialize(turtle_state))
|
||||
basic.write_to_file("brulijam/files/turtle-state.txt", textutils.serialize(turtle_state))
|
||||
else
|
||||
turtle_state = basic.read_file_all("main/files/turtle-state.txt")
|
||||
turtle_state = basic.read_file_all("brulijam/files/turtle-state.txt")
|
||||
turtle_state = textutils.unserialize(turtle_state)
|
||||
end
|
||||
return turtle_state
|
||||
@ -233,7 +233,7 @@ function strip_mine(rows, path_progress)
|
||||
if state["fuel_level"] == 0 then
|
||||
print("OUT OF FUEL")
|
||||
else
|
||||
--main for loop
|
||||
--brulijam for loop
|
||||
for i=state["data_current_row"], rows-1 do
|
||||
mine_forward(path_progress)
|
||||
turtle.turnLeft()
|
||||
|
@ -1,4 +1,4 @@
|
||||
local fallingTreeModUsed = true
|
||||
local fallingTreeModUsed = false
|
||||
|
||||
woodList = {
|
||||
[0] = "minecraft:oak_log",
|
||||
@ -82,7 +82,7 @@ local function emptyInventory()
|
||||
end
|
||||
end
|
||||
|
||||
function main()
|
||||
function brulijam()
|
||||
if fallingTreeModUsed then
|
||||
while true do
|
||||
blockFound, blockData = turtle.inspect()
|
||||
@ -118,4 +118,4 @@ function main()
|
||||
end
|
||||
end
|
||||
|
||||
main()
|
||||
brulijam()
|
||||
|
@ -1,18 +1,18 @@
|
||||
|
||||
--fetch sync script
|
||||
local repo = "https://git.brulijam.com/brulijam/Computercraft/raw/branch/main/src"
|
||||
getRequest = http.get(repo .. "/main/programs/sync.lua")
|
||||
file = fs.open("/main/programs/sync.lua", "w")
|
||||
getRequest = http.get(repo .. "/brulijam/programs/sync.lua")
|
||||
file = fs.open("/brulijam/programs/sync.lua", "w")
|
||||
file.write(getRequest.readAll())
|
||||
file.close()
|
||||
|
||||
--execute sync script
|
||||
shell.run("/main/programs/sync.lua")
|
||||
shell.run("/brulijam/programs/sync.lua")
|
||||
|
||||
--task.lua contains stuff that should be done after boot
|
||||
if not (fs.exists("main/task.lua")) then
|
||||
file = fs.open("main/task.lua", "a")
|
||||
if not (fs.exists("brulijam/task.lua")) then
|
||||
file = fs.open("brulijam/task.lua", "a")
|
||||
file.writeLine("--use this file to execute programs")
|
||||
file.close()
|
||||
end
|
||||
shell.run("main/task.lua")
|
||||
shell.run("brulijam/task.lua")
|
||||
|
Loading…
Reference in New Issue
Block a user