Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local storage
- local sideredcable
- local sidemodem
- function createsettings()
- local settings={}
- print("Number of Storage:")
- settings[1]="s"..read()
- print("Side of Modem:")
- settings[2]=read()
- print("Side of RedCable:")
- settings[3]=read()
- save(settings,"settings.txt")
- end
- function loadsettings()
- local settings=load("settings.txt")
- storage=settings[1]
- sidemodem=settings[2]
- sideredcable=settings[3]
- end
- function save(table,name)
- local file = fs.open(name,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function load(name)
- local file = fs.open(name,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function exist(name)
- file=io.open(name)
- if file~=nil then io.close(file) return true else return false end
- end
- function loadwork()
- local work=load("work")
- local w=peripheral.wrap(sideredcable)
- local names = w.getNamesRemote()
- table.sort(names)
- local z=0
- while z~=#work do
- local craftable=false
- local recipe=load(work[z+1])
- repeat
- for x=1,9 do
- craftable=false
- local cur=0
- for c=1,#names do
- local f=peripheral.wrap(names[c])
- for b=1, f.getInventorySize() do
- if f.getStackInSlot(b)~= nil then
- if f.getStackInSlot(b).display_name==recipe[x*2] then
- cur=cur+f.getStackInSlot(b).qty
- end
- end
- end
- end
- if cur>=recipe[x*2+1] then
- craftable=true
- end
- if recipe[x*2]==" " then
- craftable=true
- end
- if not craftable then break end
- end
- if craftable then
- for x=1,9 do
- local done=false
- local togo=recipe[x*2+1]
- for c=1,#names do
- sleep(0)
- local f=peripheral.wrap(names[c])
- for b=1, f.getInventorySize() do
- if f.getStackInSlot(b)~= nil then
- if f.getStackInSlot(b).display_name==recipe[x*2] then
- local num=f.getStackInSlot(b).qty
- if num>=togo then
- local n=x
- if n>=4 then
- n=n+1
- end
- if n>=8 then
- n=n+1
- end
- if c==1 then
- f.pushItem("north",b,togo,n)
- end
- if c==2 then
- f.pushItem("east",b,togo,n)
- end
- if c==3 then
- f.pushItem("south",b,togo,n)
- end
- if c==4 then
- f.pushItem("west",b,togo,n)
- end
- done=true
- else
- local n=x
- if n>=4 then
- n=n+1
- end
- if n>=8 then
- n=n+1
- end
- if c==1 then
- f.pushItem("north",b,num,n)
- end
- if c==2 then
- f.pushItem("east",b,num,n)
- end
- if c==3 then
- f.pushItem("south",b,num,n)
- end
- if c==4 then
- f.pushItem("west",b,num,n)
- end
- togo=togo-num
- end
- end
- end
- if done then break end
- end
- if done then break end
- end
- end
- redstone.setOutput("bottom",true)
- work[z+2]=work[z+2]-recipe[1]
- if work[z+2]<=0 then
- local newwork={}
- for v=1,#work do
- if v~=z+1 and v~=z+2 then
- newwork[#nework+1]=work[v]
- end
- end
- work=newwork
- end
- redstone.setOutput("bottom",false)
- save(work,"work")
- work=load("work")
- end
- until craftable==false
- end
- end
- -----------------------------
- if not exist("settings.txt") then
- createsettings()
- end
- if not exist("work") then
- local work={}
- save(work,"work")
- end
- loadsettings()
- rednet.open(sidemodem)
- while true do
- local id, mens, protocol =rednet.receive(5)
- if protocol =="Crafter"..storage then
- local work={}
- if exist("work") then
- changes=load("work")
- end
- local newwork=textutils.unserialize(mens)
- if work[1]==nil then
- work[1]=newwork[1]
- else
- work[#work+1]=newwork[1]
- end
- work[#work+1]=newwork[2]
- save(work,"work")
- rednet.send(id,"ok","confirmCrafter"..storage)
- end
- if protocol~=nil then
- if (string.sub(protocol,1,9)..storage)==("newRecCra"..storage) then
- local file = fs.open( (string.sub(protocol,1+string.len((string.sub(protocol,1,9)..storage)),string.len(protocol))),"w")
- file.write(mens)
- file.close()
- rednet.send(id,"ok","confirmNewRecipe"..storage)
- end
- if protocol==("DelRecCra"..storage) then
- if exist(mens) then
- fs.delete(mens)
- end
- rednet.broadcast("ok","confirmDeleteRecipe"..storage)
- end
- end
- loadwork()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement