Advertisement
CelticCoder

mineWorker

Aug 29th, 2024 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. os.loadAPI("turtleGeoScanMine.lua")
  2. -- todo: decide how you want to set the quarry dimension system up,
  3. -- the orientation of the chest is determined if its a horizontal/vertical mine
  4.  
  5. manual = false
  6. quarryHostID = 1
  7.  
  8. local manualMineableItems = {
  9.     { "minecraft:iron_ore", "minecraft:raw_iron" },
  10.     { "minecraft:deepslate_iron_ore", "minecraft:raw_iron"},
  11.     {"minecraft:redstone_ore", "minecraft:redstone"},
  12.     { "minecraft:deepslate_redstone_ore", "minecraft:redstone"},
  13.     {"minecraft:gold_ore", "minecraft:raw_gold"},
  14.     { "minecraft:deepslate_gold_ore", "minecraft:raw_gold"},
  15.     { "minecraft:deepslate_diamond_ore", "minecraft:diamond" },
  16.     { "minecraft:diamond_ore", "minecraft:diamond" },
  17.     { "minecraft:nether_quartz_ore", "minecraft:quartz" },
  18.     { "minecraft:ancient_debris", "minecraft:netherite_scrap" }
  19. }
  20.  
  21. function findItemSlot(itemName)
  22.     for slot = 1, 16 do
  23.         local itemDetail = turtle.getItemDetail(slot)
  24.         if itemDetail and itemDetail.name == itemName then
  25.             return slot
  26.         end
  27.     end
  28.     return nil
  29. end
  30.  
  31. function equipModemIfNeeded()
  32.     -- Check if a modem is already equipped in the right slot
  33.     local modemSlot = turtle.getItemDetail(3) -- Right slot is slot 3
  34.     if modemSlot and modemSlot.name == "computercraft:wireless_modem_normal" then
  35.         print("Modem already equipped in the right slot.")
  36.         return true
  37.     end
  38.  
  39.     -- Try to find the modem in the inventory
  40.     local modemSlotIndex = findItemSlot("computercraft:wireless_modem_normal")
  41.     if modemSlotIndex then
  42.         -- Move the modem to the right slot
  43.         turtle.select(modemSlotIndex)
  44.         turtle.equipRight()
  45.         print("Modem equipped in the right slot.")
  46.         return true
  47.     else
  48.         print("No modem found in inventory.")
  49.         return false
  50.     end
  51. end
  52.  
  53. function worker()
  54.     id, message = rednet.receive()
  55.     turtle.equipRight()
  56.     if id == quarryHostID and message ~= nil and type(message) == "table" then
  57.         print("scan approved")
  58.         turtleGeoScanMine.geoMineList(message)
  59.     end
  60.     if id ~= quarryHostID then
  61.         print("ID error")
  62.     end
  63.     if message == nil then
  64.         print("Message nil error")
  65.     end
  66.     if type(message) ~= "table" then
  67.         print("Message Type error")
  68.         print("Type: ")
  69.         print(type(message))
  70.     end
  71.     slot = findItemSlot("computercraft:wireless_modem_normal")
  72.     print(slot)
  73.     if slot ~= nil then
  74.         turtle.select(slot)
  75.         turtle.equipRight()
  76.         rednet.open("right")
  77.         os.sleep(5)
  78.         rednet.send(id, "done")
  79.         turtle.equipRight()
  80.     end
  81. end
  82.  
  83. function manualWorker()
  84.     turtleGeoScanMine.geoMineList(manualMineableItems)
  85. end
  86.  
  87. if manual then
  88.     manualWorker()
  89. else
  90.     os.sleep(3)
  91.     if equipModemIfNeeded() then
  92.         rednet.open("right")
  93.         worker()
  94.     end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement