tuekats

tabletView

Feb 19th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2. inventorySensor = sensor.wrap("right")
  3.  
  4. local fullTablets = 0
  5. local emptyTablets = 0
  6.  
  7. local fullTabletKeys = {"0,-1,4","2,-1,4","4,-1,4","6,-1,4"}
  8. local emptyTabletKeys = {"0,-1,0","2,-1,0","4,-1,0","6,-1,0"}
  9.  
  10. function countContent(inventoryKey)
  11.     local sensorReading = {}
  12.     sensorReading = inventorySensor.getTargetDetails(inventoryKey)  
  13.     --print(textutils.serialize(sensorReading))
  14.     local content = sensorReading["ItemCount"]
  15.     return content
  16. end
  17.  
  18. function tabletCount()
  19.     while true do
  20.         fullTablets = 0
  21.         for key,val in ipairs(fullTabletKeys) do
  22.             fullTablets = fullTablets + countContent(val)
  23.         end
  24.         emptyTablets = 0
  25.         for key,val in ipairs(emptyTabletKeys) do
  26.             emptyTablets = emptyTablets + countContent(val)
  27.         end
  28.         sleep(10)
  29.     end
  30. end
  31.  
  32. function printTabletCount()
  33.     while true do
  34.         shell.run("clear")
  35.         print("full tablets: " ..fullTablets)
  36.         print("empty tablets: " ..emptyTablets)
  37.         print("tablets total: "..(fullTablets+emptyTablets) )
  38.         sleep(10)
  39.     end
  40. end
  41.  
  42. function craftTablets()
  43.     while true do
  44.         if ((fullTablets+emptyTablets)<5000) then
  45.             redstone.setOutput("left",true)
  46.             sleep(1)
  47.             redstone.setOutput("left",false)
  48.             sleep(1)
  49.         end
  50.         sleep(10)
  51.     end
  52. end
  53.  
  54. parallel.waitForAll(tabletCount,printTabletCount,craftTablets)
Advertisement
Add Comment
Please, Sign In to add comment