Advertisement
gelatine87

Energized Orb Autocrafting (ATM10)

Jun 28th, 2025 (edited)
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.55 KB | Gaming | 0 0
  1. -- state enums
  2. local STATE_NONE = "NONE"
  3. local STATE_NITRO = "Nitro Crystal"
  4. local STATE_ENDER = "Ender Core"
  5. local STATE_BLAZE = "Block of Blazing Crystal"
  6. local STATE_NIOTIC = "Block of Niotic Crystal"
  7. local STATE_SPIRIT = "Block of Spirited Crystal"
  8. local STATE_STEEL = "Block of Energized Steel"
  9. local STATE_SNOW = "Charged Snowball"
  10. local STATE_ICE = "Dry Ice"
  11.  
  12. local STATE_ENERGY_BATTERY = "Creative Energy Battery"
  13. local STATE_ENERGY_CELL_POWAH = "Energy Cell (Creative)"
  14. local STATE_ENERGY_CELL = "Creative Energy Cell"
  15.  
  16. local STATE_VIBRANIUM_ALLTHEMODIUM_ALLOY_BLOCK = "Vibranium Allthemodium Alloy Block"
  17.  
  18. local STATE_BLAZING_CRYSTAL_BEE_SPAWN_EGG = "Blazing Crystal Bee Spawn Egg"
  19. local STATE_NIOTIC_CRYSTAL_BEE_SPAWN_EGG = "Niotic Crystal Bee Spawn Egg"
  20. local STATE_SPIRITID_CRYSTAL_BEE_SPAWN_EGG = "Spirited Crystal Bee Spawn Egg"
  21. local STATE_ENERGIZED_CRYSTAL_BEE_SPAWN_EGG = "Energized Crystal Bee Spawn Egg"
  22. local STATE_NITRO_CRYSTAL_BEE_SPAWN_EGG = "Nitro Crystal Bee Spawn Egg"
  23.  
  24.  
  25. -- item -> state table
  26. -- this table will be used to determine what item we are currently crafting
  27. -- and what items need to be transfered in order to craft that item
  28. local state_from_item_table = {
  29.     -- energized steel
  30.     ["minecraft:iron_block"]=STATE_STEEL,
  31.     ["minecraft:gold_block"]=STATE_STEEL,
  32.  
  33.     -- nitro
  34.     ["minecraft:nether_star"]=STATE_NITRO,
  35.     ["minecraft:redstone_block"]=STATE_NITRO,
  36.     ["powah:blazing_crystal_block"]=STATE_NITRO,
  37.  
  38.     -- ender core
  39.     ["minecraft:ender_eye"]=STATE_ENDER,
  40.     ["powah:dielectric_casing"]=STATE_ENDER,
  41.     ["powah:capacitor_basic_tiny"]=STATE_ENDER,
  42.  
  43.     -- blaze crystal
  44.     ["allthecompressed:blaze_rod_block"]=STATE_BLAZE,
  45.  
  46.     -- niotic crystal
  47.     ["minecraft:diamond_block"]=STATE_NIOTIC,
  48.  
  49.     -- spirited crystal
  50.     ["minecraft:emerald_block"]=STATE_SPIRIT,
  51.  
  52.     -- charged snowaball
  53.     ["minecraft:snowball"]=STATE_SNOW,
  54.  
  55.     -- dry ice
  56.     ["minecraft:blue_ice"]=STATE_ICE,
  57.  
  58.     -- creative energy battery
  59.     ["integrateddynamics:energy_battery"]=STATE_ENERGY_BATTERY,
  60.     ["allthetweaks:atm_star"]=STATE_ENERGY_BATTERY,
  61.  
  62.     -- energy cell (creative)
  63.     ["powah:energy_cell_nitro"]=STATE_ENERGY_CELL_POWAH,
  64.     ["allthetweaks:atm_star"]=STATE_ENERGY_CELL_POWAH,
  65.  
  66.     -- creative energy cell
  67.     ["megacell:mega_energy_cell"]=STATE_ENERGY_CELL,
  68.     ["allthetweaks:atm_star"]=STATE_ENERGY_CELL,
  69.  
  70.     -- vibranium - allthemodium alloy block
  71.     ["allthemodium:allthemodium_block"]=STATE_VIBRANIUM_ALLTHEMODIUM_ALLOY_BLOCK,
  72.     ["allthemodium:piglich:heart_block"]=STATE_VIBRANIUM_ALLTHEMODIUM_ALLOY_BLOCK,
  73.     ["allthecompressed:nitro_crystal_block_2x"]=STATE_VIBRANIUM_ALLTHEMODIUM_ALLOY_BLOCK,
  74.     ["allthemodium:vibranium_block"]=STATE_VIBRANIUM_ALLTHEMODIUM_ALLOY_BLOCK
  75.  
  76. }
  77.  
  78. -- item table describing what items are required to craft in each state
  79. local state_item_recipies = {
  80.     [STATE_STEEL] = {
  81.         ["minecraft:iron_block"] = 1,
  82.         ["minecraft:gold_block"] = 1
  83.     },
  84.     [STATE_NITRO] = {
  85.         ["minecraft:redstone_block"] = 2,
  86.         ["powah:blazing_crystal_block"] = 1,
  87.         ["minecraft:nether_star"] = 1
  88.     },
  89.     [STATE_ENDER] = {
  90.         ["minecraft:ender_eye"] = 1,
  91.         ["powah:dielectric_casing"] = 1,
  92.         ["powah:capacitor_basic_tiny"] = 1
  93.     },
  94.     [STATE_BLAZE] = {
  95.         ["allthecompressed:blaze_rod_block"] = 1
  96.     },
  97.     [STATE_NIOTIC] = {
  98.         ["minecraft:diamond_block"] = 1
  99.     },
  100.     [STATE_SPIRIT] = {
  101.         ["minecraft:emerald_block"] = 1
  102.     },
  103.     [STATE_ICE] = {
  104.         ["minecraft:blue_ice"] = 6
  105.     },
  106.     [STATE_ENERGY_BATTERY] = {
  107.         ["integrateddynamics:energy_battery"] = 4,
  108.         ["allthetweaks:atm_star"] = 1
  109.     },
  110.     [STATE_ENERGY_CELL] = {
  111.         ["imegacell:mega_energy_cell"] = 4,
  112.         ["ae2:certus_quartz_crystal"] = 1
  113.     },
  114.     [STATE_ENERGY_CELL_POWAH] = {
  115.         ["powah:energy_cell_nitro"] = 4,
  116.         ["ae2:certus_quartz_crystal"] = 1
  117.     },
  118.     [STATE_VIBRANIUM_ALLTHEMODIUM_ALLOY_BLOCK] = {
  119.         ["allthemodium:allthemodium_block"] = 1,
  120.         ["allthemodium:piglich:heart_block"] = 2,
  121.         ["allthecompressed:nitro_crystal_block_2x"] = 1,
  122.         ["allthemodium:vibranium_block"] = 1
  123.     },
  124.     [STATE_SNOW] = {
  125.         ["minecraft:snowball"] = 1
  126.     }
  127. }
  128.  
  129. ---------------------------------
  130. -- DO NOT EDIT BELOW THIS LINE --
  131. ---------------------------------
  132.  
  133. -- the current state of the system
  134. cur_state = STATE_NONE
  135.  
  136. -- helper function for cloning the item table
  137. function table.clone(org)
  138.     local tbl = {}
  139.     for k,v in pairs(org) do
  140.         tbl[k] = v
  141.     end
  142.     return tbl
  143. end
  144.  
  145. -- helper function for len of table
  146. function table.count(tbl)
  147.     local count = 0
  148.     for _ in pairs(tbl) do
  149.         count = count + 1
  150.     end
  151.     return count
  152. end
  153.  
  154. -- determine what state we should enter
  155. -- based on what item we find in the chest
  156. function determineStateFromItem(item)
  157.     local state = state_from_item_table[item]
  158.     if state == nil then
  159.         return STATE_NONE
  160.     else
  161.         return state
  162.     end
  163. end
  164.  
  165. -- find where the chest is
  166. local chest = peripheral.find("ars_nouveau:repository")
  167. local orb = peripheral.find("powah:energizing_orb")
  168.  
  169. -- waits for the orb's inventory to be empty then
  170. -- signals that the orb is ready to craft another item
  171. function waitForReset()
  172.     while true do
  173.         if table.count(orb.list()) == 0 then
  174.             break
  175.         end
  176.     end
  177.     cur_state = STATE_NONE
  178. end
  179.  
  180. -- transfers the requested number of items from the slot in the chest to the orb,
  181. -- if there is not enough items in the stack to meet the demands of the recipe
  182. -- the value in the recipe will be decremented by the amount we could transfer
  183. function transferItem(itemList, slot, item)
  184.     -- # items we need to transfer
  185.     local count = itemList[item.name]
  186.     -- try to transfer the items
  187.     local itemsTransfered = chest.pushItems(peripheral.getName(orb), slot, count)
  188.     -- number of items left required to craft the recipe
  189.     local itemsLeft = count - itemsTransfered
  190.     -- if 0 then we have enough of this item and can stop searching for it,
  191.     -- otherwise set to the amount left required to craft
  192.     if itemsLeft <= 0 then
  193.         itemList[item.name] = nil
  194.     else
  195.         itemList[item.name] = itemsLeft
  196.     end
  197. end
  198.  
  199. -- transfers the list of items from the chest to the orb
  200. -- this will remove items from the list
  201. function transferItems(itemList)
  202.     -- loop until all items are transfered
  203.     while next(itemList) ~= nil do
  204.         -- check every slot in the chest for any of the items we need to craft the current recipe
  205.         for slot, item in pairs(chest.list()) do
  206.             if itemList[item.name] ~= nil then
  207.                 transferItem(itemList, slot, item)
  208.             end
  209.         end
  210.     end
  211. end
  212.  
  213. -- constantly check the chest for items, 1 second sleeps between
  214. function waitForItems()
  215.     while cur_state == STATE_NONE do
  216.         for slot, item in pairs(chest.list()) do
  217.             cur_state = determineStateFromItem(item.name)
  218.             if cur_state ~= STATE_NONE then
  219.                 break
  220.             end
  221.         end
  222.         -- prevent looping forever with zero delay!
  223.         if cur_state == STATE_NONE then
  224.             os.sleep(1)
  225.         end
  226.     end
  227. end
  228.  
  229. -- print out program info
  230. print("Running with recipies:")
  231. printed_recipes = {}
  232.  
  233. for k, v in pairs(state_from_item_table) do
  234.     if printed_recipes[v] == nil then
  235.         printed_recipes[v] = true
  236.         print(("\t%s = {"):format(v))
  237.         for item, count in pairs(state_item_recipies[v]) do
  238.             print(("\t\t%d\t%s"):format(count, item))
  239.         end
  240.         print("\t}")
  241.     end
  242. end
  243. print("System started successfully!")
  244. print("")
  245. print("--------------------------------------")
  246. print("-- Mr. Fancy Dan's Crafting Manager --")
  247. print("--------------------------------------")
  248. print("")
  249.  
  250. -- main loop
  251. while true do
  252.     if state_item_recipies[cur_state] ~= nil then
  253.         -- if we are in a state which has a recipe
  254.         local items = table.clone(state_item_recipies[cur_state])
  255.         -- transfer the required items
  256.         transferItems(items)
  257.         -- then wait for the reset signal which tells us we are done crafting that item
  258.         waitForReset()
  259.     else
  260.         if cur_state ~= STATE_NONE then
  261.             print(("Unknown state '%d' detected"):format(cur_state))
  262.         else
  263.             -- if we don't have a recipe we are in the none state, so we should wait for the chest to
  264.             -- have an item which we can use to craft
  265.             waitForItems()
  266.         end
  267.     end
  268.     os.sleep(1)
  269. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement