akihex

rateCounter

Aug 24th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local args = {...}
  2.  
  3. mon = peripheral.find("monitor")
  4. input = "front"
  5. output = "back"
  6. --narc = peripheral.find("turtle")
  7.  
  8. rs.setOutput(input,false)
  9. rs.setOutput(output,false)
  10.  
  11. local function getItems()
  12.   rs.setOutput(input,true)
  13.   sleep(2)
  14.   rs.setOutput(input,false)
  15. end
  16.  
  17. local function flushItems()
  18.   rs.setOutput(output,true)
  19.   sleep(2)
  20.   rs.setOutput(output,false)
  21. end
  22.  
  23. local nItems = {}
  24.  
  25. local function getTime()
  26.   return os.day() * 24 + os.time()
  27. end
  28.  
  29. local start = getTime()
  30. local now = start + 0.001
  31.  
  32. -- changes for Direwolf20 and MC 1.7.10
  33. local function countItems()
  34.   now = getTime()
  35.   local item = nil
  36.   --local items = {}
  37.   for i = 1,16 do
  38.     item = turtle.getItemDetail(i)
  39.     if item then
  40.       --items[#items+1] = item
  41.       nItems[item.name] = nItems[item.name] and nItems[item.name]+item.count or item.count
  42.     end
  43.     item = nil
  44.   end
  45. end
  46.  
  47. local function countItems164()
  48.   now = getTime()
  49.   local items=narc.getAllStacks()
  50.   for i,item in pairs(items) do
  51.     nItems[item.name] = nItems[item.name] and nItems[item.name]+item.qty or item.qty
  52.   end
  53. end
  54.  
  55. local function displayCount()
  56.   if not mon then return 0 end
  57.   local monX,monY = mon.getSize()
  58.   local line = 1
  59.   mon.clear()
  60.   for name,qty in pairs(nItems) do
  61.     mon.setCursorPos(1,line)
  62.     mon.write(name)
  63.     mon.setCursorPos(monX - 5,line)
  64.     mon.write(qty)
  65.     line = line + 1
  66.   end
  67. end
  68.  
  69. local function displayRate()
  70.   if not mon then return 0 end
  71.   local monX,monY = mon.getSize()
  72.   local line = 1
  73.   mon.clear()
  74.   for name,qty in pairs(nItems) do
  75.     mon.setCursorPos(1,line)
  76.     mon.write(name)
  77.     mon.setCursorPos(monX - 5,line)
  78.     mon.write(qty / (now - start))
  79.     line = line + 1
  80.   end
  81. end
  82.  
  83. while true do
  84.   getItems()
  85.   countItems()
  86.   flushItems()
  87.   displayRate()
  88.   --sleep(5)
  89. end
Advertisement
Add Comment
Please, Sign In to add comment