Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modules=peripheral.wrap("left")
- scannerRange=8
- scannerWidth=scannerRange*2+1
- ores={}
- testBlock={
- ["name"]="enderstorage:ender_storage"
- }
- desiredOres={
- "minecraft:diamond_ore",
- "minecraft:emerald_ore",
- "minecraft:iron_ore",
- "minecraft:gold_ore",
- "minecraft:coal_ore",
- "minecraft:lapis_ore",
- "minecraft:redstone_ore",
- "minecraft:quartz_ore",
- "minecraft:quartz_block",
- "thermalfoundation:ore",
- "railcraft:ore_metal",
- "aroma1997sdimension:miningore",
- "astralsorcery:blockcustomore",
- "thaumcraft:ore_quartz",
- "appliedenergistics2:quartz_ore",
- "appliedenergistics2:charged_quartz_ore",
- "deepresonance:resonating_ore",
- "bigreactors:oreanglesite",
- "bigreactors:orebenitoite",
- "bigreactors:oreyellorite",
- "forestry:resources",
- "ic2:resource",
- "projectred-exploration:ore",
- "rftools:dimensional_shard_ore",
- "railcraft:ore_magic",
- "thaumcraft:ore_cinnabar",
- "woot:stygianironore",
- "evilcraft:dark_ore",
- "thaumcraft:crystal_aer",
- "thaumcraft:crystal_ignis",
- "thaumcraft:crystal_aqua",
- "thaumcraft:crystal_terra",
- "thaumcraft:crystal_ordo",
- "thaumcraft:crystal_perditio",
- "thaumcraft:crystal_vitium",
- "bewitchment:opal_ore",
- "bewitchment:salt_ore",
- "galacticraftcore:basic_block_core",
- ""
- }
- blacklist={
- "minecraft:cobblestone",
- "minecraft:dirt",
- "minecraft:gravel",
- "minecraft:stone"
- }
- x=0
- y=0
- z=0
- direction=90 --in degrees
- baseDirection=direction
- local function move()
- while not turtle.forward() do
- turtle.dig()
- sleep(.5)
- end
- end
- local function moveUp()
- while not turtle.up() do
- turtle.digUp()
- sleep(.5)
- end
- end
- local function moveDown()
- while not turtle.down() do
- turtle.digDown()
- sleep(.5)
- end
- end
- local function dig()
- while turtle.detect() do
- turtle.dig()
- sleep(.5)
- end
- end
- local function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(.5)
- end
- end
- local function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- sleep(.5)
- end
- end
- local function findNearestOre()--done
- if #ores>0 then
- minDist=15
- minI=1
- for i=1,#ores do
- dist=math.sqrt((ores[i].x-x)^2+(ores[i].y-y)^2+(ores[i].z-z)^2)
- if dist<minDist then
- minDist=dist
- minI=i
- end
- end
- return minI
- end
- end
- local function scan()--done
- local scanned_blocks = modules.scan()
- ores={}
- for x=-scannerRange, scannerRange do
- for z=-scannerRange, scannerRange do
- for y=-scannerRange, scannerRange do
- local scanned=scanned_blocks[scannerWidth ^ 2 * (x + scannerRange) + scannerWidth * (y + scannerRange) + (z + scannerRange) + 1]
- if scanned then
- for i=1,#desiredOres do
- if scanned.name == desiredOres[i] then
- ores[#ores+1]={["x"]=x,["y"]=y,["z"]=z}
- elseif scanned.name == testBlock.name then
- testBlock.x=x
- testBlock.y=y
- testBlock.z=z
- break
- end
- end
- end
- end
- end
- end
- end
- local function checkDirection()--done
- turtle.select(16)
- while turtle.detectUp() do
- turtle.digUp()
- sleep(1)
- end
- turtle.placeUp()
- scan()
- oldX=testBlock.x
- oldZ=testBlock.z
- turtle.select(1)
- move()
- scan()
- distX=testBlock.x-oldX
- distZ=testBlock.z-oldZ
- if distX==1 then
- direction=270
- elseif distX==-1 then
- direction=90
- elseif distZ==1 then
- direction=180
- elseif distZ==-1 then
- direction=0
- end
- baseDirection=direction
- turtle.back()
- turtle.select(16)
- turtle.digUp()
- end
- local function turn(dir)--done
- local turns = ((dir-direction)%360)/90
- if turns>0 then
- for i=1,turns do
- turtle.turnLeft()
- end
- end
- direction=dir
- end
- local function store()--done
- turtle.select(16)
- digDown()
- turtle.placeDown()
- for i=1, 15 do
- turtle.select(i)
- if #blacklist>0 then
- for j=1,#blacklist do
- if turtle.getItemDetail() then
- if turtle.getItemDetail().name == blacklist[j] then
- turtle.dropUp()
- end
- end
- end
- end
- turtle.dropDown()
- end
- turtle.select(16)
- digDown()
- end
- local function goToNearestOre()--done
- while #ores>0 do
- if #ores%8 == 7 then
- store()
- end
- local i=findNearestOre()
- if ores[i].y > y then
- for i=1,ores[i].y-y do
- moveUp()
- end
- elseif ores[i].y < y then
- for i=1,y-ores[i].y do
- while not turtle.down() do
- digDown()
- sleep(.5)
- end
- end
- end
- if ores[i].x > x then
- for i=1,ores[i].x-x do
- move()
- end
- elseif ores[i].x < x then
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,x-ores[i].x do
- move()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- if ores[i].z > z then
- turtle.turnRight()
- for i=1,ores[i].z-z do
- move()
- end
- turtle.turnLeft()
- elseif ores[i].z < z then
- turtle.turnLeft()
- for i=1,z-ores[i].z do
- move()
- end
- turtle.turnRight()
- end
- x=ores[i].x
- y=ores[i].y
- z=ores[i].z
- table.remove(ores,i)
- end
- if 0 > y then
- for i=1,0-y do
- moveUp()
- end
- elseif 0 < y then
- for i=1,y-0 do
- while not turtle.down() do
- digDown()
- sleep(.5)
- end
- end
- end
- if 0 > x then
- for i=1,0-x do
- move()
- end
- elseif 0 < x then
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,x-0 do
- move()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- if 0 > z then
- turtle.turnRight()
- for i=1,0-z do
- move()
- end
- turtle.turnLeft()
- elseif 0 < z then
- turtle.turnLeft()
- for i=1,z-0 do
- move()
- end
- turtle.turnRight()
- end
- x=0
- y=0
- z=0
- end
- local function tunnel(n)--done
- for j=1,n do
- for i=1,scannerWidth do
- move()
- digUp()
- digDown()
- end
- for i=1,scannerRange do
- turtle.back()
- end
- turn(90)
- scan()
- goToNearestOre()
- turn(baseDirection)
- direction=baseDirection
- store()
- for i=1,scannerRange do
- turtle.forward()
- end
- end
- end
- checkDirection()
- tunnel(4)
Add Comment
Please, Sign In to add comment