Skip to content

Instantly share code, notes, and snippets.

@ejaszewski
Last active December 6, 2020 04:28
Show Gist options
  • Save ejaszewski/481b80b365fd99755930601ba8298aa7 to your computer and use it in GitHub Desktop.
Save ejaszewski/481b80b365fd99755930601ba8298aa7 to your computer and use it in GitHub Desktop.
ComputerCraft Utils
minecraft:dirt
minecraft:gravel
minecraft:stone
minecraft:cobblestone
quark:slate
quark:jasper
rustic:slate
chisel:marble2
chisel:limestone2
local ignoreList = {}
function loadIgnoreList()
local ignoreListFile = fs.open("ignore.txt", "r")
local line = ignoreListFile.readLine()
while line ~= nil do
table.insert(ignoreList, line)
line = ignoreListFile.readLine()
end
end
--[[
List Functions
]]--
function isMember(t, x)
for _, val in pairs(t) do
if val == x then
return true
end
end
return false
end
--[[
Stack Functions
]]--
function push(t, x)
table.insert(t, x)
end
function peek(t)
return t[#t]
end
function pop(t)
return table.remove(t, #t)
end
--[[
Mining Functions
]]--
function isOre(block)
return not isMember(ignoreList, block.name)
end
function inspectDir(dir)
if dir == "forward" then
return turtle.inspect()
elseif dir == "up" then
return turtle.inspectUp()
elseif dir == "down" then
return turtle.inspectDown()
end
end
function digVein(dir)
local success, block = inspectDir(dir)
-- Don't explore ignored blocks or air
if not success or not isOre(block) then
return
end
if dir == "forward" then
-- Go to the block in front
turtle.dig()
turtle.forward()
-- Explore above
digVein("up")
-- Explore below
digVein("down")
-- Explore to the left
turtle.turnLeft()
digVein("forward")
turtle.turnRight()
-- Explore in front
digVein("forward")
-- Explore to the right
turtle.turnRight()
digVein("forward")
turtle.turnLeft()
-- Backtrack
turtle.back()
elseif dir == "up" or dir == "down" then
if dir == "up" then
-- Go to the block above
turtle.digUp()
turtle.up()
-- Explore above
digVein("up")
else
-- Go to the block below
turtle.digDown()
turtle.down()
-- Explore below
digVein("down")
end
-- Explore blocks around
for i = 1, 4 do
digVein("forward")
turtle.turnRight()
end
if dir == "up" then
-- Backtrack
turtle.down()
else
-- Backtrack
turtle.up()
end
end
end
function digTunnel(len)
for i = 1, len do
-- Check for a vein above
local success, above = turtle.inspectUp()
if success and isOre(above) then
digVein("above")
end
-- Check for a vein below
local success, below = turtle.inspectDown()
if success and isOre(below) then
digVein("below")
end
-- Check for a vein to the left
turtle.turnLeft()
local success, left = turtle.inspect()
if success and isOre(left) then
digVein("forward")
end
turtle.turnRight()
-- Check for a vein to the right
turtle.turnRight()
local success, right = turtle.inspect()
if success and isOre(right) then
digVein("forward")
end
turtle.turnLeft()
-- Check for a vein in front and move forward
local success, forward = turtle.inspect()
if not success then
turtle.forward()
elseif not isOre(block) then
turtle.dig()
turtle.forward()
else
digVein("forward")
turtle.forward()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment