Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --50bJxa0K
- local END_CHEST = 2
- local FUEL = 1
- local args = { ... }
- local SIZE_X = 16
- local SIZE_Z = 16
- if #args == 2 then
- SIZE_X = args[1]
- SIZE_Z = args[2]
- end
- local BLACKLIST = {
- "minecraft:cobblestone",
- "minecraft:cobbled_deepslate",
- "minecraft:gravel",
- "minecraft:tuff",
- "minecraft:calcite",
- "minecraft:dirt",
- "minecraft:granite",
- "minecraft:dripstone_block",
- "minecraft:moss_block",
- "minecraft:chest",
- "minecraft:mossy_cobblestone",
- "create:veridium",
- "create:ochrum",
- "create:limestone",
- "create:crimsite",
- "create:asurine",
- "minecraft:netherrack",
- "minecraft:end_stone",
- }
- local WHITELIST = {
- "minecraft:iron_ore",
- "minecraft:deepslate_iron_ore",
- "minecraft:copper_ore",
- "minecraft:deepslate_copper_ore",
- "minecraft:gold_ore",
- "minecraft:deepslate_gold_ore",
- "minecraft:redstone_ore",
- "minecraft:deepslate_redstone_ore",
- "minecraft:emerald_ore",
- "minecraft:deepslate_emerald_ore",
- "minecraft:lapis_ore",
- "minecraft:deepslate_lapis_ore",
- "minecraft:diamond_ore",
- "minecraft:deepslate_diamond_ore",
- "minecraft:nether_gold_ore",
- "minecraft:nether_quartz_ore",
- "minecraft:ancient_debris",
- "minecraft:obsidian",
- "create:zinc_ore",
- "create:deepslate_zinc_ore",
- "tconstruct:cobalt_ore",
- "mekanism:tin_ore",
- "mekanism:deepslate_tin_ore",
- "mekanism:lead_ore",
- "mekanism:deepslate_lead_ore",
- "mekanism:osmium_ore",
- "mekanism:deepslate_osmium_ore",
- "mekanism:uranium_ore",
- "mekanism:deepslate_uranium_ore",
- -- "mekanism:fluorite_ore",
- -- "mekanism:deepslate_fluorite_ore"
- "alltheores:aluminum_ore",
- "alltheores:aluminum_end_ore",
- "alltheores:aluminum_nether_ore",
- "alltheores:aluminum_other_ore",
- "alltheores:aluminum_slate_ore",
- "alltheores:copper_other_ore",
- "alltheores:diamond_other_ore",
- "alltheores:emerald_other_ore",
- "alltheores:gold_other_ore",
- "alltheores:iridium_ore",
- "alltheores:iridium_end_ore",
- "alltheores:iridium_nether_ore",
- "alltheores:iridium_other_ore",
- "alltheores:iridium_slate_ore",
- "alltheores:iron_other_ore",
- "alltheores:lapis_other_ore",
- "alltheores:lead_end_ore",
- "alltheores:lead_ore",
- "alltheores:lead_nether_ore",
- "alltheores:lead_other_ore",
- "alltheores:lead_slate_ore",
- "alltheores:nickel_end_ore",
- "alltheores:nickel_ore",
- "alltheores:nickel_nether_ore",
- "alltheores:nickel_other_ore",
- "alltheores:nickel_slate_ore",
- "alltheores:osmium_end_ore",
- "alltheores:osmium_ore",
- "alltheores:osmium_nether_ore",
- "alltheores:osmium_other_ore",
- "alltheores:osmium_slate_ore",
- "alltheores:platinum_end_ore",
- "alltheores:platinum_ore",
- "alltheores:platinum_nether_ore",
- "alltheores:platinum_other_ore",
- "alltheores:platinum_slate_ore",
- "alltheores:quartz_other_ore",
- "alltheores:redstone_other_ore",
- "alltheores:silver_end_ore",
- "alltheores:silver_nether_ore",
- "alltheores:silver_ore",
- "alltheores:silver_other_ore",
- "alltheores:silver_slate_ore",
- "alltheores:tin_end_ore",
- "alltheores:tin_nether_ore",
- "alltheores:tin_ore",
- "alltheores:tin_other_ore",
- "alltheores:tin_slate_ore",
- "alltheores:uranium_end_ore",
- "alltheores:uranium_nether_ore",
- "alltheores:uranium_ore",
- "alltheores:uranium_other_ore",
- "alltheores:uranium_slate_ore",
- "alltheores:zinc_end_ore",
- "alltheores:zinc_nether_ore",
- "alltheores:zinc_ore",
- "alltheores:zinc_other_ore",
- "alltheores:zinc_slate_ore",
- "minecraft:coal_ore",
- "minecraft:deepslate_coal_ore",
- "alltheores:coal_end_ore",
- "alltheores:coal_nether_ore",
- "alltheores:coal_other_ore",
- }
- if SIZE_X % 8 ~= 0 or SIZE_Z % 8 ~= 0 then
- error("Quarrying area must be a multiple of 8")
- end
- local map = {}
- map[0] = {}
- for i = 0, SIZE_X - 1 do
- map[0][i] = {}
- for j = 0, SIZE_Z - 1 do
- map[0][i][j] = 0
- end
- end
- map[0][0][0] = 1
- local imap = {}
- imap[0] = {}
- for i = -1, SIZE_X do
- imap[0][i] = {}
- for j = -1, SIZE_Z do
- imap[0][i][j] = 0
- end
- end
- local pos = vector.new(0, 0, 0)
- local dir = vector.new(0, 0, 1)
- local channel = math.random(0, 65535)
- local modem = peripheral.find("modem")
- local status = 0
- if modem == nil or not modem.isWireless() then
- error("Please connect a wireless modem to the turtle")
- end
- print("Turtle display on " .. channel)
- modem.open(channel)
- table.includes = function(tbl, item)
- for i = 1, #tbl do
- if tbl[i] == item then
- return true
- end
- end
- return false
- end
- function mapSet(pos, val)
- if map[pos.y] == nil then
- map[pos.y] = {}
- for i = 0, SIZE_X - 1 do
- map[pos.y][i] = {}
- for j = 0, SIZE_Z - 1 do
- map[pos.y][i][j] = 0
- end
- end
- end
- map[pos.y][pos.x][pos.z] = val
- imapSet(pos, 1)
- end
- function mapGet(pos)
- if map[pos.y] == nil then
- map[pos.y] = {}
- for i = 0, SIZE_X - 1 do
- map[pos.y][i] = {}
- for j = 0, SIZE_Z - 1 do
- map[pos.y][i][j] = 0
- end
- end
- return 0
- end
- return map[pos.y][pos.x][pos.z]
- end
- function imapSet(pos, val)
- if imap[pos.y] == nil then
- imap[pos.y] = {}
- for i = -1, SIZE_X do
- imap[pos.y][i] = {}
- for j = -1, SIZE_Z do
- imap[pos.y][i][j] = 0
- end
- end
- end
- imap[pos.y][pos.x][pos.z] = val
- end
- function imapGet(pos)
- if imap[pos.y] == nil then
- imap[pos.y] = {}
- for i = -1, SIZE_X do
- imap[pos.y][i] = {}
- for j = -1, SIZE_Z do
- imap[pos.y][i][j] = 0
- end
- end
- return 0
- end
- return imap[pos.y][pos.x][pos.z]
- end
- local storage = ""
- function checkAndDeposit()
- turtle.select(14)
- if turtle.getItemDetail() == nil then
- turtle.select(1)
- return
- end
- modem.transmit(channel, 0, { map, pos, dir, 4 })
- while turtle.digUp() do
- end
- turtle.select(2)
- turtle.placeUp()
- for i = 3, 16 do
- turtle.select(i)
- local item = turtle.getItemDetail()
- if item ~= nil then
- if table.includes(BLACKLIST, item.name) then
- turtle.drop()
- else
- turtle.dropUp()
- end
- end
- end
- turtle.select(2)
- turtle.digUp()
- turtle.select(1)
- end
- function canMoveLegally()
- local aim = pos + dir
- return not (aim.x < 0 or aim.z < 0 or aim.x > SIZE_X - 1 or aim.z > SIZE_Z - 1)
- end
- function findOres()
- if mapGet(pos) == 1 then
- return
- end
- mapSet(pos, 1)
- print("checking ores")
- mineOres()
- print("finished checking ores")
- status = 0
- modem.transmit(channel, 0, { map, pos, dir, status })
- end
- function mineOres()
- local exists, data
- local function inspectFront()
- exists, data = turtle.inspect()
- imapSet(pos + dir, 1)
- if exists and table.includes(WHITELIST, data.name) then
- if canMoveLegally() then
- repeat
- turtle.dig()
- status = 2
- modem.transmit(channel, 0, { map, pos, dir, status })
- until turtle.forward()
- pos = pos + dir
- status = 1
- mapSet(pos, 1)
- mineOres()
- turtle.back()
- pos = pos - dir
- else
- turtle.dig()
- status = 3
- modem.transmit(channel, 0, { map, pos, dir, status })
- end
- end
- end
- modem.transmit(channel, 0, { map, pos, dir, status })
- exists, data = turtle.inspectUp()
- imapSet(pos + vector.new(0, 1, 0), 1)
- if exists and table.includes(WHITELIST, data.name) then
- repeat
- turtle.digUp()
- status = 2
- modem.transmit(channel, 0, { map, pos, dir, status })
- until turtle.up()
- pos = pos + vector.new(0, 1, 0)
- status = 1
- mapSet(pos, 1)
- mineOres()
- turtle.down()
- pos = pos + vector.new(0, -1, 0)
- end
- modem.transmit(channel, 0, { map, pos, dir, status })
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- exists, data = turtle.inspectDown()
- imapSet(pos + vector.new(0, -1, 0), 1)
- if exists and table.includes(WHITELIST, data.name) then
- repeat
- turtle.digDown()
- status = 2
- modem.transmit(channel, 0, { map, pos, dir, status })
- until turtle.down()
- pos = pos + vector.new(0, -1, 0)
- status = 1
- mapSet(pos, 1)
- mineOres()
- turtle.up()
- pos = pos + vector.new(0, 1, 0)
- end
- modem.transmit(channel, 0, { map, pos, dir, status })
- local code = 0
- code = code + (1 - imapGet(pos + vector.new(dir.z, 0, -dir.x)))
- code = code + 2 * (1 - imapGet(pos + vector.new(-dir.x, 0, -dir.z)))
- code = code + 4 * (1 - imapGet(pos + vector.new(-dir.z, 0, dir.x)))
- if code == 0 then
- return
- end
- if code == 1 then
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(true)
- elseif code == 2 then
- turn(false)
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(true)
- turn(true)
- elseif code == 3 then
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(true)
- turn(true)
- elseif code == 4 then
- turn(true)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(false)
- elseif code == 5 then
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(true)
- turn(true)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(false)
- elseif code == 6 then
- turn(true)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(true)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(false)
- turn(false)
- elseif code == 7 then
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(false)
- inspectFront()
- modem.transmit(channel, 0, { map, pos, dir, status })
- turn(false)
- end
- end
- function refuel()
- turtle.digDown()
- turtle.select(1)
- turtle.placeDown()
- turtle.suckDown(math.min((turtle.getFuelLimit() - turtle.getFuelLevel()) / 800, 64))
- turtle.refuel(64)
- turtle.digDown()
- end
- function scheduleMovement(blocks)
- local dist = 0
- repeat
- repeat
- turtle.dig()
- until turtle.forward()
- dist = dist + 1
- pos = pos + dir
- status = 0
- modem.transmit(channel, 0, { map, pos, dir, status })
- findOres()
- until dist == blocks
- end
- function rawMove(blocks)
- for i = 1, blocks do
- turtle.forward()
- pos = pos + dir
- status = 0
- modem.transmit(channel, 0, { map, pos, dir, status })
- end
- end
- function turn(orient, updateStatus)
- updateStatus = updateStatus or false
- if orient then
- turtle.turnRight()
- dir = vector.new(-dir.z, 0, dir.x)
- if updateStatus then
- status = 0
- end
- modem.transmit(channel, 0, { map, pos, dir, status })
- else
- turtle.turnLeft()
- dir = vector.new(dir.z, 0, -dir.x)
- if updateStatus then
- status = 0
- end
- modem.transmit(channel, 0, { map, pos, dir, status })
- end
- end
- function stripmine(sx, sz, orient)
- if turtle.getFuelLevel() < (sx + sz) * 10 then
- refuel()
- end
- for x = 1, sx / 8 do
- scheduleMovement(sz - 1)
- checkAndDeposit()
- turn(orient)
- scheduleMovement(4)
- turn(orient)
- scheduleMovement(sz - 1)
- checkAndDeposit()
- turn(orient)
- turn(orient)
- rawMove(3)
- turn(orient)
- if x == sx / 8 then
- scheduleMovement(3)
- else
- scheduleMovement(4)
- turn(orient)
- scheduleMovement(3)
- end
- turn(orient)
- turn(orient)
- end
- if turtle.getFuelLevel() < (sx + sz) * 10 then
- refuel()
- end
- for z = 1, sz / 8 do
- scheduleMovement(sx - 1)
- checkAndDeposit()
- turn(orient)
- scheduleMovement(4)
- turn(orient)
- scheduleMovement(sx - 1)
- checkAndDeposit()
- turn(orient)
- turn(orient)
- if z == sz / 8 then
- break
- end
- rawMove(3)
- turn(orient)
- scheduleMovement(4)
- turn(orient)
- scheduleMovement(3)
- turn(orient)
- turn(orient)
- end
- end
- local finished = false
- function mineLayer(sx, sz)
- stripmine(sx, sz, false)
- turtle.digDown()
- if not turtle.down() then
- finished = true
- end
- pos = pos + vector.new(0, -1, 0)
- if not finished then
- findOres()
- stripmine(sx, sz, true)
- turtle.digDown()
- if not turtle.down() then
- finished = true
- end
- pos = pos + vector.new(0, -1, 0)
- findOres()
- end
- end
- while not finished do
- mineLayer(SIZE_X, SIZE_Z)
- end
- while not turtle.inspectUp() do
- turtle.digUp()
- turtle.up()
- modem.transmit(channel, 0, { map, pos, dir, 3 })
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement