Advertisement
fergenbergel

MinecoloniesEnhancedStorageIntegration

Aug 6th, 2021
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 KB | None | 0 0
  1.  
  2. --Opens the file for writing out errors.
  3. outputfile = "manualAttentionNeeded"
  4. local file = fs.open( outputfile, "w" )
  5.  
  6. items_needed_jade = colony.getBuilderResources({x=227, y=69, z=-2291})
  7. items_needed_ayleen = colony.getBuilderResources({x=220, y=64, z=-2315})
  8. items_needed_billy = colony.getBuilderResources({x=346, y=64, z=-2305})
  9. items_needed = {items_needed_jade, items_needed_ayleen, items_needed_billy}
  10.  
  11. print("\nCreating missing items...")
  12. --Loop through each builder
  13. for i in pairs(items_needed) do
  14.     --Loop through each item needed.
  15.     for index in pairs(items_needed[i]) do
  16.         local item_needed_name = items_needed[i][index]["item"]["name"]
  17.         local item_needed_count = items_needed[i][index]["item"]["count"]
  18.         local item_needed_status = items_needed[i][index]["status"]
  19.         local item_storage_count = refinedstorage.getItem({name = item_needed_name})["count"]
  20.        
  21.         --Make sure the item is needed by the builder
  22.         if item_needed_status ~= "NOT_NEEDED" then
  23.             if item_storage_count == nil then
  24.                 item_storage_count = 0
  25.             end
  26.            
  27.             --If the item has a crafting recipe and there is not enough already in storage, craft the remainder needed.
  28.             if refinedstorage.hasPattern({name=item_needed_name}) and item_needed_count - item_storage_count > 0 then
  29.                 --Write out what item and how many are in storage out of the total needed.
  30.                 file.write("\n")
  31.                 file.write(textutils.serialize(item_needed_name))
  32.                 file.write(" " .. textutils.serialize(item_storage_count) .. "/" .. textutils.serialize(item_needed_count))
  33.                 file.write("\nPreparing to create " .. item_needed_count - item_storage_count)
  34.                 refinedstorage.scheduleTask({name=item_needed_name}, item_needed_count - item_storage_count)
  35.             end
  36.            
  37.             if not refinedstorage.hasPattern({name=item_needed_name}) and item_needed_count - item_storage_count > 0 then --Pattern does not exist, and needs to be created manually.
  38.                 file.write("\nPattern Needed for " .. item_needed_name)
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. print("Waiting 30s for items to finish crafting...")
  45. sleep(30)
  46. print("Outputing Items...")
  47.  
  48. i = 0
  49. index = 0
  50.  
  51. for i in pairs(items_needed) do
  52.     --Loop through each item needed.
  53.     for index in pairs(items_needed[i]) do
  54.         local item_needed_name = items_needed[i][index]["item"]["name"]
  55.         local item_needed_count = items_needed[i][index]["item"]["count"]
  56.         local item_needed_status = items_needed[i][index]["status"]
  57.         local output_side = nil
  58.        
  59.         --Calculate Output Side based on building.
  60.         if i == 1 then
  61.             output_side = "up"
  62.         elseif i == 2 then
  63.             output_side = "north"
  64.         elseif i == 3 then
  65.             output_side = "west"
  66.         else
  67.             output_side = "north"
  68.         end
  69.        
  70.         --Make sure the item is needed by the builder
  71.         if item_needed_status ~= "NOT_NEEDED" then
  72.            
  73.             --Extract as many of the item as we need, up to the amount available.
  74.             refinedstorage.extractItem({name=item_needed_name}, item_needed_count, output_side)
  75.         end
  76.     end
  77. end
  78.  
  79. print("Please view " .. outputfile .. " for information on missing items.")
  80.  
  81. file.close()
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement