Advertisement
Stekeblad

Computercraft script automating Applied Energetics Inscribe

Mar 6th, 2016
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.00 KB | None | 0 0
  1. -- Created by Stekeblad 3/2016
  2.  
  3. -- This program is made to automate the inscriber from Applied Energetics
  4.  
  5. local pressChest = peripheral.wrap("chest_1")
  6. local resourceChest = peripheral.wrap("chest_2")
  7. local insc = peripheral.wrap("left") -- network name is tileinscriber_x there x is a number
  8. local siliChest = peripheral.wrap("chest_0")
  9. local pressChestDir = "east"
  10. local resourceChestDir = "north"
  11. local siliChestDir = "west"
  12. local printDBG = false
  13. local sleepDBG = false
  14.  
  15. -- Do not make any changes below
  16. --this line if you do not know
  17. --what you are doing
  18.  
  19. -----------------------------------------
  20.  
  21. if not insc then
  22.   error("Could not find inscriber")
  23. end
  24.  
  25. local curPress, slot = nil
  26. local nrSilicon = 0
  27. local pressGold, pressSilicon, pressPure, pressDiamond = nil
  28. if (insc.getStackInSlot(1) and string.find(insc.getStackInSlot(1).display_name, "Press")) then
  29.   insc.pushItemIntoSlot(pressChestDir, 1, 1, 1)
  30. else
  31.   insc.pushItemIntoSlot(siliChestDir, 1, 64, 27)
  32.   insc.pushItemIntoSlot(siliChestDir, 2, 64, 26)
  33.   insc.pushItemIntoSlot(resourceChestDir, 3, 64, 25)
  34.   insc.pushItemIntoSlot(siliChestDir, 4, 64, 1)
  35. end
  36. pressChest.condenseItems()
  37. if printDBG then print("finding presses...") end
  38. for i = 1, pressChest.getInventorySize() do
  39.   slot = pressChest.getStackInSlot(i)
  40.   if slot then
  41.     if (string.sub(slot.raw_name, 39) == "siliconpress") then
  42.       pressSilicon = i
  43.     elseif (string.sub(slot.raw_name, 39) == "logicprocessorpress") then
  44.       pressGold = i
  45.     elseif (string.sub(slot.raw_name, 39) == "engprocessorpress") then
  46.       pressDiamond = i
  47.     elseif (string.sub(slot.raw_name, 39) == "calcprocessorpress") then
  48.       pressPure = i
  49.     end
  50.   end
  51. end
  52. --if printDBG then print(pressGold .. " " .. pressSilicon .. " " .. pressPure .. " " .. pressDiamond) end
  53.  
  54. -----------------
  55.  
  56. function inscribeWithPress(press, slotNr, amount)
  57.   success = 0
  58.   if printDBG then print("inscribeWithPress") end
  59.   success = insc.pullItemIntoSlot(pressChestDir, press, 1, 1)
  60.   if success == 0 then error("Failed to place press in inscriber") end
  61.   for i = 1, amount do
  62.     sleep(0.5)
  63.     success = insc.pullItemIntoSlot(resourceChestDir, slotNr, 1, 3)
  64.     if success == 0 then error("Failed to move item from resourceChest slot " .. slotNr) end
  65.     local clogged = true
  66.     while clogged do
  67.       sleep(0.2)
  68.       if not insc.getStackInSlot(3) then
  69.         clogged = false
  70.       end
  71.     end
  72.   end
  73.   sleep(0.75)
  74.   if (string.find(insc.getStackInSlot(1).display_name, "Silicon")) then
  75.     insc.pushItemIntoSlot(siliChestDir, 4, 64, siliChest.getInventorySize())
  76.   else
  77.     insc.pushItemIntoSlot(pressChestDir, 4, 64, pressChest.getInventorySize())
  78.   end
  79.   insc.pushItemIntoSlot(pressChestDir, 1, 1, press)
  80.   resourceChest.condenseItems()
  81.   pressChest.condenseItems()
  82.   siliChest.condenseItems()
  83. end
  84.  
  85. function inscribeNoPress(resourceChestDir, printedType, redstone, silic)
  86.   local ok1 = 0
  87.   local ok2 = 0
  88.   local ok3 = 0
  89.   if printDBG then print("inscribeNoPress, " .. printedType) end
  90.   ok1 = insc.pullItemIntoSlot(pressChestDir, printedType, 1, 1)
  91.   ok2 = insc.pullItemIntoSlot(siliChestDir, silic, 1, 2)
  92.   ok3 = insc.pullItemIntoSlot(resourceChestDir, redstone, 1, 3)
  93.   if (ok1 == 0 or ok2 == 0 or ok3 == 0) then error("inscribeNoPress error moving: " .. ok1 .. " " .. ok2 .. " " .. ok3) end
  94.   if (not pressChest.getStackInSlot(printedType)) then
  95.     printedType = nil
  96.   elseif (not resourceChest.getStackInSlot(redstone)) then
  97.     redstone = nil
  98.   elseif (not siliChest.getStackInSlot(silic)) then
  99.     silic = nil
  100.   end
  101.   local clogged = true
  102.   while clogged do
  103.     sleep(0.2)
  104.     if not insc.getStackInSlot(2) then
  105.       clogged = false
  106.     end
  107.   end
  108.   sleep(0.5)
  109.   insc.pushItemIntoSlot(resourceChestDir, 4, 1, resourceChest.getInventorySize())
  110.   resourceChest.condenseItems()
  111.   return printedType, redstone, silic
  112. end
  113.  
  114. -----------------
  115. resourceChest.condenseItems()
  116.  
  117. local didJob = false
  118. local slotNr = 1
  119. local logic = nil
  120. local calcu = nil
  121. local enginer = nil
  122. local redstone = nil
  123. local silic = nil
  124.  
  125. while true do
  126.   if printDBG then print("main loop start") end
  127.   resourceChest.condenseItems()
  128.   slotNr = 1
  129.   slot = resourceChest.getStackInSlot(slotNr)
  130.   if sleepDBG then sleep(1) end
  131.  
  132.   while (slot ~= nil) and (slotNr < resourceChest.getInventorySize()) do
  133.     if printDBG then print("looping resources: " .. slotNr) end
  134.     didJob = false
  135.     if printDBG then print(slot.display_name) end
  136.     if slot.display_name == "Gold Ingot" then
  137.       if printDBG then print("gold") end
  138.       inscribeWithPress(pressGold, slotNr, slot.qty)
  139.       didJob = true
  140.     elseif slot.display_name == "Silicon" then
  141.       if printDBG then print("silicon") end
  142.       inscribeWithPress(pressSilicon, slotNr, slot.qty)
  143.       didJob = true
  144.     elseif slot.display_name == "Pure Certus Quartz Crystal" then
  145.       if printDBG then print("pure") end
  146.       inscribeWithPress(pressPure, slotNr, slot.qty)
  147.       didJob = true
  148.     elseif slot.display_name == "Diamond" then
  149.       if printDBG then print("diamond") end
  150.       inscribeWithPress(pressDiamond, slotNr, slot.qty)
  151.       didJob = true
  152.     end
  153.     if not didJob then
  154.       if printDBG then print("did no job") end
  155.       slotNr = slotNr + 1
  156.     end
  157.     slot = resourceChest.getStackInSlot(slotNr)
  158.     if sleepDBG then sleep(1) end
  159.   end
  160.   -- And now to the processors!
  161.   -- 1) Find materials slot number
  162.   for i = 1, siliChest.getInventorySize() do
  163.     if printDBG then print("finding printed parts: " .. i) end
  164.     invSlot = siliChest.getStackInSlot(i)
  165.     if (invSlot and string.find(invSlot.display_name, "Silicon")) then
  166.       silic = i
  167.     end
  168.     invSlot = pressChest.getStackInSlot(i)
  169.     if(invSlot and invSlot.display_name) then
  170.       if string.find(invSlot.display_name, "Printed") then
  171.         if (string.find(invSlot.display_name, "Calculation")) then
  172.           calcu = i
  173.         end
  174.         if (string.find(invSlot.display_name, "Engineering")) then
  175.           enginer = i
  176.         end
  177.         if (string.find(invSlot.display_name, "Logic")) then
  178.           logic = i
  179.         end
  180.       end
  181.       invSlot = resourceChest.getStackInSlot(i)
  182.       if(invSlot and invSlot.display_name == "Redstone") then
  183.         redstone = i
  184.       end
  185.     end
  186.     if sleepDBG then sleep(0.3) end
  187.   end
  188.   --if printDBG then print(calcu .. " " .. enginer .. " " .. logic) end
  189.   -- 2) make Circuits
  190.   while true do
  191.     if (not redstone or not silic or (not logic and not enginer and not calcu)) then
  192.       if printDBG then print("broke") end
  193.       break
  194.     else
  195.       if(logic) then
  196.         logic, redstone, silic = inscribeNoPress(resourceChestDir, logic, redstone, silic)
  197.       elseif(enginer) then
  198.         enginer, redstone, silic = inscribeNoPress(resourceChestDir, enginer, redstone,  silic)
  199.       elseif (calcu) then
  200.         calcu, redstone, silic = inscribeNoPress(resourceChestDir, calcu, redstone, silic)
  201.       end
  202.     end
  203.     if sleepDBG then sleep(1) end
  204.   end
  205.   if printDBG then print("sleeping...") end
  206.   sleep(10)
  207. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement