diff --git a/src/main/programs/turtle-chaosMine.lua b/src/main/programs/turtle-chaosMine.lua new file mode 100644 index 0000000..15e1a15 --- /dev/null +++ b/src/main/programs/turtle-chaosMine.lua @@ -0,0 +1,153 @@ +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", +} + +local function get_fuel_level() + fuel_level = turtle.getFuelLevel() + return fuel_level +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 digForward(length) + for i=0, length do + turtle.dig() + turtle.forward() + end +end + +local function digUpward(length) + for i=0, length do + turtle.dig() + turtle.up() + end +end + +local function digDownward(length) + for i=0, length do + turtle.digDown() + turtle.down() + end +end + + +function chaosMine() + direction1 = math.random(0,2) + length = math.random(3,6) + + if direction == 0 then + direction2 = math.random(0,3) + for i=0, 3 do + turtle.turnRight() + end + digForward(length) + elseif direction == 1 then + digUpward(length) + elseif direction == 2 then + digDownward(length) + end + chaosMine() +end + + +