Advertisement
SirSheepe

Untitled

May 7th, 2023 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.12 KB | None | 0 0
  1. --50bJxa0K
  2.  
  3. local END_CHEST = 2
  4. local FUEL = 1
  5.  
  6. local args = { ... }
  7.  
  8. local SIZE_X = 16
  9. local SIZE_Z = 16
  10.  
  11. if #args == 2 then
  12.     SIZE_X = args[1]
  13.     SIZE_Z = args[2]
  14. end
  15.  
  16. local BLACKLIST = {
  17.     "minecraft:cobblestone",
  18.     "minecraft:cobbled_deepslate",
  19.     "minecraft:gravel",
  20.     "minecraft:tuff",
  21.     "minecraft:calcite",
  22.     "minecraft:dirt",
  23.     "minecraft:granite",
  24.     "minecraft:dripstone_block",
  25.     "minecraft:moss_block",
  26.     "minecraft:chest",
  27.     "minecraft:mossy_cobblestone",
  28.     "create:veridium",
  29.     "create:ochrum",
  30.     "create:limestone",
  31.     "create:crimsite",
  32.     "create:asurine",
  33.     "minecraft:netherrack",
  34.     "minecraft:end_stone",
  35. }
  36.  
  37. local WHITELIST = {
  38.     "minecraft:iron_ore",
  39.     "minecraft:deepslate_iron_ore",
  40.     "minecraft:copper_ore",
  41.     "minecraft:deepslate_copper_ore",
  42.     "minecraft:gold_ore",
  43.     "minecraft:deepslate_gold_ore",
  44.     "minecraft:redstone_ore",
  45.     "minecraft:deepslate_redstone_ore",
  46.     "minecraft:emerald_ore",
  47.     "minecraft:deepslate_emerald_ore",
  48.     "minecraft:lapis_ore",
  49.     "minecraft:deepslate_lapis_ore",
  50.     "minecraft:diamond_ore",
  51.     "minecraft:deepslate_diamond_ore",
  52.     "minecraft:nether_gold_ore",
  53.     "minecraft:nether_quartz_ore",
  54.     "minecraft:ancient_debris",
  55.     "minecraft:obsidian",
  56.     "create:zinc_ore",
  57.     "create:deepslate_zinc_ore",
  58.     "tconstruct:cobalt_ore",
  59.     "mekanism:tin_ore",
  60.     "mekanism:deepslate_tin_ore",
  61.     "mekanism:lead_ore",
  62.     "mekanism:deepslate_lead_ore",
  63.     "mekanism:osmium_ore",
  64.     "mekanism:deepslate_osmium_ore",
  65.     "mekanism:uranium_ore",
  66.     "mekanism:deepslate_uranium_ore",
  67.     -- "mekanism:fluorite_ore",
  68.     -- "mekanism:deepslate_fluorite_ore"
  69.     "alltheores:aluminum_ore",
  70.     "alltheores:aluminum_end_ore",
  71.     "alltheores:aluminum_nether_ore",
  72.     "alltheores:aluminum_other_ore",
  73.     "alltheores:aluminum_slate_ore",
  74.     "alltheores:copper_other_ore",
  75.     "alltheores:diamond_other_ore",
  76.     "alltheores:emerald_other_ore",
  77.     "alltheores:gold_other_ore",
  78.     "alltheores:iridium_ore",
  79.     "alltheores:iridium_end_ore",
  80.     "alltheores:iridium_nether_ore",
  81.     "alltheores:iridium_other_ore",
  82.     "alltheores:iridium_slate_ore",
  83.     "alltheores:iron_other_ore",
  84.     "alltheores:lapis_other_ore",
  85.     "alltheores:lead_end_ore",
  86.     "alltheores:lead_ore",
  87.     "alltheores:lead_nether_ore",
  88.     "alltheores:lead_other_ore",
  89.     "alltheores:lead_slate_ore",
  90.     "alltheores:nickel_end_ore",
  91.     "alltheores:nickel_ore",
  92.     "alltheores:nickel_nether_ore",
  93.     "alltheores:nickel_other_ore",
  94.     "alltheores:nickel_slate_ore",
  95.     "alltheores:osmium_end_ore",
  96.     "alltheores:osmium_ore",
  97.     "alltheores:osmium_nether_ore",
  98.     "alltheores:osmium_other_ore",
  99.     "alltheores:osmium_slate_ore",
  100.     "alltheores:platinum_end_ore",
  101.     "alltheores:platinum_ore",
  102.     "alltheores:platinum_nether_ore",
  103.     "alltheores:platinum_other_ore",
  104.     "alltheores:platinum_slate_ore",
  105.     "alltheores:quartz_other_ore",
  106.     "alltheores:redstone_other_ore",
  107.     "alltheores:silver_end_ore",
  108.     "alltheores:silver_nether_ore",
  109.     "alltheores:silver_ore",
  110.     "alltheores:silver_other_ore",
  111.     "alltheores:silver_slate_ore",
  112.     "alltheores:tin_end_ore",
  113.     "alltheores:tin_nether_ore",
  114.     "alltheores:tin_ore",
  115.     "alltheores:tin_other_ore",
  116.     "alltheores:tin_slate_ore",
  117.     "alltheores:uranium_end_ore",
  118.     "alltheores:uranium_nether_ore",
  119.     "alltheores:uranium_ore",
  120.     "alltheores:uranium_other_ore",
  121.     "alltheores:uranium_slate_ore",
  122.     "alltheores:zinc_end_ore",
  123.     "alltheores:zinc_nether_ore",
  124.     "alltheores:zinc_ore",
  125.     "alltheores:zinc_other_ore",
  126.     "alltheores:zinc_slate_ore",
  127.     "minecraft:coal_ore",
  128.     "minecraft:deepslate_coal_ore",
  129.     "alltheores:coal_end_ore",
  130.     "alltheores:coal_nether_ore",
  131.     "alltheores:coal_other_ore",
  132. }
  133.  
  134. if SIZE_X % 8 ~= 0 or SIZE_Z % 8 ~= 0 then
  135.     error("Quarrying area must be a multiple of 8")
  136. end
  137.  
  138. local map = {}
  139. map[0] = {}
  140.  
  141. for i = 0, SIZE_X - 1 do
  142.     map[0][i] = {}
  143.     for j = 0, SIZE_Z - 1 do
  144.         map[0][i][j] = 0
  145.     end
  146. end
  147.  
  148. map[0][0][0] = 1
  149.  
  150. local imap = {}
  151. imap[0] = {}
  152.  
  153. for i = -1, SIZE_X do
  154.     imap[0][i] = {}
  155.     for j = -1, SIZE_Z do
  156.         imap[0][i][j] = 0
  157.     end
  158. end
  159.  
  160. local pos = vector.new(0, 0, 0)
  161. local dir = vector.new(0, 0, 1)
  162.  
  163. local channel = math.random(0, 65535)
  164. local modem = peripheral.find("modem")
  165. local status = 0
  166.  
  167. if modem == nil or not modem.isWireless() then
  168.     error("Please connect a wireless modem to the turtle")
  169. end
  170.  
  171. print("Turtle display on " .. channel)
  172. modem.open(channel)
  173.  
  174. table.includes = function(tbl, item)
  175.     for i = 1, #tbl do
  176.         if tbl[i] == item then
  177.             return true
  178.         end
  179.     end
  180.     return false
  181. end
  182.  
  183. function mapSet(pos, val)
  184.     if map[pos.y] == nil then
  185.         map[pos.y] = {}
  186.         for i = 0, SIZE_X - 1 do
  187.             map[pos.y][i] = {}
  188.             for j = 0, SIZE_Z - 1 do
  189.                 map[pos.y][i][j] = 0
  190.             end
  191.         end
  192.     end
  193.  
  194.     map[pos.y][pos.x][pos.z] = val
  195.  
  196.     imapSet(pos, 1)
  197. end
  198.  
  199. function mapGet(pos)
  200.     if map[pos.y] == nil then
  201.         map[pos.y] = {}
  202.         for i = 0, SIZE_X - 1 do
  203.             map[pos.y][i] = {}
  204.             for j = 0, SIZE_Z - 1 do
  205.                 map[pos.y][i][j] = 0
  206.             end
  207.         end
  208.  
  209.         return 0
  210.     end
  211.  
  212.     return map[pos.y][pos.x][pos.z]
  213. end
  214.  
  215. function imapSet(pos, val)
  216.     if imap[pos.y] == nil then
  217.         imap[pos.y] = {}
  218.         for i = -1, SIZE_X do
  219.             imap[pos.y][i] = {}
  220.             for j = -1, SIZE_Z do
  221.                 imap[pos.y][i][j] = 0
  222.             end
  223.         end
  224.     end
  225.  
  226.     imap[pos.y][pos.x][pos.z] = val
  227. end
  228.  
  229. function imapGet(pos)
  230.     if imap[pos.y] == nil then
  231.         imap[pos.y] = {}
  232.         for i = -1, SIZE_X do
  233.             imap[pos.y][i] = {}
  234.             for j = -1, SIZE_Z do
  235.                 imap[pos.y][i][j] = 0
  236.             end
  237.         end
  238.  
  239.         return 0
  240.     end
  241.  
  242.     return imap[pos.y][pos.x][pos.z]
  243. end
  244.  
  245. local storage = ""
  246.  
  247. function checkAndDeposit()
  248.     turtle.select(14)
  249.  
  250.     if turtle.getItemDetail() == nil then
  251.         turtle.select(1)
  252.         return
  253.     end
  254.  
  255.     modem.transmit(channel, 0, { map, pos, dir, 4 })
  256.  
  257.     while turtle.digUp() do
  258.     end
  259.  
  260.     turtle.select(2)
  261.     turtle.placeUp()
  262.  
  263.     for i = 3, 16 do
  264.         turtle.select(i)
  265.  
  266.         local item = turtle.getItemDetail()
  267.  
  268.         if item ~= nil then
  269.             if table.includes(BLACKLIST, item.name) then
  270.                 turtle.drop()
  271.             else
  272.                 turtle.dropUp()
  273.             end
  274.         end
  275.     end
  276.  
  277.     turtle.select(2)
  278.     turtle.digUp()
  279.     turtle.select(1)
  280. end
  281.  
  282. function canMoveLegally()
  283.     local aim = pos + dir
  284.     return not (aim.x < 0 or aim.z < 0 or aim.x > SIZE_X - 1 or aim.z > SIZE_Z - 1)
  285. end
  286.  
  287. function findOres()
  288.     if mapGet(pos) == 1 then
  289.         return
  290.     end
  291.  
  292.     mapSet(pos, 1)
  293.  
  294.     print("checking ores")
  295.     mineOres()
  296.     print("finished checking ores")
  297.  
  298.     status = 0
  299.     modem.transmit(channel, 0, { map, pos, dir, status })
  300. end
  301.  
  302. function mineOres()
  303.     local exists, data
  304.  
  305.     local function inspectFront()
  306.         exists, data = turtle.inspect()
  307.         imapSet(pos + dir, 1)
  308.         if exists and table.includes(WHITELIST, data.name) then
  309.             if canMoveLegally() then
  310.                 repeat
  311.                     turtle.dig()
  312.                     status = 2
  313.                     modem.transmit(channel, 0, { map, pos, dir, status })
  314.                 until turtle.forward()
  315.                 pos = pos + dir
  316.                 status = 1
  317.                 mapSet(pos, 1)
  318.                 mineOres()
  319.                 turtle.back()
  320.                 pos = pos - dir
  321.             else
  322.                 turtle.dig()
  323.                 status = 3
  324.                 modem.transmit(channel, 0, { map, pos, dir, status })
  325.             end
  326.         end
  327.     end
  328.  
  329.     modem.transmit(channel, 0, { map, pos, dir, status })
  330.  
  331.     exists, data = turtle.inspectUp()
  332.     imapSet(pos + vector.new(0, 1, 0), 1)
  333.     if exists and table.includes(WHITELIST, data.name) then
  334.         repeat
  335.             turtle.digUp()
  336.             status = 2
  337.             modem.transmit(channel, 0, { map, pos, dir, status })
  338.         until turtle.up()
  339.         pos = pos + vector.new(0, 1, 0)
  340.         status = 1
  341.         mapSet(pos, 1)
  342.         mineOres()
  343.         turtle.down()
  344.         pos = pos + vector.new(0, -1, 0)
  345.     end
  346.  
  347.     modem.transmit(channel, 0, { map, pos, dir, status })
  348.  
  349.     inspectFront()
  350.  
  351.     modem.transmit(channel, 0, { map, pos, dir, status })
  352.  
  353.     exists, data = turtle.inspectDown()
  354.     imapSet(pos + vector.new(0, -1, 0), 1)
  355.     if exists and table.includes(WHITELIST, data.name) then
  356.         repeat
  357.             turtle.digDown()
  358.             status = 2
  359.             modem.transmit(channel, 0, { map, pos, dir, status })
  360.         until turtle.down()
  361.         pos = pos + vector.new(0, -1, 0)
  362.         status = 1
  363.         mapSet(pos, 1)
  364.         mineOres()
  365.         turtle.up()
  366.         pos = pos + vector.new(0, 1, 0)
  367.     end
  368.  
  369.     modem.transmit(channel, 0, { map, pos, dir, status })
  370.  
  371.     local code = 0
  372.     code = code + (1 - imapGet(pos + vector.new(dir.z, 0, -dir.x)))
  373.     code = code + 2 * (1 - imapGet(pos + vector.new(-dir.x, 0, -dir.z)))
  374.     code = code + 4 * (1 - imapGet(pos + vector.new(-dir.z, 0, dir.x)))
  375.  
  376.     if code == 0 then
  377.         return
  378.     end
  379.  
  380.     if code == 1 then
  381.         turn(false)
  382.         inspectFront()
  383.         modem.transmit(channel, 0, { map, pos, dir, status })
  384.         turn(true)
  385.     elseif code == 2 then
  386.         turn(false)
  387.         turn(false)
  388.         inspectFront()
  389.         modem.transmit(channel, 0, { map, pos, dir, status })
  390.         turn(true)
  391.         turn(true)
  392.     elseif code == 3 then
  393.         turn(false)
  394.         inspectFront()
  395.         modem.transmit(channel, 0, { map, pos, dir, status })
  396.         turn(false)
  397.         inspectFront()
  398.         modem.transmit(channel, 0, { map, pos, dir, status })
  399.         turn(true)
  400.         turn(true)
  401.     elseif code == 4 then
  402.         turn(true)
  403.         inspectFront()
  404.         modem.transmit(channel, 0, { map, pos, dir, status })
  405.         turn(false)
  406.     elseif code == 5 then
  407.         turn(false)
  408.         inspectFront()
  409.         modem.transmit(channel, 0, { map, pos, dir, status })
  410.         turn(true)
  411.         turn(true)
  412.         inspectFront()
  413.         modem.transmit(channel, 0, { map, pos, dir, status })
  414.         turn(false)
  415.     elseif code == 6 then
  416.         turn(true)
  417.         inspectFront()
  418.         modem.transmit(channel, 0, { map, pos, dir, status })
  419.         turn(true)
  420.         inspectFront()
  421.         modem.transmit(channel, 0, { map, pos, dir, status })
  422.         turn(false)
  423.         turn(false)
  424.     elseif code == 7 then
  425.         turn(false)
  426.         inspectFront()
  427.         modem.transmit(channel, 0, { map, pos, dir, status })
  428.         turn(false)
  429.         inspectFront()
  430.         modem.transmit(channel, 0, { map, pos, dir, status })
  431.         turn(false)
  432.         inspectFront()
  433.         modem.transmit(channel, 0, { map, pos, dir, status })
  434.         turn(false)
  435.     end
  436. end
  437.  
  438. function refuel()
  439.     turtle.digDown()
  440.     turtle.select(1)
  441.     turtle.placeDown()
  442.     turtle.suckDown(math.min((turtle.getFuelLimit() - turtle.getFuelLevel()) / 800, 64))
  443.     turtle.refuel(64)
  444.     turtle.digDown()
  445. end
  446.  
  447. function scheduleMovement(blocks)
  448.     local dist = 0
  449.  
  450.     repeat
  451.         repeat
  452.             turtle.dig()
  453.         until turtle.forward()
  454.  
  455.         dist = dist + 1
  456.         pos = pos + dir
  457.  
  458.         status = 0
  459.         modem.transmit(channel, 0, { map, pos, dir, status })
  460.  
  461.         findOres()
  462.     until dist == blocks
  463. end
  464.  
  465. function rawMove(blocks)
  466.     for i = 1, blocks do
  467.         turtle.forward()
  468.         pos = pos + dir
  469.         status = 0
  470.         modem.transmit(channel, 0, { map, pos, dir, status })
  471.     end
  472. end
  473.  
  474. function turn(orient, updateStatus)
  475.     updateStatus = updateStatus or false
  476.     if orient then
  477.         turtle.turnRight()
  478.         dir = vector.new(-dir.z, 0, dir.x)
  479.  
  480.         if updateStatus then
  481.             status = 0
  482.         end
  483.  
  484.         modem.transmit(channel, 0, { map, pos, dir, status })
  485.     else
  486.         turtle.turnLeft()
  487.         dir = vector.new(dir.z, 0, -dir.x)
  488.  
  489.         if updateStatus then
  490.             status = 0
  491.         end
  492.  
  493.         modem.transmit(channel, 0, { map, pos, dir, status })
  494.     end
  495. end
  496.  
  497. function stripmine(sx, sz, orient)
  498.     if turtle.getFuelLevel() < (sx + sz) * 10 then
  499.         refuel()
  500.     end
  501.  
  502.     for x = 1, sx / 8 do
  503.         scheduleMovement(sz - 1)
  504.         checkAndDeposit()
  505.         turn(orient)
  506.         scheduleMovement(4)
  507.         turn(orient)
  508.         scheduleMovement(sz - 1)
  509.         checkAndDeposit()
  510.         turn(orient)
  511.         turn(orient)
  512.         rawMove(3)
  513.         turn(orient)
  514.  
  515.         if x == sx / 8 then
  516.             scheduleMovement(3)
  517.         else
  518.             scheduleMovement(4)
  519.             turn(orient)
  520.             scheduleMovement(3)
  521.         end
  522.  
  523.         turn(orient)
  524.         turn(orient)
  525.     end
  526.  
  527.     if turtle.getFuelLevel() < (sx + sz) * 10 then
  528.         refuel()
  529.     end
  530.  
  531.     for z = 1, sz / 8 do
  532.         scheduleMovement(sx - 1)
  533.         checkAndDeposit()
  534.         turn(orient)
  535.         scheduleMovement(4)
  536.         turn(orient)
  537.         scheduleMovement(sx - 1)
  538.         checkAndDeposit()
  539.         turn(orient)
  540.         turn(orient)
  541.  
  542.         if z == sz / 8 then
  543.             break
  544.         end
  545.  
  546.         rawMove(3)
  547.         turn(orient)
  548.         scheduleMovement(4)
  549.         turn(orient)
  550.         scheduleMovement(3)
  551.  
  552.         turn(orient)
  553.         turn(orient)
  554.     end
  555. end
  556.  
  557. local finished = false
  558.  
  559. function mineLayer(sx, sz)
  560.     stripmine(sx, sz, false)
  561.  
  562.     turtle.digDown()
  563.  
  564.     if not turtle.down() then
  565.         finished = true
  566.     end
  567.  
  568.     pos = pos + vector.new(0, -1, 0)
  569.  
  570.     if not finished then
  571.         findOres()
  572.  
  573.         stripmine(sx, sz, true)
  574.  
  575.         turtle.digDown()
  576.  
  577.         if not turtle.down() then
  578.             finished = true
  579.         end
  580.  
  581.         pos = pos + vector.new(0, -1, 0)
  582.  
  583.         findOres()
  584.     end
  585. end
  586.  
  587. while not finished do
  588.     mineLayer(SIZE_X, SIZE_Z)
  589. end
  590.  
  591. while not turtle.inspectUp() do
  592.     turtle.digUp()
  593.     turtle.up()
  594.     modem.transmit(channel, 0, { map, pos, dir, 3 })
  595. end
  596.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement