Advertisement
MeXaN1cK

sorter

Mar 31st, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local com = require("component")
  2. local r = require("robot")
  3. local s = require("sides")
  4. local serialization=require('serialization')
  5. loc ={["x"]=0,["y"]=0,["z"]=0}
  6. is=com.inventory_controller
  7. local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
  8. 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
  9. function goToHome()
  10. r.turnLeft()
  11. 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
  12. if loc["y"] > 0 then for i=1,loc["y"] do r.forward() end end r.turnLeft()
  13. if loc["x"] > 0 then for i=1,loc["x"] do r.forward() end end r.turnAround()
  14. end
  15. function goToChest(arr,slot)
  16.  x=loc["x"]-arr["x"] y=loc["y"]-arr["y"]  z=loc["z"]-arr["z"]
  17.  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()
  18.  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
  19.  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()
  20.  r.select(slot)
  21. end
  22. function scan()
  23.  for i=1, 64 do
  24.  r.select(i)
  25.  r.suckUp()
  26.  end
  27.  for i=1,64 do
  28.  scans = is.getStackInInternalSlot(i)
  29.  if scans~=nil then
  30.  a = scans["label"]
  31.  a=string.gsub(a,' ','_')
  32.  f=loadTbl('/chests/'..a..'.txt')
  33.  goToChest(f,i)
  34.  r.drop()
  35.  end
  36.  end
  37. end
  38. scan()
  39. goToHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement