Advertisement
starkrights

utils.lua

May 27th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 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.     turtle.equipLeft()
  67.     --- Dig entangloporter
  68.     turtle.forward()
  69.     turtle.forward()
  70.     turtle.up()
  71.     turtle.digUp()
  72.     turtle.down()
  73.     turtle.back()
  74.     turtle.back()
  75.  
  76.     --- Dig fluxpoint
  77.     turtle.turnRight()
  78.     turtle.forward()
  79.     turtle.forward()
  80.     turtle.digUp()
  81.     turtle.back()
  82.     turtle.back()
  83.     turtle.turnLeft()
  84.  
  85.     --- Mine digiminer
  86.     turtle.digUp()
  87. end
  88.  
  89. function constructDigiminerComplex()
  90.     digiminerSlot = findItemSlot(BLOCK_IDS.digiminer)
  91.     tesseractSlot = findItemSlot(BLOCK_IDS.tesseract)
  92.     fluxpointSlot = findItemSlot(BLOCK_IDS.fluxpoint)
  93.     modemSlot = findItemSlot(BLOCK_IDS.modem)
  94.     --- place digiminer
  95.     turtle.select(digiminerSlot)
  96.     turtle.placeUp()
  97.    
  98.     --- place entangloporter
  99.     turtle.forward()
  100.     turtle.forward()
  101.     turtle.up()
  102.     turtle.select(tesseractSlot)
  103.     turtle.placeUp()
  104.     turtle.down()
  105.     turtle.back()
  106.     turtle.back()
  107.  
  108.     --- place fluxpoint
  109.     turtle.turnRight()
  110.     turtle.forward()
  111.     turtle.forward()
  112.     turtle.select(fluxpointSlot)
  113.     turtle.placeUp()
  114.     turtle.back()
  115.     turtle.back()
  116.     turtle.turnLeft()
  117. end
  118.  
  119.  
  120. function main()
  121.     while true do
  122.         local digiminer = peripheral.wrap("top")
  123.         if peripheral.getType(digiminer) ~= "digitalMiner" then
  124.             print("Loop broken: Digiminer not found above turtle")
  125.             return -1
  126.         end
  127.         local toMine = digiminer.getToMine()
  128.         if toMine ~= 0 then
  129.             print("Digminer still mining with "..toMine.." left to go. Sleeping for 1 miunte...")
  130.             os.sleep(60)
  131.         else
  132.             print("Digiminer finished mining. Starting relocation process...")
  133.            
  134.             print("  Deconstructing digiminer complex...")
  135.             deconstructDigiminerComplex()
  136.             print("    Digiminer complex deconstructed!")
  137.            
  138.             print("  Moving to next chunk...")
  139.             gotoNextChunkCenter()
  140.             print("    Reached next chunk!")
  141.            
  142.             print("  Constructing digiminer complex...")
  143.             constructDigiminerComplex()
  144.             print("    Constructed digiminer complex!")
  145.  
  146.             digiminer = peripheral.wrap("top")
  147.             if peripheral.getType(digiminer) ~= "digitalMiner" then
  148.                 print("Loop broken: Digiminer not found above turtle after relocation")
  149.                 return -1
  150.             end
  151.  
  152.             digiminer.start()
  153.         end
  154.     end
  155. end
  156.  
  157. deconstructDigiminerComplex()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement