Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local r = require("robot")
- local s = require("sides")
- local serialization=require('serialization')
- loc ={["x"]=0,["y"]=0,["z"]=0}
- is=com.inventory_controller
- 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 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()
- end
- function goToChest(arr,slot)
- 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.forward() 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()
- r.select(slot)
- end
- function scan()
- for i=1, 64 do
- r.select(i)
- r.suckUp()
- end
- for i=1,64 do
- scans = is.getStackInInternalSlot(i)
- if scans~=nil then
- a = scans["label"]
- a=string.gsub(a,' ','_')
- f=loadTbl('/chests/'..a..'.txt')
- goToChest(f,i)
- r.drop()
- end
- end
- end
- scan()
- goToHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement