Advertisement
starkrights

utils.lua

May 27th, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. startX = 728
  2. startY = 253
  3. startZ = -169
  4.  
  5.  
  6. function gotoNextChunkCenter()
  7.     local x,y,z = gps.locate()
  8.     local nextX = x + 16
  9.     while x ~= nextX or z ~= startZ do
  10.         x,y,z = gps.locate()
  11.         turtle.refuel()
  12.             if x ~= nextX then
  13.                 if x > nextX then
  14.                     turtle.back()
  15.                 else
  16.                     turtle.forward()
  17.                 end
  18.             end
  19.            
  20.             if z ~= startZ then
  21.                 turtle.turnRight()
  22.                 if z > startZ then
  23.                     turtle.back()
  24.                 else
  25.                     turtle.forward()
  26.                 end
  27.                 turtle.turnLeft()
  28.             end
  29.     end
  30. end
  31.  
  32. RelativePosition = {x = 0, y = 0, z = 0}
  33. function RelativePosition:new ()
  34.     self.x = 0
  35.     self.y = 0
  36.     self.z = 0
  37.     return self
  38. end
  39.  
  40. BLOCK_IDS = {
  41.     digiminer = "mekanism:digital_miner",
  42.     tesseract = "mekanism:quantum_entangloporter",
  43.     fluxpoint = "fluxnetworks:flux_point",
  44.     modem = "computerecraft:wired_modem_full",
  45. }
  46. function findItemSlot(itemName)
  47.     print("Finding item '"..itemName.."'...")
  48.     for i=1,16 do
  49.         print("  Testing slot "..i)
  50.         turtle.select(i)
  51.         item = turtle.getItemDetail()
  52.         if item then
  53.             print("    - Slot contains "..item.name)
  54.             if item.name == itemName then
  55.                 return i
  56.             end
  57.         else
  58.             print("    - Slot is nil")
  59.         end
  60.     end
  61.     return -1
  62. end
  63.  
  64.  
  65. function deconstructDigiminerComplex()
  66.     --- Dig entangloporter
  67.     turtle.forward()
  68.     turtle.forward()
  69.     turtle.up()
  70.     turtle.digUp()
  71.     turtle.down()
  72.     turtle.back()
  73.     turtle.back()
  74.  
  75.     --- Dig fluxpoint
  76.     turtle.turnRight()
  77.     turtle.forward()
  78.     turtle.forward()
  79.     turtle.digUp()
  80.     turtle.back()
  81.     turtle.back()
  82.     turtle.turnLeft()
  83.  
  84.     --- Mine digiminer
  85.     turtle.digUp()
  86. end
  87.  
  88. function constructDigiminerComplex()
  89.     digiminerSlot = findItemSlot(BLOCK_IDS.digiminer)
  90.     tesseractSlot = findItemSlot(BLOCK_IDS.tesseract)
  91.     fluxpointSlot = findItemSlot(BLOCK_IDS.fluxpoint)
  92.     modemSlot = findItemSlot(BLOCK_IDS.modem)
  93.     --- place digiminer
  94.     turtle.select(digiminerSlot)
  95.     turtle.placeUp()
  96.    
  97.     --- place entangloporter
  98.     turtle.forward()
  99.     turtle.forward()
  100.     turtle.up()
  101.     turtle.select(tesseractSlot)
  102.     turtle.placeUp()
  103.     turtle.down()
  104.     turtle.back()
  105.     turtle.back()
  106.  
  107.     --- place fluxpoint
  108.     turtle.turnRight()
  109.     turtle.forward()
  110.     turtle.forward()
  111.     turtle.select(fluxpointSlot)
  112.     turtle.placeUp()
  113.     turtle.back()
  114.     turtle.back()
  115.     turtle.turnLeft()
  116. end
  117.  
  118.  
  119. function main()
  120.     while true do
  121.         local digiminer = peripheral.wrap("top")
  122.         if peripheral.getType(digiminer) ~= "digitalMiner" then
  123.             print("Loop broken: Digiminer not found above turtle")
  124.             return -1
  125.         end
  126.         local toMine = digiminer.getToMine()
  127.         if toMine ~= 0 then
  128.             print("Digminer still mining with "..toMine.." left to go. Sleeping for 1 miunte...")
  129.             os.sleep(60)
  130.         else
  131.             print("Digiminer finished mining. Starting relocation process...")
  132.            
  133.             print("  Deconstructing digiminer complex...")
  134.             deconstructDigiminerComplex()
  135.             print("    Digiminer complex deconstructed!")
  136.            
  137.             print("  Moving to next chunk...")
  138.             gotoNextChunkCenter()
  139.             print("    Reached next chunk!")
  140.            
  141.             print("  Constructing digiminer complex...")
  142.             constructDigiminerComplex()
  143.             print("    Constructed digiminer complex!")
  144.  
  145.             digiminer = peripheral.wrap("top")
  146.             if peripheral.getType(digiminer) ~= "digitalMiner" then
  147.                 print("Loop broken: Digiminer not found above turtle after relocation")
  148.                 return -1
  149.             end
  150.  
  151.             digiminer.start()
  152.         end
  153.     end
  154. end
  155.  
  156. deconstructDigiminerComplex()
  157. constructDigiminerComplex()
  158. digiminer = peripheral.wrap("top")
  159. os.sleep(20)
  160. digiminer.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement