diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Computercraft.iml b/.idea/Computercraft.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Computercraft.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1b2d693 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d4a50bc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/files/sync-filelist.txt b/src/main/files/sync-filelist.txt new file mode 100755 index 0000000..3b0d3d2 --- /dev/null +++ b/src/main/files/sync-filelist.txt @@ -0,0 +1,13 @@ +{ + [0] = "startup.lua", + [1] = "bos/system-lock.lua", + [2] = "bos/lib/networking.lua", + [3] = "bos/lib/basic-functions.lua", + [4] = "bos/turtle-farmer.lua", + [5] = "bos/turtle-miner.lua", + [6] = "bos/turtle-miner-enderchest.lua", + [7] = "bos/turtle-miner-enderchest2.lua", + [8] = "bos/turtle-wood.lua", + [9] = "bos/turtle-build.lua", + [10] = "bos/stairs.lua", +} diff --git a/src/main/files/sync-targets.txt b/src/main/files/sync-targets.txt new file mode 100755 index 0000000..ce407cf --- /dev/null +++ b/src/main/files/sync-targets.txt @@ -0,0 +1,7 @@ +{ + [ 0 ] = "Turtle Dish", + [ 1 ] = "Wood Dish", + [ 2 ] = "Nether Dish", + [ 3 ] = "Farmer Dish", + [ 4 ] = "Door Panel", +} diff --git a/src/main/files/test-aes.lua b/src/main/files/test-aes.lua deleted file mode 100755 index ce49764..0000000 --- a/src/main/files/test-aes.lua +++ /dev/null @@ -1,15 +0,0 @@ -os.loadAPI("bos/lib/aes.lua") ---aes = require("lib.aes") - - -local encMessage = aes.encrypt("MyKey", "My Message") - -print("encMessage: " .. encMessage) -sleep(2) - -local decMessage = aes.decrypt("MyKey", encMessage) -print("decMessage: " .. decMessage) -sleep(2) - - - diff --git a/src/main/files/test-hash.lua b/src/main/files/test-hash.lua deleted file mode 100755 index 173422d..0000000 --- a/src/main/files/test-hash.lua +++ /dev/null @@ -1,20 +0,0 @@ -os.loadAPI("brammeros/programs/cryptography/hash.lua") - - -while true do - write("Eingabe: ") - message = read() - - hashedMessage = hash.digestStr(message) - print("") - print("Hashed Stuff: " .. hashedMessage) - print("") - print("") -end - - - - - - - diff --git a/src/main/programs/turtle-miner.lua b/src/main/programs/turtle-miner.lua new file mode 100755 index 0000000..07cc4d9 --- /dev/null +++ b/src/main/programs/turtle-miner.lua @@ -0,0 +1,298 @@ +basic_functions = require("lib.basic-functions") + +ore_list = { + [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:quartz_ore", + [15] = "minecraft:deepslate_quartz_ore", + [16] = "minecraft:copper_ore", + [17] = "minecraft:deepslate_copper_ore", + [18] = "minecraft:ancient_debris", +} + +throw_away_list = { + [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 get_fuel_level() + fuel_level = turtle.getFuelLevel() + return fuel_level +end + + + +local function save_state() + basic_functions.write_to_file("bos/files/turtle-state.txt", textutils.serialize(state)) +end + + + +local function get_state() + if not fs.exists "bos/files/turtle-state.txt" then + turtle_state = {} + turtle_state["script"] = "bos/turtle-miner.lua" + turtle_state["info"] = "" + turtle_state["fuel_level"] = get_fuel_level() + 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_functions.write_to_file("bos/files/turtle-state.txt", textutils.serialize(turtle_state)) + else + turtle_state = basic_functions.read_file_all("bos/files/turtle-state.txt") + turtle_state = textutils.unserialize(turtle_state) + end + return turtle_state +end + +local function clear_inventory() + for i=1, 16 do + turtle.select(i) + item_datail = turtle.getItemDetail() + + for j=0, #throw_away_list do + item_detail = turtle.getItemDetail() + if item_detail ~= nil then + if item_detail.name == throw_away_list[j] then + turtle.dropDown() + end + end + end + end + turtle.select(1) +end + +local function store_items() + --check inv for chest and place it + chest_available = false + for i=1, 16 do + turtle.select(i) + item_detail = turtle.getItemDetail() + if item_detail ~= nil then + if item_detail.name == "minecraft:chest" then + turtle.placeDown() + --TODO save in list, where chest is placed + chest_available = true + break + elseif i == 16 then + --TODO save in state that no chests are available + end + end + end + + --drop items in chest + if chest_available then + for i=1, 16 do + turtle.select(i) + item_detail = turtle.getItemDetail() + if item_detail ~= nil then + if item_detail.name ~= "minecraft:torch" and item_detail.name ~= "minecraft:chest" then + turtle.dropDown() + end + end + end + end +end + + + +local function check_inventory() + for i=1, 16 do + turtle.select(i) + item_count = turtle.getItemCount() + if item_count == 0 then + turtle.select(1) + return + end + end + + store_items() + turtle.select(1) +end + + + +local function is_ore(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 check_for_ore() + for i=0, 3 do + turtle.turnLeft() + block_found, block_data = turtle.inspect() + if is_ore(block_data) then + turtle.dig() + turtle.forward() + check_for_ore() + turtle.back() + end + end + + block_found, block_data = turtle.inspectUp() + if is_ore(block_data) then + turtle.digUp() + turtle.up() + check_for_ore() + turtle.down() + end + + block_found, block_data = turtle.inspectDown() + if is_ore(block_data) then + turtle.digDown() + turtle.down() + check_for_ore() + turtle.up() + end +end + +local function place_torch() + for i=1, 16 do + turtle.select(i) + item_detail = turtle.getItemDetail() + + if item_detail ~= nil then + if item_detail.name == "minecraft:torch" then + turtle.placeDown() + end + end + + --pcall_success, item_detail_name = pcall(place_torch_zwei) + + --if pcall_success and item_detail_name == "minecraft:torch" then + -- turtle.placeDown() + -- return true + --end + end +end + + + +function mine_forward(distance) + --mine a 3 Block high Tunnel for Blocks + for i=state["data_current_path_progress"], distance-2 do + + print("row: " .. state["data_current_row"]+1 .. "/" .. state["data_goal_rows"] .. ", path_progress: " .. state["data_current_path_progress"]+1 .. "/" .. state["data_goal_path_progress"]) + + turtle.dig() + turtle.forward() + turtle.digUp() + turtle.digDown() + + --check current mining step for ore + turtle.up() + check_for_ore() + turtle.down() + check_for_ore() + turtle.down() + check_for_ore() + turtle.up() + + if i%8 == 0 then + place_torch() + end + + check_inventory() + clear_inventory() + + --save path progress + state["data_current_path_progress"] = i+1 + state["fuel_level"] = get_fuel_level() + save_state(state) + end + print("row: " .. state["data_current_row"]+1 .. "/" .. state["data_goal_rows"] .. ", path_progress: " .. state["data_current_path_progress"]+1 .. "/" .. state["data_goal_path_progress"]) +end + +function strip_mine(rows, path_progress) + print(">starting strip mining") + sleep(5) + + state = get_state() + + --save rows and path_length as state goal + state["data_goal_rows"] = rows + state["data_goal_path_progress"] = path_progress + save_state() + + if state["fuel_level"] == 0 then + print("OUT OF FUEL") + else + --main for loop + for i=state["data_current_row"], rows-1 do + mine_forward(path_progress) + turtle.turnLeft() + turtle.turnLeft() + + while not turtle.detect() do + turtle.forward() + end + + turtle.turnLeft() + + for j=0, 2 do + turtle.dig() + turtle.forward() + turtle.digUp() + turtle.digDown() + end + + turtle.turnLeft() + turtle.dig() + turtle.forward() + + state["data_current_row"] = i+1 + state["data_current_path_progress"] = 0 + save_state(state) + end + end +end + + + +function mine_stairs_down(length) + for i=0, length do + turtle.dig() + turtle.forward() + turtle.digUp() + turtle.digDown() + turtle.down() + turtle.digDown() + end +end + +state = get_state() +--print(textutils.serialize(state)) + +--store_items() +--strip_mine(50, 200) + +--check_for_ore() +--mine_forward(50) +--mine_forward_fast(20) +--mine_stairs_down(50) +--stairs_up(60) + +