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.14 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.     pick = "minecraft:diamond_pickaxe"
  46. }
  47. function findItemSlot(itemName)
  48.     print("Finding item '"..itemName.."'...")
  49.     for i=1,16 do
  50.         print("  Testing slot "..i)
  51.         turtle.select(i)
  52.         item = turtle.getItemDetail()
  53.         if item then
  54.             print("    - Slot contains "..item.name)
  55.             if item.name == itemName then
  56.                 return i
  57.             end
  58.         else
  59.             print("    - Slot is nil")
  60.         end
  61.     end
  62.     return -1
  63. end
  64.  
  65.  
  66. function deconstructDigiminerComplex()
  67.     turtle.select(findItemSlot(BLOCK_IDS.pick))
  68.     turtle.equipLeft()
  69.     --- Dig entangloporter
  70.     turtle.forward()
  71.     turtle.forward()
  72.     turtle.up()
  73.     turtle.digUp()
  74.     turtle.down()
  75.     turtle.back()
  76.     turtle.back()
  77.  
  78.     --- Dig fluxpoint
  79.     turtle.turnRight()
  80.     turtle.forward()
  81.     turtle.forward()
  82.     turtle.digUp()
  83.     turtle.back()
  84.     turtle.back()
  85.     turtle.turnLeft()
  86.  
  87.     --- Mine digiminer
  88.     turtle.digUp()
  89. end
  90.  
  91. function constructDigiminerComplex()
  92.     digiminerSlot = findItemSlot(BLOCK_IDS.digiminer)
  93.     tesseractSlot = findItemSlot(BLOCK_IDS.tesseract)
  94.     fluxpointSlot = findItemSlot(BLOCK_IDS.fluxpoint)
  95.     modemSlot = findItemSlot(BLOCK_IDS.modem)
  96.     --- place digiminer
  97.     turtle.select(digiminerSlot)
  98.     turtle.placeUp()
  99.    
  100.     --- place entangloporter
  101.     turtle.forward()
  102.     turtle.forward()
  103.     turtle.up()
  104.     turtle.select(tesseractSlot)
  105.     turtle.placeUp()
  106.     turtle.down()
  107.     turtle.back()
  108.     turtle.back()
  109.  
  110.     --- place fluxpoint
  111.     turtle.turnRight()
  112.     turtle.forward()
  113.     turtle.forward()
  114.     turtle.select(fluxpointSlot)
  115.     turtle.placeUp()
  116.     turtle.back()
  117.     turtle.back()
  118.     turtle.turnLeft()
  119. end
  120.  
  121.  
  122. function main()
  123.     while true do
  124.         local digiminer = peripheral.wrap("top")
  125.         if peripheral.getType(digiminer) ~= "digitalMiner" then
  126.             print("Loop broken: Digiminer not found above turtle")
  127.             return -1
  128.         end
  129.         local toMine = digiminer.getToMine()
  130.         if toMine ~= 0 then
  131.             print("Digminer still mining with "..toMine.." left to go. Sleeping for 1 miunte...")
  132.             os.sleep(60)
  133.         else
  134.             print("Digiminer finished mining. Starting relocation process...")
  135.            
  136.             print("  Deconstructing digiminer complex...")
  137.             deconstructDigiminerComplex()
  138.             print("    Digiminer complex deconstructed!")
  139.            
  140.             print("  Moving to next chunk...")
  141.             gotoNextChunkCenter()
  142.             print("    Reached next chunk!")
  143.            
  144.             print("  Constructing digiminer complex...")
  145.             constructDigiminerComplex()
  146.             print("    Constructed digiminer complex!")
  147.  
  148.             digiminer = peripheral.wrap("top")
  149.             if peripheral.getType(digiminer) ~= "digitalMiner" then
  150.                 print("Loop broken: Digiminer not found above turtle after relocation")
  151.                 return -1
  152.             end
  153.  
  154.             digiminer.start()
  155.         end
  156.     end
  157. end
  158.  
  159. deconstructDigiminerComplex()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement