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