Advertisement
Guest User

AE2Crafting.lua

a guest
Mar 29th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.31 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. items = {{"minecraft:coal,1,1,1"}}
  25. --os.execute("itemList.cfg")  
  26.  
  27. loopDelay = 30 -- Seconds between runs
  28.  
  29. -- Init list with crafting status
  30. for curIdx = 1, #items do
  31.     items[curIdx][5] = false -- Crafting status set to false
  32.     items[curIdx][6] = nil -- Crafting object null
  33. end
  34.  
  35.  
  36. local function loop()
  37.     --os.execute("itemList.cfg")
  38.     for curIdx = 1, #items do
  39.         curName = items[curIdx][1]
  40.         curDamage = items[curIdx][2]
  41.         curMinValue = items[curIdx][3]
  42.         curMaxRequest = items[curIdx][4]
  43.         curCrafting = items[curIdx][5]
  44.         curCraftStatus = items[curIdx][6]
  45.  
  46.         -- io.write("Checking for " .. curMinValue .. " of " .. curName .. "\n")
  47.         storedItem = meController.getItemsInNetwork({
  48.             name = curName,
  49.             damage = curDamage
  50.             })
  51.         drawText("Network contains ",gpu2p)
  52.         gpu2p.setForeground(0xCC24C0) -- Purple-ish
  53.         --print(storedItem[1].size)
  54.         drawText(storedItem[1].size,gpu2p)
  55.         gpu2p.setForeground(0xFFFFFF) -- White
  56.         drawText(" items with label ",gpu2p)
  57.         gpu2p.setForeground(0x00FF00) -- Green
  58.         drawText(storedItem[1].label .. "\n",gpu2p)
  59.         gpu2p.setForeground(0xFFFFFF) -- White
  60.         if storedItem[1].size < curMinValue then
  61.             delta = curMinValue - storedItem[1].size
  62.             craftAmount = delta
  63.             if delta > curMaxRequest then
  64.                 craftAmount = curMaxRequest
  65.             end
  66.  
  67.             drawText("  Need to craft ",gpu2p)
  68.             gpu2p.setForeground(0xFF0000) -- Red
  69.             drawText(delta,gpu2p)
  70.             gpu2p.setForeground(0xFFFFFF) -- White
  71.             drawText(", requesting ",gpu2p)
  72.             gpu2p.setForeground(0xCC24C0) -- Purple-ish
  73.             drawText(craftAmount .. "... ",gpu2p)
  74.             gpu2p.setForeground(0xFFFFFF) -- White
  75.  
  76.             craftables = meController.getCraftables({
  77.                 name = curName,
  78.                 damage = curDamage
  79.                 })
  80.             if craftables.n >= 1 then
  81.                 cItem = craftables[1]
  82.                 if curCrafting then
  83.                     if curCraftStatus.isCanceled() or curCraftStatus.isDone() then
  84.                         drawText("Previous Craft completed\n",gpu2p)
  85.                         items[curIdx][5] = false
  86.                         curCrafting = false
  87.                     end
  88.                 end
  89.                 if curCrafting then
  90.                         drawText("Previous Craft busy\n",gpu2p)
  91.                 end
  92.                 if not curCrafting then
  93.                     retval = cItem.request(craftAmount)
  94.                     items[curIdx][5] = true
  95.                     items[curIdx][6] = retval
  96.                     gpu2p.setForeground(0x00FF00) -- Green
  97.                     drawText("Requested - ",gpu2p)
  98.             --while (not retval.isCanceled()) and (not retval.isDone()) do
  99.                 --      os.sleep(1)
  100.                     --        io.write(".")
  101.             -- end
  102.                     gpu2p.setForeground(0xFFFFFF) -- White
  103.                     drawText("Done \n",gpu2p)
  104.                 end
  105.             else
  106.                 gpu2p.setForeground(0xFF0000) -- Red
  107.                 drawText("    Unable to locate craftable for " .. storedItem[1].name .. "\n",gpu2p)
  108.                 gpu2p.setForeground(0xFFFFFF) -- White
  109.             end
  110.         end
  111.     end
  112.     drawText("Sleeping for " .. loopDelay .. " seconds...\n\n",gpu2p)
  113. end
  114.  
  115. loop()
  116. ae2timer = event.timer(loopDelay, loop, math.huge)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement