Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local jarPeripheral=nil
- function getJar()
- return peripheral.wrap("back")
- end
- function getAspect()
- if (jarPeripheral==nil) then
- jarPeripheral=getJar()
- end
- local tableAspect= jarPeripheral.getAspects()[1]
- if(tableAspect~=nil) then
- return tableAspect["name"]
- else
- return nil
- end
- end
- function getAspectAmount()
- local Aspect= getAspect()
- if( Aspect==nil) then
- return nil
- else
- return jarPeripheral.getAspectCount(Aspect)
- end
- end
- function openNetwork()
- if(rednet.isOpen("front")==false) then
- rednet.open("front")
- end
- end
- function split(str,pat)
- local t={}
- local fpat="(.-)"..pat
- local last_end=1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end=e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function canDoStorage(qty)
- if (getAspectAmount()+qty<=64) then
- return true
- else
- return false
- end
- end
- function openStorage()
- redstone.setOutput("top",true)
- end
- function closeStorage()
- redstone.setOutput("top",false)
- end
- function mkStrAspectData()
- local AspectType=getAspect()
- if (AspectType==nil) then
- return "aspectdata-untyped"
- end
- return "aspectdata-"..AspectType.."-"..getAspectAmount()
- end
- function setStartup()
- if(fs.exists("startup")==false) then
- local startupFile=fs.open("startup","w")
- startupFile.write("os.run({}, \""..shell.getRunningProgram().."\")")
- startupFile.close()
- end
- end
- function listenNetwork()
- openNetwork()
- while(true) do
- write("test")
- senderId, rawMessage, distance = rednet.receive()
- local messageTable=split(rawMessage,"-")
- --write(rawMessage)
- --write(textutils.serialize(senderId))
- if(messageTable[1]=="wherestore") then
- if(messageTable[2]==getAspect()) then
- if (canDoStorage(messageTable[3])) then
- write("Inform provider i'm avaible for this\n")
- rednet.send(senderId,"here")
- end
- end
- elseif (messageTable[1]=="store") then
- if (messageTable[2]==getAspect()) then
- write("Begin to store\n")
- openStorage()
- end
- elseif(messageTable[1]=="stop") then
- write("End to store\n")
- closeStorage()
- elseif(messageTable[1]=="howmany") then
- write("Begin to store\n")
- rednet.send(senderId, mkStrAspectData())
- end
- end
- end
- setStartup()
- listenNetwork()
- --write(getAspect())
- --write(textutils.serialize(canDoStorage(16)))
- --write(textutils.serialize(split("store-magic","-")))
- --write(textutils.serialize(getAspectAmount()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement