Cypher121

essence

Jun 28th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. chestSide = "back"
  2. furtvSide = "west"
  3. furSide = "top"
  4. aspSide = "left"
  5. asptvSide = "east"
  6. modemSide = "front"
  7. tlocSide = "bottom"
  8.  
  9. controlID = 24
  10. golemTravel = 5
  11. alembics = {}
  12. slot = {}
  13.  
  14. itemName = "Ethereal Essence"
  15. alembicType = "tilesiphon"
  16.  
  17. ch = peripheral.wrap(chestSide)
  18. as = peripheral.wrap(aspSide)
  19. fr = peripheral.wrap(furSide)
  20. rednet.open(modemSide)
  21.  
  22. ---------functions---------
  23. function getRemotePeripherals()
  24.   perID = peripheral.getNames()
  25.   for i, n in pairs(perID) do
  26.     if (peripheral.getType(n) == alembicType) then
  27.       table.insert(alembics, peripheral.wrap(n))
  28.     end
  29.   end
  30. end
  31.  
  32. function cleanChest()
  33.   for i = 1, 54 do
  34.     if (ch.getStackInSlot(i) ~= nil) then
  35.       if (ch.getStackInSlot(i).name ~= itemName) then
  36.         ch.destroyStack(i)
  37.       end
  38.     end
  39.   end
  40.   ch.condenseItems()
  41. end
  42.  
  43. function cleanSystem()
  44.   ch.condenseItems()
  45.   filled = table.getn(ch.getAllStacks())
  46.   if (filled >= (ch.getInventorySize() - 1)) then
  47.     cleanChest()
  48.   end
  49.   ch.pullItem(furtvSide, 1)
  50.   ch.pullItem(asptvSide, 1)
  51.   cleanChest()
  52. end
  53.  
  54. function buildAspectMap()
  55.   rs.setOutput(tlocSide, true)
  56.   for i = 1, 51 do
  57.     if (ch.getStackInSlot(i) ~= nil) then
  58.       ch.pushItem(asptvSide, i, 1)
  59.       asp1, asp2 = as.getAspects()
  60.       if (asp2 == "auram") then
  61.         asp2 = asp1
  62.       end
  63.       if (asp2 == nil) then
  64.         asp2 = "auram"
  65.       end
  66.       ch.pullItem(asptvSide, 1, 1, i)
  67.       slot[asp2] = i
  68.     end
  69.   end
  70.   rs.setOutput(tlocSide, false)
  71. end
  72.  
  73. function alembicsEssenceCount()
  74.   for t, al in pairs(alembics) do
  75.     if (al.getAspects()[1] ~= nil) then
  76.       return true
  77.     end
  78.   end
  79.   return false
  80. end
  81.  
  82. function getRequest()
  83.   print("Listening")
  84.   id, msg = rednet.receive()
  85.   if (id == controlID) then
  86.     print("Received request")
  87.     data = textutils.unserialize(msg)
  88.     if (data.asp == "auram") then
  89.       itemCount = math.ceil(data["amount"] / 4)
  90.     else
  91.       itemCount = math.ceil(data["amount"] / 2)
  92.     end
  93.     if (itemCount >= ch.getStackInSlot(slot[data.asp]).qty) then
  94.       itemCount = ch.getStackInSlot(slot[data.asp]).qty - 1
  95.     end
  96.     print("Pushing " .. itemCount .. " " .. data["asp"] .. " from " .. slot[data["asp"]])
  97.     process(slot[data.asp], itemCount)
  98.     rednet.send(id, "done")
  99.   end
  100. end
  101.  
  102. function process(slot, cnt)
  103.   while (cnt > 0) do
  104.     cnt = cnt - ch.pushItem(furtvSide, slot, cnt, 1)
  105.   end
  106.   while ((fr.getStackInSlot(1)) or alembicsEssenceCount()) do
  107.     sleep(1)
  108.   end
  109.   sleep(golemTravel)
  110.   print("Request completed")
  111. end
  112. ---------------------------
  113. print("Start")
  114.  
  115. cleanSystem()
  116. print("System ready")
  117.  
  118. buildAspectMap()
  119. print("Map built")
  120.  
  121. getRemotePeripherals()
  122. print("Remote peripherals wrapped")
  123.  
  124. while true do
  125.   getRequest()
  126. end
Advertisement
Add Comment
Please, Sign In to add comment