Advertisement
Guest User

craft.lua

a guest
Feb 16th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.50 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.  
  6. local component = require("component")
  7. local meController = component.proxy(component.me_controller.address)
  8. local gpu = component.gpu
  9.  
  10. -- Each element of the array is "item", "damage", "number wanted", "max craft size"
  11. -- Damage value should be zero for base items
  12.  
  13. items = {
  14. -- Applied Energistics
  15.   { "appliedenergistics2:material",       24, 10000, 1000 }, -- Engineering Processor
  16.   { "appliedenergistics2:material",       23, 10000, 1000 }, -- Calculation Processor
  17.   { "appliedenergistics2:material",       22, 10000, 1000 }, -- Logic Processor
  18.  
  19.   { "appliedenergistics2:part",       56, 1000, 100 }, -- ME Smart Cable
  20.   { "appliedenergistics2:part",       76, 1000, 100 }, -- ME Dense Smart Cable
  21.   { "appliedenergistics2:part",       140, 1000, 100 }, -- Quartz Fiber
  22.   { "appliedenergistics2:part",       120, 1000, 100 }, -- Cable Anchor
  23.   { "appliedenergistics2:interface",       0, 100, 10 }, -- ME Interface
  24.   { "appliedenergistics2:part",       440, 1000, 100 }, -- Me Interface
  25.   { "appliedenergistics2:part",       260, 1000, 100 }, -- Export Bus
  26.   { "appliedenergistics2:part",       240, 1000, 100 }, -- Import Bus
  27.   { "appliedenergistics2:part",       280, 100, 10 }, -- ME Level Emitter
  28.   { "appliedenergistics2:part",       460, 100, 10 }, -- P2P Tunnel - ME
  29.  
  30.   { "appliedenergistics2:material",       25, 1000, 1000 }, -- Basic Card
  31.   { "appliedenergistics2:material",       27, 1000, 100 }, -- Capacity Card
  32.   { "appliedenergistics2:material",       53, 1000, 100 }, -- Crafting Card
  33.   { "appliedenergistics2:material",       26, 1000, 100 }, -- Redstone Card
  34.   { "appliedenergistics2:material",       28, 1000, 1000 }, -- Advanced Card
  35.   { "appliedenergistics2:material",       29, 1000, 100 }, -- Fuzzy Card
  36.   { "appliedenergistics2:material",       31, 1000, 100 }, -- Inverter Card
  37.   { "appliedenergistics2:material",       30, 1000, 100 }, -- Acceleration Card
  38.  
  39.   { "appliedenergistics2:crafting_storage_64k", 0 , 100, 10 }, -- 64k Crafting Unit
  40.   { "appliedenergistics2:crafting_monitor", 0 , 10, 1 }, -- Crafting Monitor
  41.   { "appliedenergistics2:crafting_accelerator", 0 , 100, 10 }, -- Crafting Co-Processor
  42.  
  43.   { "extracells:storage.physical", 3 , 10, 1 }, -- 16384k Storage
  44.   { "appliedenergistics2:dense_energy_cell", 0 , 500, 50 }, -- Dense Energy Cell
  45.  
  46.   { "appliedenergistics2:fluid_storage_cell_1k",       0, 100, 10 }, -- 1k ME Fluid Storage Cell
  47.   { "appliedenergistics2:fluid_storage_cell_64k",       0, 10, 1 }, -- 64k ME Fluid Storage Cell
  48.   { "appliedenergistics2:part",       261, 1000, 100 }, -- Fluid Export Bus
  49.   { "appliedenergistics2:part",       241, 1000, 100 }, -- Fluid Import Bus
  50.   { "appliedenergistics2:part",       281, 100, 10 }, -- ME Fluid Level Emitter
  51.  
  52. -- Draconic Evolution
  53.   { "draconicevolution:draconic_core",       0, 1000, 100 }, -- Draconic Core
  54.   { "draconicevolution:wyvern_energy_core",       0, 100, 10 }, -- Wyvern Energy Core
  55.   { "draconicevolution:wyvern_core",       0, 100, 10 }, -- Wyvern Core
  56.   { "draconicevolution:draconium_block",       0, 1000, 100 }, -- Block of Draconium
  57.   { "draconicevolution:draconium_dust",       0, 10000, 1000 }, -- Draconium Dust
  58.  
  59. -- Mekanism
  60.   { "mekanism:controlcircuit",       0, 1000, 100 }, -- Basic Control Circuit
  61.   { "mekanism:controlcircuit",       1, 1000, 100 }, -- Advanced Control Circuit
  62.   { "mekanism:controlcircuit",       2, 1000, 100 }, -- Elite Control Circuit
  63.  
  64.   { "mekanism:reinforcedalloy", 0 , 1000, 100 }, -- Reinforced Alloy
  65.   { "mekanism:atomicalloy", 0 , 1000, 100 }, -- Atomic Alloy
  66.  
  67. -- Crafting Materials
  68.   { "minecraft:ender_eye", 0 , 1000, 100 }, -- Ender Eye
  69.   { "minecraft:string", 0 , 10000, 1000 }, -- String
  70.   { "extendedcrafting:material", 24 , 1000, 100 }, -- Crystaline Ingot
  71.  
  72. -- Fusion Reactor
  73.   { "nuclearcraft:fusion_core", 0 , 10, 1 }, -- Fusion Core
  74.   { "nuclearcraft:fusion_electromagnet_transparent_idle", 0 , 1000, 100 }, -- Clear Electromagnet
  75.   { "nuclearcraft:fusion_electromagnet_idle", 0 , 1000, 100 }, -- Electromagnet
  76.   { "nuclearcraft:fusion_connector", 0 , 100, 10 }, -- Connector
  77.  
  78. --Fision Reactor
  79.   { "nuclearcraft:reactor_casing_transparent", 0 , 1000, 100 }, -- NAME
  80.   { "nuclearcraft:fission_block", 0 , 200, 20 }, -- NAME
  81.   { "nuclearcraft:fission_controller_new_fixed", 0 , 10, 1 }, -- NAME
  82.   { "nuclearcraft:fission_port", 0 , 100, 10 }, -- NAME
  83.   { "nuclearcraft:cell_block", 0 , 200, 20 }, -- NAME
  84.   { "nuclearcraft:ingot_block", 8 , 200, 20 }, -- NAME
  85.  
  86.   { "nuclearcraft:cooler", 0 , 500, 50 }, -- NAME
  87.   { "nuclearcraft:cooler", 1 , 500, 50 }, -- NAME
  88.   { "nuclearcraft:cooler", 2 , 500, 50 }, -- NAME
  89.   { "nuclearcraft:cooler", 3 , 500, 50 }, -- NAME
  90.   { "nuclearcraft:cooler", 4 , 500, 50 }, -- NAME
  91.   { "nuclearcraft:cooler", 5 , 500, 50 }, -- NAME
  92.   { "nuclearcraft:cooler", 6 , 500, 50 }, -- NAME
  93.   { "nuclearcraft:cooler", 7 , 500, 50 }, -- NAME
  94.   { "nuclearcraft:cooler", 8 , 500, 50 }, -- NAME
  95.   { "nuclearcraft:cooler", 9 , 500, 50 }, -- NAME
  96.   { "nuclearcraft:cooler", 10, 500, 50 }, -- NAME
  97.   { "nuclearcraft:cooler", 11 , 500, 50 }, -- NAME
  98.   { "nuclearcraft:cooler", 12 , 500, 50 }, -- NAME
  99.   { "nuclearcraft:cooler", 13 , 500, 50 }, -- NAME
  100.   { "nuclearcraft:cooler", 14 , 500, 50 }, -- NAME
  101.   { "nuclearcraft:cooler", 15 , 500, 50 }, -- NAME
  102.  
  103. -- Mystical Agricalture
  104.   { "mysticalagriculture:crafting", 1 , 1000, 100 }, -- NAME
  105.   { "mysticalagriculture:crafting", 2 , 1000, 100 }, -- NAME
  106.   { "mysticalagriculture:crafting", 3 , 1000, 100 }, -- NAME
  107.   { "mysticalagriculture:crafting", 4 , 1000, 100 }, -- NAME
  108.   { "mysticalagradditions:insanium", 0 , 1000, 100 }, -- NAME
  109.  
  110.   { "mysticalagriculture:storage", 0, 1000, 100 }, -- NAME
  111.   { "mysticalagriculture:storage", 1 , 1000, 100 }, -- NAME
  112.   { "mysticalagriculture:storage", 2 , 1000, 100 }, -- NAME
  113.   { "mysticalagriculture:storage", 3 , 1000, 100 }, -- NAME
  114.   { "mysticalagriculture:storage", 4 , 1000, 100 }, -- NAME
  115.   { "mysticalagradditions:storage", 0 , 1000, 100 }, -- NAME
  116.  
  117.   { "mysticalagriculture:crafting", 32 , 1000, 100 }, -- NAME
  118.   { "mysticalagriculture:crafting", 34 , 1000, 100 }, -- NAME
  119.   { "mysticalagriculture:crafting", 35 , 1000, 100 }, -- NAME
  120.   { "mysticalagriculture:crafting", 36 , 1000, 100 }, -- NAME
  121.   { "mysticalagriculture:crafting", 37 , 1000, 100 }, -- NAME
  122.   { "mysticalagradditions:insanium", 2 , 1000, 100 }, -- NAME
  123.  
  124.   { "mysticalagriculture:growth_accelerator", 0 , 1000, 100 }, -- NAME
  125.   { "cyclicmagic:sprinkler", 0 ,300, 30 }, -- NAME
  126.  
  127.  
  128. }
  129.  
  130. loopDelay = 2 -- Seconds between runs
  131.  
  132. -- Init list with crafting status
  133. for curIdx = 1, #items do
  134.   items[curIdx][5] = false -- Crafting status set to false
  135.   items[curIdx][6] = nil -- Crafting object null
  136. end
  137.  
  138. while true do
  139.     for curIdx = 1, #items do
  140.         curName = items[curIdx][1]
  141.         curDamage = items[curIdx][2]
  142.         curMinValue = items[curIdx][3]
  143.         curMaxRequest = items[curIdx][4]
  144.         curCrafting = items[curIdx][5]
  145.         curCraftStatus = items[curIdx][6]
  146.  
  147.         -- io.write("Checking for " .. curMinValue .. " of " .. curName .. "\n")
  148.         storedItem = meController.getItemsInNetwork({
  149.             name = curName,
  150.             damage = curDamage
  151.             })
  152.         --io.write(storedItem.n)
  153.         -- IF ITEM NOT IN SYSTEM GET storedItem FROM COBBLESTONE FOR FORMAT THEN APPLY CURRENT VALUES
  154.         if storedItem.n == 0 then
  155.           storedItem = meController.getItemsInNetwork({
  156.               name = "minecraft:cobblestone",
  157.               damage = 0
  158.           })
  159.           storedItem[1].name = curName
  160.           storedItem[1].size = 0
  161.           storedItem[1].label = "missing item"          
  162.         end
  163.         gpu.setForeground(0xCC24C0) -- Purple-ish
  164.         io.write(storedItem[1].label)
  165.         gpu.setForeground(0xFFFFFF) -- White
  166.         io.write(" - ")    
  167.         gpu.setForeground(0xFFFF00) -- Yellow
  168.         io.write(math.floor(storedItem[1].size))
  169.         gpu.setForeground(0xFFFFFF) -- White
  170.         io.write(" of ")
  171.         gpu.setForeground(0xFFFF00) -- Yellow
  172.         io.write(curMinValue)
  173.         gpu.setForeground(0xFFFFFF) -- White
  174.         io.write(" - ")
  175.        
  176.         if storedItem[1].size < curMinValue then
  177.             delta = curMinValue - storedItem[1].size
  178.             craftAmount = curMaxRequest
  179.             io.write("Stockpile Shortfall of: ")
  180.             gpu.setForeground(0xFF0000) -- Red
  181.             io.write(math.floor(delta))
  182.             gpu.setForeground(0xFFFFFF) -- White
  183.             io.write(" - Requesting: ")
  184.             gpu.setForeground(0xFF0000) -- Red
  185.             io.write(craftAmount)
  186.             gpu.setForeground(0xFFFFFF) -- White
  187.             io.write(" - ")
  188.  
  189.             craftables = meController.getCraftables({
  190.                 name = curName,
  191.                 damage = curDamage
  192.                 })
  193.             if craftables.n >= 1 then
  194.                 cItem = craftables[1]
  195.                 if curCrafting then
  196.                     if curCraftStatus.isCanceled() or curCraftStatus.isDone() then
  197.                         items[curIdx][5] = false
  198.                         curCrafting = false
  199.                     end
  200.                 end
  201.                 if curCrafting then
  202.                         io.write("Previous Craft busy\n")
  203.                 end
  204.                 if not curCrafting then
  205.                     retval = cItem.request(craftAmount)
  206.                     items[curIdx][5] = true
  207.                     items[curIdx][6] = retval
  208.                     io.write("Crafting Request Made\n")
  209.                     os.sleep(15)
  210.                     --gpu.setForeground(0x00FF00) -- Green
  211.                     --io.write("Requested\n")
  212.           --gpu.setForeground(0xFFFFFF) -- White
  213.           --while (not retval.isCanceled()) and (not retval.isDone()) do
  214.           --  os.sleep(1)
  215.           --  io.write(".")
  216.           --end
  217.                     --io.write("Done \n")
  218.                 end
  219.             else
  220.                 gpu.setForeground(0xFF0000) -- Red
  221.                 io.write("    Unable to locate craftable for " .. storedItem[1].name .. "\n")
  222.                 gpu.setForeground(0xFFFFFF) -- White
  223.             end
  224.     else
  225.       delta = storedItem[1].size - curMinValue
  226.       io.write("Stockpile Surplus of: ")
  227.             gpu.setForeground(0x00FF00) -- Green
  228.             io.write(math.floor(delta))
  229.       io.write("\n")
  230.       gpu.setForeground(0xFFFFFF) -- White      
  231.         end
  232.     --io.write("Sleeping for " .. loopDelay .. " seconds...\n\n")
  233.     os.sleep(loopDelay)
  234.   end
  235.   io.write("\nLoop done, Starting Over!\n\n")
  236. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement