Guest User

NeverCast's MiscPeriph API

a guest
Jan 8th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. -- Code by NeverCast
  2. 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}
  3. directions.south = directions["+Z"]
  4. directions.east = directions["+X"]
  5. directions.north = directions["-Z"]
  6. directions.west = directions["-X"]
  7.  
  8. function getStack(uuid, c)
  9.     -- Reverse RG's fancy math
  10.     subt = bit.band(uuid, 0xffff)
  11.     dexorm = bit.bxor(subt, 0x3a69)
  12.     metadata = nil
  13.     if dexorm ~= 28262 then -- item takes dmg
  14.         metadata = bit.bxor(dexorm, 0x6e6c)
  15.     end
  16.     id = bit.bxor((uuid-subt)/0x8000, 0x4f89)
  17.     -- put it in to a nice table
  18.     stack = {}
  19.     stack.amount = c
  20.     stack.id = id
  21.     stack.meta = metadata
  22.     return stack
  23. end
  24.  
  25. function getStacks(direction, invDirection)
  26.     if not peripheral.isPresent(direction) then
  27.         return false, "No Peripheral"
  28.     end
  29.     if peripheral.getType(direction) ~= "interactiveSorter" then
  30.         return false, "Not a sorter"
  31.     end
  32.     local stacks = {}
  33.     for uuid,count in pairs(peripheral.call(direction, "list", directions[invDirection])) do
  34.         table.insert(stacks, getStack(uuid, count))
  35.     end
  36.     return stacks  
  37. end
Advertisement
Add Comment
Please, Sign In to add comment