Cypher121

export

Jun 28th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cntID = 24
  2. outID = 51
  3.  
  4. offset = 1000
  5.  
  6. trSide = "front"
  7. bufferSide = "back"
  8. bellowSide = "left"
  9. modemSide = "top"
  10. valveSide = "bottom"
  11.  
  12. jarType = "tilejar"
  13. voidType = "tilejarvoid"
  14.  
  15. trans = peripheral.wrap(trSide)
  16. buff = peripheral.wrap(bufferSide)
  17. rednet.open(modemSide)
  18.  
  19. source = {}
  20.  
  21. function mapJars()
  22.   pers = peripheral.getNames()
  23.   for i, v in pairs(pers) do
  24.     pType = peripheral.getType(v)
  25.     if (pType == voidType) then
  26.       if (string.sub(v, string.find(v, "_[^_]*$") + 1, -1) ~= outID) then
  27.         asp = peripheral.call(v, "getAspects")[1]
  28.         if (asp ~= nil) then
  29.           source[asp.name] = tonumber(string.sub(v, string.find(v, "_[^_]*$") + 1, -1))
  30.         end
  31.       end
  32.     end
  33.   end
  34. end
  35.  
  36. function getFill(per)
  37.   aspInfo = per.getAspects()[1]
  38.   if (aspInfo == nil) then
  39.     return 0
  40.   end
  41.   return aspInfo.quantity
  42. end
  43.  
  44. function push(ess, amount)
  45.   amount = amount - 1
  46.   rs.setOutput(valveSide, false)
  47.   jar = peripheral.wrap(voidType .. "_" .. source[ess])
  48.   targetJar = peripheral.wrap(jarType .. "_" .. outID)
  49.   if (targetJar == nil) then
  50.     targetJar = peripheral.wrap(voidType .. "_" .. outID)
  51.   end    
  52.   targetInitAmount = getFill(targetJar)
  53.   trans.setFreq(offset + source[ess])
  54.   initAmount = getFill(jar)
  55.   target = initAmount - amount - 1
  56.   complete = false
  57.   print("Target: " .. target)
  58.  
  59.   rs.setOutput(trSide, true)
  60.   rs.setOutput(valveSide, false)
  61.   while ((getFill(jar) >= target) and (getFill(jar) > 0)) do
  62.     buffFill = getFill(buff)
  63.     if (buffFill == 0) then
  64.       rs.setOutput(bellowSide, false)
  65.     elseif (buffFill == 8) then
  66.       rs.setOutput(bellowSide, true)
  67.     end
  68.   end
  69.   sleep(0.5)
  70.   rs.setOutput(trSide, false)
  71.   sleep(1)
  72.   rs.setOutput(bellowSide, false)
  73.   sleep(1)
  74.  
  75.   newTarget = targetInitAmount + amount
  76.   print("New target: " .. newTarget)
  77.   while (getFill(targetJar) < newTarget) do
  78.     buffFill = getFill(buff)
  79.     if (buffFill == 0) then
  80.       if (not complete) then
  81.         rs.setOutput(bellowSide, false)
  82.       else
  83.         sleep(2)
  84.         if (getFill(targetJar) < newTarget) then
  85.           rs.setOutput(valveSide, false)
  86.           complete = false
  87.         end
  88.       end
  89.     elseif (buffFill == 8) then
  90.       rs.setOutput(bellowSide, true)
  91.     end
  92.     if ((buffFill >= (newTarget - getFill(targetJar)) - 2) and (buffFill > 0)) then
  93.       rs.setOutput(bellowSide, true)
  94.       complete = true
  95.       rs.setOutput(valveSide, true)
  96.     end
  97.   end
  98.   rs.setOutput(trSide, true)
  99.   while (getFill(jar) < target) do
  100.   end
  101.   sleep(1)
  102.   rs.setOutput(trSide, false)
  103.   while (getFill(targetJar) <= newTarget) do
  104.     push1(ess)
  105.     print("Pushing last essentia")
  106.   end
  107. end
  108.  
  109. function push1(ess)
  110.   jar = peripheral.wrap(voidType .. "_" .. source[ess])
  111.   targetJar = peripheral.wrap(jarType .. "_" .. outID)
  112.   if (targetJar == nil) then
  113.     targetJar = peripheral.wrap(voidType .. "_" .. outID)
  114.   end
  115.   initAmount = getFill(jar)
  116.   initTarget = getFill(targetJar)
  117.   trans.setFreq(offset + source[ess])
  118.   rs.setOutput(bellowSide, false)
  119.   rs.setOutput(valveSide, false)
  120.   while (getFill(jar) >= initAmount) do
  121.     rs.setOutput(trSide, true)
  122.     sleep(0.25)
  123.     rs.setOutput(trSide, false)
  124.     sleep(0.25)
  125.   end
  126.   while (getFill(buff) == 0) do
  127.   end
  128.  
  129.   rs.setOutput(bellowSide, true)
  130.   while (getFill(targetJar) == initTarget) do
  131.   end
  132.  
  133.   rs.setOutput(valveSide, true)
  134. end
  135.      
  136. mapJars()
  137. rs.setOutput(trSide, false)
  138. rs.setOutput(valveSide, false)
  139. rs.setOutput(bellowSide, true)
  140. while true do
  141.   id, msg = rednet.receive()
  142.   if (id == cntID) then
  143.     t = textutils.unserialize(msg)
  144.     if (t.amount > 1) then
  145.       push(t.ess, t.amount)
  146.     else
  147.       push1(t.ess)
  148.     end
  149.     rednet.send(cntID, "OK")
  150.   end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment