Advertisement
Guest User

AE2Crafting.lua

a guest
Mar 22nd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.17 KB | None | 0 0
  1. -- Original by Palagius : https://oc.cil.li/index.php?/topic/1426-ae2-level-auto-crafting/
  2. -- Modfied by Dalden 2018-07-28
  3. --           - Store crafting result object to check for status
  4. --           - If crafting job is not yet finished from previous cycle then skip this cycle
  5. local arg = {...}
  6. if not arg[1] then
  7. arg[1] = "009" else arg[1] = tostring(arg[1]) end
  8. if not arg[2] then
  9. arg[2] = "ac7" else arg[2] = tostring(arg[2]) end
  10. local component = require("component")
  11. local term = require("term")
  12. local thread = require("thread")
  13. local event = require("event")
  14. local meController = component.proxy(component.me_controller.address)
  15. local gpu2p = component.proxy(component.get(arg[1]))
  16. local screen2 = component.get(arg[2])
  17. local count = 0
  18. startScreen(arg[1],arg[2])
  19. gpu2p.setForeground(0xFFFFFF)
  20. --term.setViewport(nil, nil, nil, nil, nil, nil, window)
  21.  
  22.  
  23. -- Each element of the array is "item", "damage", "number wanted", "max craft size"
  24. -- Damage value should be zero for base items
  25.  
  26. items = {
  27.     { "minecraft:coal",      1, 100, 300 }
  28. --    { "minecraft:coal_block",       0, 10, 256 }
  29. --    { "minecraft:iron_ingot",       0, 16384, 256 },
  30. --    { "minecraft:gold_ingot",       0, 16384, 256 },
  31. --    { "minecraft:glass",      0, 16384, 256 },
  32. --    { "minecraft:quartz",      0, 16384, 256 },
  33. --    { "minecraft:diamond",      0, 16384, 256 },
  34. --    { "minecraft:emerald",      0, 16384, 256 },
  35. --    { "draconicevolution:draconium_ingot",      0, 16384, 256 },
  36. --    { "thermalfoundation:material",       128, 1024, 256 }, -- Copper Ingot
  37. --    { "thermalfoundation:material",       129, 1024, 256 }, -- Tin Ingot
  38. --    { "thermalfoundation:material",       130, 1024, 256 }, -- Silver Ingot
  39. --    { "thermalfoundation:material",       131, 1024, 256 }, -- Lead Ingot
  40. --    { "thermalfoundation:material",       161, 1024, 256 }, -- Electrum Ingot
  41. --    { "thermalfoundation:material",       162, 1024, 256 }, -- Invar Ingot
  42. --    { "thermalfoundation:material",       163, 1024, 256 }, -- Bronze Ingot
  43. --    { "thermalfoundation:material",       164, 1024, 256 }, -- Constantan Ingot
  44. --    { "thermalfoundation:material",       165, 1024, 256 }, -- Signalum Ingot
  45. --    { "thermalfoundation:material",       166, 1024, 256 }, -- Lumium Ingot
  46. --    { "thermalfoundation:material",       167, 1024, 256 }, -- Enderium Ingot
  47. --    { "appliedenergistics2:material",       24, 4096, 256 }, -- Engineering Processor
  48. --    { "appliedenergistics2:material",       23, 4096, 256 }, -- Calculation Processor
  49. --    { "appliedenergistics2:material",       22, 4096, 256 }, -- Logic Processor
  50. --    { "appliedenergistics2:material",       11, 4096, 256 }, -- Pure Nether Quartz Crystal
  51. --    { "appliedenergistics2:material",       10, 4096, 256 }, -- Pure Certus Quartz Crystal
  52. --    { "appliedenergistics2:material",       7, 4096, 256 }, -- Fluix Crystal
  53. --    { "appliedenergistics2:material",       12, 4096, 256 }, -- Pure Fluix Crystal
  54. --    { "appliedenergistics2:material",       0, 4096, 256 }, -- Certus Quartz Crystal
  55. --    { "appliedenergistics2:material",       1, 4096, 256 }, -- Charged Certus Quartz Crystal
  56. --    { "appliedenergistics2:material",       8, 4096, 256 }, -- Fluix Dust
  57. --    { "appliedenergistics2:material",       2, 4096, 256 }, -- Certus Quartz Dust
  58. --    { "actuallyadditions:item_dust",       5, 4096, 256 }, -- Crushed Quartz
  59. --    { "enderio:item_material",       5, 4096, 256 }, -- Silicon
  60. --    { "enderio:item_alloy_ingot",       1, 1024, 256 }, -- Energetic Alloy Ingot
  61. --    { "enderio:item_alloy_ingot",       2, 1024, 256 }, -- Vibrant Alloy Ingot
  62. --    { "enderio:item_alloy_ingot",       5, 1024, 256 }, -- Pulsating Iron Ingot
  63. --    { "enderio:item_alloy_ingot",       6, 1024, 256 }, -- Dark Steel Ingot
  64. --    { "enderio:item_alloy_ingot",       7, 1024, 256 }, -- Soularium Ingot
  65. --    { "enderio:item_alloy_ingot",       8, 1024, 256 }, -- End Steel Ingot
  66. --    { "enderio:item_alloy_ingot",       0, 1024, 256 } -- Electrical Steel Ingot
  67. }
  68.  
  69. loopDelay = 60 -- Seconds between runs
  70.  
  71. -- Init list with crafting status
  72. for curIdx = 1, #items do
  73.     items[curIdx][5] = false -- Crafting status set to false
  74.     items[curIdx][6] = nil -- Crafting object null
  75. end
  76.  
  77. ae2 = thread.create(function()
  78. while true do
  79.     for curIdx = 1, #items do
  80.         curName = items[curIdx][1]
  81.         curDamage = items[curIdx][2]
  82.         curMinValue = items[curIdx][3]
  83.         curMaxRequest = items[curIdx][4]
  84.         curCrafting = items[curIdx][5]
  85.         curCraftStatus = items[curIdx][6]
  86.  
  87.         -- io.write("Checking for " .. curMinValue .. " of " .. curName .. "\n")
  88.         storedItem = meController.getItemsInNetwork({
  89.             name = curName,
  90.             damage = curDamage
  91.             })
  92.         drawText("Network contains ",gpu2p)
  93.         gpu2p.setForeground(0xCC24C0) -- Purple-ish
  94.         drawText(storedItem[1].size,gpu2p)
  95.         gpu2p.setForeground(0xFFFFFF) -- White
  96.         drawText(" items with label ",gpu2p)
  97.         gpu2p.setForeground(0x00FF00) -- Green
  98.         drawText(storedItem[1].label .. "\n",gpu2p)
  99.         gpu2p.setForeground(0xFFFFFF) -- White
  100.         if storedItem[1].size < curMinValue then
  101.             delta = curMinValue - storedItem[1].size
  102.             craftAmount = delta
  103.             if delta > curMaxRequest then
  104.                 craftAmount = curMaxRequest
  105.             end
  106.  
  107.             drawText("  Need to craft ",gpu2p)
  108.             gpu2p.setForeground(0xFF0000) -- Red
  109.             drawText(delta,gpu2p)
  110.             gpu2p.setForeground(0xFFFFFF) -- White
  111.             drawText(", requesting ",gpu2p)
  112.             gpu2p.setForeground(0xCC24C0) -- Purple-ish
  113.             drawText(craftAmount .. "... ",gpu2p)
  114.             gpu2p.setForeground(0xFFFFFF) -- White
  115.  
  116.             craftables = meController.getCraftables({
  117.                 name = curName,
  118.                 damage = curDamage
  119.                 })
  120.             if craftables.n >= 1 then
  121.                 cItem = craftables[1]
  122.                 if curCrafting then
  123.                     if curCraftStatus.isCanceled() or curCraftStatus.isDone() then
  124.                         drawText("Previous Craft completed\n",gpu2p)
  125.                         items[curIdx][5] = false
  126.                         curCrafting = false
  127.                     end
  128.                 end
  129.                 if curCrafting then
  130.                         drawText("Previous Craft busy\n",gpu2p)
  131.                 end
  132.                 if not curCrafting then
  133.                     retval = cItem.request(craftAmount)
  134.                     items[curIdx][5] = true
  135.                     items[curIdx][6] = retval
  136.                     gpu2p.setForeground(0x00FF00) -- Green
  137.                     drawText("Requested - ",gpu2p)
  138.             --while (not retval.isCanceled()) and (not retval.isDone()) do
  139.                 --      os.sleep(1)
  140.                     --        io.write(".")
  141.             -- end
  142.                     gpu2p.setForeground(0xFFFFFF) -- White
  143.                     drawText("Done \n",gpu2p)
  144.                 end
  145.             else
  146.                 gpu2p.setForeground(0xFF0000) -- Red
  147.                 drawText("    Unable to locate craftable for " .. storedItem[1].name .. "\n",gpu2p)
  148.                 gpu2p.setForeground(0xFFFFFF) -- White
  149.             end
  150.         end
  151.     end
  152.     drawText("Sleeping for " .. loopDelay .. " seconds...\n\n",gpu2p)
  153.     event.pull(loopDelay,"ae2close")
  154. end
  155. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement