Advertisement
zajrik

treeFarmControl - old

Sep 19th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. local c1 = peripheral.wrap("diamond_0")
  2. local c2 = peripheral.wrap("diamond_1")
  3. local m  = peripheral.wrap("front")
  4.  
  5. local slots1     = c1.getInventorySize()
  6. local slots2     = c2.getInventorySize()
  7. --local stackSize1 = c1.getStackInSlot(1) --method call for stackSize#.maxSize var
  8. --local stackSize2 = c2.getStackInSlot(1)
  9. local maxItems1  = slots1 * 64
  10. local maxItems2  = slots2 * 64
  11.  
  12. function checkMachines()
  13.     term.setCursorPos(1, 3)
  14.     term.write("------------------")
  15.     if rs.getOutput("top") then
  16.         machine = "Harvest"
  17.         term.setCursorPos(1, 4)
  18.         term.write(machine.." : Off")
  19.     else
  20.         machine = "Harvest"
  21.         term.setCursorPos(1, 4)
  22.         term.write(machine.." : On ")
  23.     end
  24.     if rs.getOutput("right") then
  25.         machine = "Furnaces"
  26.         term.setCursorPos(1, 5)
  27.         term.write(machine..": Off")
  28.     else
  29.         machine = "Furnaces"
  30.         term.setCursorPos(1, 5)
  31.         term.write(machine..": On ")
  32.     end
  33. end
  34.  
  35. function clearScr(lines)
  36.     clear = "                             "
  37.     for i=1, lines do
  38.         term.setCursorPos(1, i)
  39.         term.write(clear)
  40.     end
  41.     --[[term.setCursorPos(1, 1) -- Block deprecated for efficiency, saved for debugging
  42.     term.write(clear)
  43.     term.setCursorPos(1, 2)
  44.     term.write(clear)
  45.     term.setCursorPos(1, 3)
  46.     term.write(clear)]]--
  47. end
  48.  
  49. function coalCount()
  50.     c1.condenseItems()
  51.    
  52.     inv  = c1.getAllStacks()
  53.     qty  = 0
  54.     name = c1.getStackInSlot(1)
  55.    
  56.     if name == nil then
  57.         nameAlt = "Charcoal"
  58.     end
  59.    
  60.     for k, v in pairs(inv) do
  61.    
  62.         qty = qty + v.qty
  63.        
  64.         if qty >= maxItems1 - 1 then
  65.             rs.setOutput("right", true)
  66.         elseif qty == nil then
  67.             qty = 0
  68.         else
  69.             rs.setOutput("right", false)
  70.         end
  71.        
  72.     end
  73.     term.setCursorPos(1, 1)
  74.     term.write(name.name..":"..qty.."/"..maxItems1 or nameAlt..":"..qty.."/"..maxItems1)
  75. end
  76.  
  77. function woodCount()
  78.     c2.condenseItems()
  79.    
  80.     inv  = c2.getAllStacks()
  81.     qty  = 0
  82.     name = c2.getStackInSlot(2)
  83.    
  84.     if name == nil then
  85.         nameAlt = "Oak Logs"
  86.     end
  87.  
  88.     for k, v in pairs(inv) do
  89.        
  90.         qty = qty + v.qty
  91.        
  92.         if qty >= maxItems2 - 1 then
  93.             rs.setOutput("top", true)
  94.         elseif qty == nil then
  95.             qty = 0
  96.         else
  97.             rs.setOutput("top", false)
  98.         end
  99.        
  100.     end
  101.     term.setCursorPos(1, 2)
  102.     term.write(name.name..":"..qty.."/"..maxItems2 or nameAlt..":"..qty.."/"..maxItems2)
  103. end
  104.  
  105. term.redirect(m)
  106. --term.setCursorPos(1, 5) --display debugging
  107. --term.write("debug")
  108. clearScr(5)
  109.  
  110. while true do
  111.     checkMachines()
  112.     coalCount()
  113.     woodCount()
  114.     sleep(1)
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement