Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cntID = 24
- outID = 51
- offset = 1000
- trSide = "front"
- bufferSide = "back"
- bellowSide = "left"
- modemSide = "top"
- valveSide = "bottom"
- jarType = "tilejar"
- voidType = "tilejarvoid"
- trans = peripheral.wrap(trSide)
- buff = peripheral.wrap(bufferSide)
- rednet.open(modemSide)
- source = {}
- function mapJars()
- pers = peripheral.getNames()
- for i, v in pairs(pers) do
- pType = peripheral.getType(v)
- if (pType == voidType) then
- if (string.sub(v, string.find(v, "_[^_]*$") + 1, -1) ~= outID) then
- asp = peripheral.call(v, "getAspects")[1]
- if (asp ~= nil) then
- source[asp.name] = tonumber(string.sub(v, string.find(v, "_[^_]*$") + 1, -1))
- end
- end
- end
- end
- end
- function getFill(per)
- aspInfo = per.getAspects()[1]
- if (aspInfo == nil) then
- return 0
- end
- return aspInfo.quantity
- end
- function push(ess, amount)
- amount = amount - 1
- rs.setOutput(valveSide, false)
- jar = peripheral.wrap(voidType .. "_" .. source[ess])
- targetJar = peripheral.wrap(jarType .. "_" .. outID)
- if (targetJar == nil) then
- targetJar = peripheral.wrap(voidType .. "_" .. outID)
- end
- targetInitAmount = getFill(targetJar)
- trans.setFreq(offset + source[ess])
- initAmount = getFill(jar)
- target = initAmount - amount - 1
- complete = false
- print("Target: " .. target)
- rs.setOutput(trSide, true)
- rs.setOutput(valveSide, false)
- while ((getFill(jar) >= target) and (getFill(jar) > 0)) do
- buffFill = getFill(buff)
- if (buffFill == 0) then
- rs.setOutput(bellowSide, false)
- elseif (buffFill == 8) then
- rs.setOutput(bellowSide, true)
- end
- end
- sleep(0.5)
- rs.setOutput(trSide, false)
- sleep(1)
- rs.setOutput(bellowSide, false)
- sleep(1)
- newTarget = targetInitAmount + amount
- print("New target: " .. newTarget)
- while (getFill(targetJar) < newTarget) do
- buffFill = getFill(buff)
- if (buffFill == 0) then
- if (not complete) then
- rs.setOutput(bellowSide, false)
- else
- sleep(2)
- if (getFill(targetJar) < newTarget) then
- rs.setOutput(valveSide, false)
- complete = false
- end
- end
- elseif (buffFill == 8) then
- rs.setOutput(bellowSide, true)
- end
- if ((buffFill >= (newTarget - getFill(targetJar)) - 2) and (buffFill > 0)) then
- rs.setOutput(bellowSide, true)
- complete = true
- rs.setOutput(valveSide, true)
- end
- end
- rs.setOutput(trSide, true)
- while (getFill(jar) < target) do
- end
- sleep(1)
- rs.setOutput(trSide, false)
- while (getFill(targetJar) <= newTarget) do
- push1(ess)
- print("Pushing last essentia")
- end
- end
- function push1(ess)
- jar = peripheral.wrap(voidType .. "_" .. source[ess])
- targetJar = peripheral.wrap(jarType .. "_" .. outID)
- if (targetJar == nil) then
- targetJar = peripheral.wrap(voidType .. "_" .. outID)
- end
- initAmount = getFill(jar)
- initTarget = getFill(targetJar)
- trans.setFreq(offset + source[ess])
- rs.setOutput(bellowSide, false)
- rs.setOutput(valveSide, false)
- while (getFill(jar) >= initAmount) do
- rs.setOutput(trSide, true)
- sleep(0.25)
- rs.setOutput(trSide, false)
- sleep(0.25)
- end
- while (getFill(buff) == 0) do
- end
- rs.setOutput(bellowSide, true)
- while (getFill(targetJar) == initTarget) do
- end
- rs.setOutput(valveSide, true)
- end
- mapJars()
- rs.setOutput(trSide, false)
- rs.setOutput(valveSide, false)
- rs.setOutput(bellowSide, true)
- while true do
- id, msg = rednet.receive()
- if (id == cntID) then
- t = textutils.unserialize(msg)
- if (t.amount > 1) then
- push(t.ess, t.amount)
- else
- push1(t.ess)
- end
- rednet.send(cntID, "OK")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment