CelticCoder

hostMine

Sep 3rd, 2024 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.51 KB | None | 0 0
  1. os.loadAPI("turtleChest.lua")
  2.  
  3. --pick and modem swapped in left, chunkloader in right
  4.  
  5. maxturtles = 3
  6.  
  7. mineableItems = {
  8.     { "minecraft:iron_ore", "minecraft:raw_iron" },
  9.     { "minecraft:deepslate_iron_ore", "minecraft:raw_iron"},
  10.     {"minecraft:redstone_ore", "minecraft:redstone"},
  11.     { "minecraft:deepslate_redstone_ore", "minecraft:redstone"},
  12.     {"minecraft:gold_ore", "minecraft:raw_gold"},
  13.     { "minecraft:deepslate_gold_ore", "minecraft:raw_gold"},
  14.     { "minecraft:deepslate_diamond_ore", "minecraft:diamond" },
  15.     { "minecraft:diamond_ore", "minecraft:diamond" },
  16.     { "minecraft:nether_quartz_ore", "minecraft:quartz" },
  17.     { "minecraft:ancient_debris", "minecraft:netherite_scrap" }
  18. }
  19.  
  20. function isChestInFront()
  21.     local success, data = turtle.inspect()
  22.     if success and data.name:find("chest") then
  23.         return true
  24.     end
  25.     return false
  26. end
  27.  
  28. function findItemSlot(itemName)
  29.     for slot = 1, 16 do
  30.         local itemDetail = turtle.getItemDetail(slot)
  31.         if itemDetail and itemDetail.name == itemName then
  32.             return slot
  33.         end
  34.     end
  35.     return nil
  36. end
  37.  
  38. function insertAll()
  39.     for slot = 1, 16 do
  40.         if turtle.getItemCount(slot) > 0 and slot ~= findItemSlot("computercraft:wireless_modem_advanced") and slot ~= findItemSlot("minecraft:diamond_pickaxe") then
  41.             turtle.select(slot)
  42.             turtle.drop()
  43.         end
  44.     end
  45.     turtle.select(1)
  46. end
  47.  
  48. function findTurtleAmount(maxturtles)
  49.     maxheight = (31 * maxturtles) + 15
  50.     cx, cy, cz = gps.locate()
  51.     if cy - maxheight < -58 then
  52.         return math.floor((maxheight + 58) / 31)
  53.     else
  54.         return maxturtles
  55.     end
  56. end
  57.  
  58. function buildChest()
  59.     turtle.digUp()
  60.     turtle.up()
  61.     turtle.turnLeft()
  62.     turtle.turnLeft()
  63.     turtle.dig()
  64.     turtle.forward()
  65.     turtle.digDown()
  66.     turtle.turnRight()
  67.     slot = findItemSlot("minecraft:chest")
  68.     if slot == nil then
  69.         print("chest not found")
  70.         os.exit(1)
  71.     else
  72.         turtle.select(slot)
  73.         turtle.placeDown()
  74.         turtle.turnRight()
  75.         turtle.forward()
  76.         turtle.turnLeft()
  77.         slot = findItemSlot("minecraft:chest")
  78.         if slot == nil then
  79.             print("chest not found")
  80.             os.exit(1)
  81.         else
  82.             turtle.placeDown()
  83.             turtle.turnLeft()
  84.             turtle.forward()
  85.             turtle.dig()
  86.             turtle.forward()
  87.             turtle.turnLeft()
  88.             turtle.turnLeft()
  89.             turtle.digDown()
  90.             turtle.down()
  91.             slot = findItemSlot("minecraft:chest")
  92.             if slot ~= nil then
  93.                 turtle.select(slot)
  94.                 turtle.drop()
  95.             end
  96.         end
  97.     end
  98. end
  99.  
  100. function placeTurtles(turtles)
  101.     if not isChestInFront() then
  102.         buildChest()
  103.     end
  104.     for i = 1, turtles do
  105.         for j = 1, 31 do
  106.             turtle.digDown()
  107.             turtle.down()
  108.         end
  109.         turtle.dig()
  110.         slot = findItemSlot("computercraft:turtle_normal")
  111.         if slot == nil then
  112.             print("turtle not found")
  113.         else
  114.             turtle.select(slot)
  115.             turtle.place()
  116.             slot2 = findItemSlot("computercraft:wireless_modem_normal")
  117.             if slot2 ~= nil then
  118.                 turtle.select(slot2)
  119.                 turtle.drop(1)
  120.                 target = peripheral.wrap("front")
  121.                 target.turnOn()
  122.             else
  123.                 print("modem not found")
  124.             end
  125.         end
  126.     end
  127.     for i = 1, turtles do
  128.         for j = 1, 31 do
  129.             turtle.digUp()
  130.             turtle.up()
  131.         end
  132.     end
  133.     insertAll()
  134.     slot = findItemSlot("computercraft:wireless_modem_advanced")
  135.     turtle.select(slot)
  136.     turtle.equipLeft()
  137.     rednet.open("left")
  138.     for i = 1, turtles * turtles do
  139.         rednet.broadcast(mineableItems)
  140.     end
  141.     for i = 1, turtles do
  142.         id, workerstatus = rednet.receive() --this process should have a large time limit for worst case scenario.
  143.     end
  144.     slot = findItemSlot("minecraft:diamond_pickaxe")
  145.     turtle.select(slot)
  146.     turtle.equipLeft()
  147. end
  148.  
  149. function collectOre(turtles)
  150.     for i = 1, turtles do
  151.         for j = 1, 31 * i do
  152.             turtle.digDown()
  153.             turtle.down()
  154.         end
  155.         turtleChest.takeAll()
  156.         for j = 1, 31 * i do
  157.             turtle.digUp()
  158.             turtle.up()
  159.         end
  160.         insertAll()
  161.     --add feature to go to top and deposit
  162.     end
  163. end
  164.  
  165. function collectTurtles(turtles)
  166.     for i = 1, turtles do
  167.         for j = 1, 31 do
  168.             turtle.digDown()
  169.             turtle.down()
  170.         end
  171.         turtle.dig()
  172.     end
  173.     for i = 1, turtles do
  174.         for j = 1, 31 do
  175.             turtle.digUp()
  176.             turtle.up()
  177.         end
  178.     end
  179. end
  180.  
  181. slot = findItemSlot("computercraft:wireless_modem_advanced")
  182. if slot == nil then
  183.     print("modem not found")
  184.     os.exit(1)
  185. end
  186. turtle.select(slot)
  187. turtle.equipLeft()
  188.  
  189. rednet.open("left")
  190. turtles = findTurtleAmount(maxturtles)
  191. if turtles == 0 then
  192.     os.exit(1)
  193. end
  194. slot = findItemSlot("minecraft:diamond_pickaxe")
  195. turtle.select(slot)
  196. turtle.equipLeft()
  197. placeTurtles(turtles)
  198. collectOre(turtles)
  199. collectTurtles(turtles)
Advertisement
Add Comment
Please, Sign In to add comment