Azzy_b

rscraft

Nov 18th, 2025 (edited)
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | Gaming | 0 0
  1. -- Refined Storage Craftable Browser + Craft Queue
  2. -- Requires: CC:Tweaked + Advanced Peripherals (rsBridge)
  3.  
  4. local bridge = peripheral.find("rsBridge")
  5. if not bridge then error("No RS Bridge found. Attach an RS Bridge block next to the computer!") end
  6.  
  7. local craftables = {}
  8. local scroll = 0
  9. local pageSize = 15
  10. local running = true
  11.  
  12. -- Pull craftable items from RS
  13. local function refreshCraftables()
  14.     craftables = bridge.listCraftableItems()
  15.     table.sort(craftables, function(a, b) return a.displayName < b.displayName end)
  16. end
  17.  
  18. -- Draw UI
  19. local function draw()
  20.     term.clear()
  21.     term.setCursorPos(1,1)
  22.     print("=== Refined Storage Crafting Browser ===")
  23.     print("Scroll: Up/Down | Craft: Enter | Refresh: R | Quit: Q")
  24.     print("----------------------------------------")
  25.  
  26.     for i = 1, pageSize do
  27.         local idx = i + scroll
  28.         if craftables[idx] then
  29.             print(string.format("%3d: %s", idx, craftables[idx].displayName))
  30.         end
  31.     end
  32. end
  33.  
  34. -- Ask the user how many to craft
  35. local function craftItem(item)
  36.     term.clear()
  37.     term.setCursorPos(1,1)
  38.     print("Crafting: " .. item.displayName)
  39.     write("Enter amount: ")
  40.     local amt = tonumber(read())
  41.  
  42.     if not amt or amt < 1 then
  43.         print("Invalid amount.")
  44.         sleep(1.5)
  45.         return
  46.     end
  47.  
  48.     print("Sending craft request...")
  49.     local success, err = bridge.craftItem({name = item.name, count = amt})
  50.  
  51.     if success then
  52.         print("Craft queued successfully!")
  53.     else
  54.         print("Craft failed: "..tostring(err))
  55.     end
  56.  
  57.     print("Press any key to return.")
  58.     os.pullEvent("key")
  59. end
  60.  
  61. -- Main event loop
  62. local function loop()
  63.     refreshCraftables()
  64.     draw()
  65.  
  66.     while running do
  67.         local event, key = os.pullEvent()
  68.  
  69.         if event == "key" then
  70.             if key == keys.q then
  71.                 running = false
  72.                 return
  73.             elseif key == keys.r then
  74.                 refreshCraftables()
  75.                 draw()
  76.             elseif key == keys.up then
  77.                 if scroll > 0 then scroll = scroll - 1 end
  78.                 draw()
  79.             elseif key == keys.down then
  80.                 if scroll < #craftables - pageSize then scroll = scroll + 1 end
  81.                 draw()
  82.             elseif key == keys.enter then
  83.                 term.setCursorPos(1, pageSize + 4)
  84.                 write("Enter ID to craft: ")
  85.                 local id = tonumber(read())
  86.  
  87.                 if id and craftables[id] then
  88.                     craftItem(craftables[id])
  89.                 else
  90.                     print("Invalid ID!")
  91.                     sleep(1)
  92.                 end
  93.  
  94.                 draw()
  95.             end
  96.         end
  97.     end
  98. end
  99.  
  100. loop()
  101.  
Advertisement
Add Comment
Please, Sign In to add comment