lost_RD

MiscPeripherals UUID Reader for v3.0+

Mar 19th, 2013
742
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ Original code by NeverCast, revised for v3.0 by lost_RD
  2.      This should be loaded like a typical api
  3.      Feel free to name it what you like
  4.      This paste created for http://ftbwiki.org/Interactive_Sorter
  5. --]]
  6. local directions = { [0]=0,[1]=1,[2]=2,[3]=3,[4]=4,[5]=5,["down"] = 0, ["up"] = 1, ["-Z"] = 2, ["+Z"] = 3, ["-X"] = 4, ["+X"] = 5, ["+Y"] = 1, ["-Y"] = 0}
  7. directions.south = directions["+Z"]
  8. directions.east = directions["+X"]
  9. directions.north = directions["-Z"]
  10. directions.west = directions["-X"]
  11.  
  12. -- Gets the Unique ID based on the ID and Meta
  13. function getUUID(id, meta)
  14.   uuid = id + meta * 32768
  15.   return uuid
  16. end
  17.  
  18. -- Get a stack table from a single uuid and amount
  19. -- Valid for version 3.0
  20. function getID(uuid)
  21.   id = uuid
  22.   meta = 0
  23.   if uuid > 32768 then
  24.     meta = uuid%32768
  25.     id = id - (meta * 32768)
  26.   end
  27. end
  28.  
  29. -- Get stacks from an Interactive Sorter
  30. -- direction   : the direction of the Interactive Sorter Peripheral
  31. -- invDirection: the direction of the inventory from the peripheral
  32. -- valid options for invDirection are 0,1,2,3,4,5 ( original values),
  33. -- north, south, east, west, up, down, and the +/-X,Y,Z strings.
  34. -- (see directions variable)
  35. function getStacks(direction, invDirection)
  36.   if not peripheral.isPresent(direction) then
  37.     return false, "No Peripheral"
  38.   end
  39.   if peripheral.getType(direction) ~= "interactiveSorter" then
  40.     return false, "Not a sorter"
  41.   end
  42.   local stacks = {}
  43.   for uuid,count in pairs(peripheral.call(direction, "list", directions[invDirection])) do
  44.     table.insert(stacks, getStack(uuid))
  45.   end
  46.   return true, stacks
  47. end
RAW Paste Data