gelatine87

Energized Orb Autocrafting (ATM10)

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