From 9ad825fc60bdbf8f17969f38544ca38d7c95e8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Wed, 19 Aug 2020 23:28:55 +0200 Subject: [PATCH] Mine around turtle at each shaft step --- turtles/mine.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/turtles/mine.lua b/turtles/mine.lua index b365d19..aa5b416 100644 --- a/turtles/mine.lua +++ b/turtles/mine.lua @@ -224,6 +224,56 @@ function find_next_shaft() end end +function is_block_precious(block) + local WORTHY_BLOCKS = { + { name = 'minecraft:coal_ore' }, + { name = 'minecraft:iron_ore' }, + { name = 'minecraft:gold_ore' }, + { name = 'minecraft:lapis_ore' }, + { name = 'minecraft:redstone_ore' }, + { name = 'minecraft:diamond_ore' }, + { name = 'minecraft:emerald_ore' }, + { name = 'ic2:resource', state_type = 'lead_ore' }, + { name = 'ic2:resource', state_type = 'copper_ore' }, + { name = 'ic2:resource', state_type = 'tin_ore' }, + { name = 'ic2:resource', state_type = 'uranium_ore' }, + } + if block then + for id, refblock in ipairs(WORTHY_BLOCKS) do + if block['name'] == refblock['name'] then + if (refblock['state_type'] + and block['state'] and block['state']['type'] + and block['state']['type'] == refblock['state_type']) then + return true + end + end + end + end + return false +end + +-- Mine worthy blocks around the current turtle position +function mine_around() + exists, details = turtle.inspectUp() + if exists and is_block_precious(details) then + turtle.digUp() + end + + exists, details = turtle.inspectDown() + if exists and is_block_precious(details) then + turtle.digDown() + end + + for lookat=1,3,2 do -- lookat in {1,3} + turn_abs(lookat) + exists, details = turtle.inspect() + if exists and is_block_precious(details) then + turtle.dig() + end + end + turn_abs(0) +end + -- Mine a new shaft in front of the turtle function mine_shaft() turn_abs(0) @@ -231,7 +281,10 @@ function mine_shaft() while turtle.detect() do turtle.dig() end + move_forward() + + mine_around() end turn_abs(2) while depth > 0 do