pro_du_piton

ProcessOres

Sep 22nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. local args = {...}
  2.  
  3. if (#args < 3) then
  4.   error("Usage: process [inventory side] [output ore direction] [output pulverized direction")
  5. end
  6.  
  7. local inventory = peripheral.wrap(args[1])
  8.  
  9. local function yieldOs()
  10.     local loopTimerId = os.startTimer(tickInterval)
  11.    
  12.     while (true) do
  13.         local event, timerId = os.pullEvent("timer")    
  14.         if (timerId == loopTimerId) then
  15.             break
  16.         end
  17.     end
  18. end
  19.  
  20. local function exportItem(item, direction)
  21.     local count = 0
  22.     count = item.size;
  23.    
  24.     while (cout > 0) do
  25.         local amount = 64
  26.         if (count < amount) then
  27.             amount = count
  28.         end
  29.    
  30.         local status = interface.exportItem(item.fingerprint, direction, amount)
  31.         count = count - status.size
  32.         if (status.size ~= amount) then
  33.             -- Container space exceeded.
  34.             return
  35.         end
  36.    
  37.         yieldOs()
  38.     end
  39. end
  40.  
  41. local function mainTick()
  42.     local items = inventory.getAvailableItems()
  43.     local count = 0
  44.  
  45.     for _, item in pairs(items) do
  46.         if string.sub(item.display_name, -4) == " Ore" then
  47.             exportItem(item, args[2])
  48.         end
  49.    
  50.         if string.sub(item.display_name, 11) == "Pulverized " then
  51.             exportItem(item, args[3])
  52.         end
  53.     end
  54. end
  55.  
  56. local function main()
  57.     interface = peripheral.wrap(args[1])
  58.  
  59.     while (true) do
  60.         mainTick()
  61.         yieldOs()
  62.     end
  63. end
  64.  
  65. while true do
  66.   -- Prevent "not attached" error
  67.   pcall(main())
  68. end
Advertisement
Add Comment
Please, Sign In to add comment