Advertisement
Guest User

debug

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