Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require("component")
- local r = require("robot")
- local s = require("sides")
- local serialization=require('serialization')
- local event=require("event")
- local m = cmp.tunnel
- local m1=cmp.modem
- loc ={["x"]=0,["y"]=0,["z"]=0}
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
- function d()
- r.turnAround()
- for i=1,64 do
- r.select(i)
- r.drop()
- end
- r.select(1)
- r.turnAround()
- end
- function suckItem()
- if a==4096 then a=math.floor(a/64) for i=1,a do r.suck() end
- elseif a>64 and a<4096 then a1=math.floor(a/64) a2=a/64
- if a2>a1 then a3=a-a1*64 for i=1,a1 do r.suck() end r.suck(a3) end
- elseif a==64 or a<64 then r.suck(a) end
- for i=1,3 do
- ch()
- end
- end
- function ch()
- amo1=0
- for i=1,64 do
- r.select(i) amo=r.count()
- amo1=amo1+amo
- end
- if amo1<a then amo2=a-amo1
- if amo2 >64 then amo3=math.floor(amo2/64) amo4=amo2/64
- if amo4>amo3 then amo5=amo2-amo3*64 for i=1,amo3 do r.suck() end r.suck(amo5) end
- end end
- end
- function goToHome() r.turnLeft()
- if loc["z"] > 0 then for i=1,loc["z"] do r.down() end elseif loc["z"]<0 then loc["z"]=loc["z"]*-1 for i=1,loc["z"] do r.up() end end
- if loc["y"] > 0 then for i=1,loc["y"] do r.forward() end end r.turnLeft()
- if loc["x"] > 0 then for i=1,loc["x"] do r.forward() end end r.turnAround()
- loc["z"]=0 loc["y"]=0 loc["x"]=0
- end
- function goTo(arr) x=loc["x"]-arr["x"] y=loc["y"]-arr["y"] z=loc["z"]-arr["z"]
- if x < 0 then x=x*-1 for i=1,x do r.forward() loc["x"]=loc["x"]+1 end elseif x> 0 then for i=1,x do loc["x"]=loc["x"]-1 r.back() end end r.turnRight()
- if y < 0 then y=y*-1 for i=1,y do r.forward() loc["y"]=loc["y"]+1 end elseif y > 0 then for i=1,y do loc["y"]=loc["y"]-1 r.back() end end
- if z < 0 then z=z*-1 for i=1,z do r.up() loc["z"]=loc["z"]+1 end elseif z > 0 then for i=1,z do loc["z"]=loc["z"]-1 r.down() end end r.turnLeft()
- end
- function ItoP()
- while true do
- key,_,address,port,_,message = event.pull()
- if key=="modem_message" then
- a=string.sub(message,1,4) a=tonumber(a)
- b=string.sub(message,5)
- f=loadTbl('/chests/'..b..'.txt')
- goTo(f)
- suckItem()
- m1.send("e51089c7-42c7-465b-9791-ccd8758480ea",1,"check")
- goToHome()
- d()
- end
- end
- end
- ItoP()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement