Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --list of all ores or blocks we want to mine--
- local ores = {
- "minecraft:iron_ore",
- "minecraft:diamond_ore",
- "minecraft:coal_ore",
- "minecraft:gold_ore",
- "minecraft:emerald_ore",
- "minecraft:redstone_ore",
- "minecraft:lapis_lazuli_ore",
- "create:zinc_ore",
- "mekanism:tin_ore",
- "mekanism:copper_ore",
- "mekansim:lead_ore",
- "mekanism:osmium_ore"
- }
- --stuff to throw away--
- local garbage = {
- "minecraft:dirt",
- "minecraft:cobblestone",
- "minecraft:gravel",
- "minecraft:sand",
- "minecraft:granite",
- "minecraft:diorite",
- "minecraft:cobbled_deepslate"
- }
- --if below this number it will use coal to refuel--
- local refill = 2000
- local tArgs = {...}
- local tunnelLength = 0
- local numTunnels = 0
- local pos = {0,0,0,1}
- local tunnelFormula = 0
- --set tunnels length--
- if tArgs[2] then
- tunnelLength = tonumber(tArgs[2])
- numTunnels = tonumber(tArgs[1])
- else
- error("[USAGE]: <number of tunnels> <length of tunnels>")
- end
- local fuelLevel = turtle.getFuelLevel()
- local fuelFormula = math.ceil((tunnelLength*4)+(tunnelLength*0.45)*numTunnels)+150
- --test fuel level. If good ask if ready--
- if fuelLevel < fuelFormula then
- error("[Fuel Required]: " .. fuelFormula - fuelLevel)
- end
- --this function checks the block and gives info--
- function inspect(side)
- local worked, data = false,{}
- if not side then
- worked, data = turtle.inspect()
- elseif side == 1 then
- worked, data = turtle.inspectUp()
- elseif side == 2 then
- worked, data = turtle.inspectDown()
- end
- if worked then
- for i=1,#ores do
- if data.name == ores[i] then
- return data.name
- end
- end
- if oreName(data.name) then
- return data.name
- end
- return false
- end
- end
- --all movement functions. Makes it look better--
- function right()
- turtle.turnRight()
- pos[4] = pos[4] + 1
- if pos[4] >= 5 then
- pos[4] = 1
- end
- end
- function left()
- turtle.turnLeft()
- pos[4] = pos[4] - 1
- if pos[4] <= 0 then
- pos[4] = 4
- end
- end
- function forward()
- repeat turtle.dig() until turtle.forward()
- if pos[4] == 1 then
- pos[1] = pos[1] + 1
- elseif pos[4] == 2 then
- pos[3] = pos[3] + 1
- elseif pos[4] == 3 then
- pos[1] = pos[1] - 1
- else
- pos[3] = pos[3] - 1
- end
- return true
- end
- function back()
- if not turtle.back() then
- right()
- right()
- forward()
- left()
- left()
- else
- if pos[4] == 1 then
- pos[1] = pos[1] - 1
- elseif pos[4] == 2 then
- pos[3] = pos[3] - 1
- elseif pos[4] == 3 then
- pos[1] = pos[1] + 1
- else
- pos[3] = pos[3] + 1
- end
- end
- return true
- end
- function up()
- repeat turtle.digUp() until turtle.up()
- pos[2] = pos[2] + 1
- return true
- end
- function down()
- repeat turtle.digDown() until turtle.down()
- pos[2] = pos[2] - 1
- return true
- end
- function setDir(d)
- while pos[4] > d do
- left()
- end
- while pos[4] < d do
- right()
- end
- end
- function goto(tbl)
- while pos[2] > tbl[2] do
- down()
- end
- while pos[2] < tbl[2] do
- up()
- end
- if pos[3] > tbl[3] then
- setDir(4)
- while pos[3] > tbl[3] do
- forward()
- end
- end
- if pos[3] < tbl[3] then
- setDir(2)
- while pos[3] < tbl[3] do
- forward()
- end
- end
- if pos[1] > tbl[1] then
- setDir(3)
- while pos[1] > tbl[1] do
- forward()
- end
- end
- if pos[1] < tbl[1] then
- setDir(1)
- while pos[1] < tbl[1] do
- forward()
- end
- end
- setDir(tbl[4])
- end
- --this is what does all the looking for ores around the turtle. Recursive function--
- function scan( nTry )
- if not nTry then
- nTry = 1
- elseif nTry > 180 then
- return
- end
- --check to the right--
- right()
- if inspect() then
- forward()
- scan(nTry+1)
- back()
- end
- left()
- --check to the left--
- left()
- if inspect() then
- forward()
- scan(nTry+1)
- back()
- end
- right()
- --check in front--
- if inspect() then
- forward()
- scan(nTry+1)
- back()
- end
- --check up--
- if inspect(1) then
- up()
- scan(nTry+1)
- down()
- end
- --check down--
- if inspect(2) then
- down()
- scan(nTry+1)
- up()
- end
- end
- function oreName(name)
- if string.find(name, "ore") then
- return true
- end
- return false
- end
- function dumpItems()
- purgeInv()
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- --cleans out and reorganizes the inventory--
- function purgeInv()
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- local data = turtle.getItemDetail(i)
- if turtle.getItemCount(i) < 64 then
- for j=i+1,16 do
- local d = turtle.getItemDetail(j)
- if d and d.name == data.name then
- turtle.select(j)
- turtle.transferTo(i)
- end
- end
- end
- for b=1,#garbage do
- if data.name == garbage[b] then
- turtle.select(i)
- turtle.drop()
- break
- elseif data.name == "minecraft:coal" then
- if turtle.getFuelLevel() < refill then
- turtle.select(i)
- turtle.refuel()
- break
- end
- end
- end
- end
- end
- turtle.select(1)
- end
- function moveForward()
- forward()
- scan()
- up()
- scan()
- down()
- end
- --this is the main function where all the other functions are called in order and makes it work--
- function main()
- print("[MINING] ".. numTunnels .. " x ".. tunnelLength)
- print("START [Y/N]")
- while true do
- local _,c = os.pullEvent("char")
- if c:lower() == "y" then
- if numTunnels > 2 then
- tunnelFormula = math.ceil((numTunnels-2)/2)
- else
- tunnelFormula = 0
- end
- --start mining--
- for b=1, tunnelFormula*4 do
- moveForward()
- if b % 3 == 0 then
- purgeInv()
- end
- end
- goto({0,0,0,3})
- dumpItems()
- local moves = 0
- local tmpDir = nil
- for i=1,numTunnels do
- if i > 2 then
- moves = math.ceil((i-2)/2)*4
- else
- moves = 0
- end
- if i%2 == 0 then
- tmpDir = 2
- else
- tmpDir = 4
- end
- goto({moves,0,0,tmpDir})
- for t=1,tunnelLength do
- moveForward()
- if t % 5 == 0 then
- purgeInv()
- end
- end
- goto({0,0,0,3})
- dumpItems()
- end
- return
- else
- error("You didn't press y")
- end
- end
- end
- --call the main function to start it all--
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement