-- Strip Mining Program V1.7.1 --
-- Includes anti-gravel protocol --
-- Mines until full, then terminates --
-- tunnels are always two wide, 3 high in current version --
-- Planned features --
-- Rednet connection to central monitor for hub monitoring of all mining turtles, includes inventory fill status --
-- Config --
Mside = "right" -- set to whatever side the modem is on the turtle
chn = 1 -- set to channel you want to transmit on
-- Defining tables and variables --
local ores = {
["minecraft:diamond_ore"]=true,
["minecraft:emerald_ore"]=true,
["minecraft:emerald_ore"]=true,
["minecraft:gold_ore"]=true,
["minecraft:iron_ore"]=true,
["minecraft:redstone_ore"]=true,
["minecraft:lapis_ore"]=true,
["minecraft:coal_ore"]=true,
["ic2:blockmetal"]=true,
["galacticraftcore:basic_block_core"] = true
}
local gravel = {
["minecraft:gravel"]=true
}
local inv = {}
local Cscan = {}
local logFile = fs.open("minelog", "a")
-- Assinging functions --
function log(data) -- function to write data into minelog file
logFile.writeLine(data)
end
function minenup(repeats) -- turtle moving up then mining
cl()
print("Mining...")
for i = 1,repeats do
turtle.up()
turtle.dig()
scan()
cl()
print("Mining...")
end
end
function minend(repeats) -- turtle moving down then mining
cl()
print("Mining...")
for l = 1,repeats do
turtle.down()
turtle.dig()
scan()
cl()
print("Mining...")
end
end
function scan() -- scanning blocks around turtle
cl()
print("Scanning surroundings...")
success, Cscan = turtle.inspectUp()
if ores[Cscan.name] then
turtle.digUp()
log(Cscan.name)
end
success, Cscan = turtle.inspectDown()
if ores[Cscan.name] then
turtle.digDown()
log(Cscan.name)
end
for i = 1,4 do
success, Cscan = turtle.inspect()
if ores[Cscan.name] then
log(Cscan.name)
turtle.dig()
turtle.turnRight()
elseif gravel[Cscan.name] then
while gravel[Cscan.name] do
turtle.dig()
success, Cscan = turtle.inspect()
end
turtle.turnRight()
else
turtle.turnRight()
end
end
end
function mineLayer()
cl()
print("Mining...")
for k = 1,2 do
readInv()
scan()
turtle.dig()
minenup(2)
readInv()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.dig()
scan()
minend(2)
turtle.forward()
turtle.turnRight()
scan()
turtle.forward()
turtle.turnLeft()
readInv()
end
end
function cl()
term.clear()
term.setCursorPos(1,1)
end
function writeFull ()
local startup = fs.open("startup", "w")
startup.writeLine("term.clear()")
startup.writeLine("term.setCursorPos(1,1)")
startup.writeLine("_G.printError('Inventory full, terminating program...')")
startup.close()
end
function inList(str, list)
for _,row in ipairs(list) do
if row[1] == str then
return true
end
end
return false
end
function readInv()
cl()
print("Reading inventory...")
sleep(0.5)
table.insert(inv, {"Slot", "Name", "Count"})
turtle.select(1)
for i = 1,16 do
turtle.select(i)
local detail = turtle.getItemDetail(i, true)
if detail then
table.insert (inv, {tostring(i), detail.name, tostring(detail.count)})
end
end
turtle.select(1)
trasn(inv)
check = inList("16", inv)
if check == true then
cl()
_G.printError("Inventory full, terminating program...")
if logFile then
logFile.close()
logFile = nil
end
writeFull()
shell.run("full")
os.shutdown()
end
end
-- Rednet --
modem = peripheral.wrap(Mside)
open = rednet.isOpen()
if open == false then
cl()
print("Opening modem...")
rednet.open(Mside)
sleep(0.5)
end
function trans(msg)
cl()
print("Transmitting to base...")
modem.transmit(chn, Rchn, msg)
end
-- Start of program --
cl()
print("Initialising strip mining program...")
sleep(1)
-- Main WHILE loop --
repeat
mineLayer()
until check == true
-- Main WHILE loop --
-- TESTING AREA --
if logFile then
logFile.close() -- closing log file, if still open
end