DrFair

lister

Jan 24th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. itemname = "Cobble"
  2. dir = "+Y"
  3.  
  4. 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}
  5. directions.south = directions["+Z"]
  6. directions.east = directions["+X"]
  7. directions.north = directions["-Z"]
  8. directions.west = directions["-X"]
  9.  
  10. function getID(id, meta)
  11. if meta == nil then
  12. meta = 27268
  13. else
  14. meta = bit.bxor(meta, 0x6E6C)
  15. end
  16. local uuid = bit.bxor(id, 0x4F89) * 0x8000 + bit.bxor(meta, 0x3A69)
  17. return uuid
  18. end
  19.  
  20. function getStack(uuid, c)
  21. -- Reverse RG's fancy math
  22. local subt = bit.band(uuid, 0xffff)
  23. local dexorm = bit.bxor(subt, 0x3a69)
  24. local metadata = nil
  25. if dexorm ~= 28262 then -- item takes dmg
  26. metadata = bit.bxor(dexorm, 0x6e6c)
  27. end
  28. local id = bit.bxor((uuid-subt)/0x8000, 0x4f89)
  29. -- put it in to a nice table
  30. local stack = {}
  31. stack.amount = c
  32. stack.id = id
  33. stack.meta = metadata
  34. return stack
  35. end
  36.  
  37. function getStacks(direction, invDirection)
  38. if not peripheral.isPresent(direction) then
  39. return false, "No Peripheral"
  40. end
  41. if peripheral.getType(direction) ~= "interactiveSorter" then
  42. return false, "Not a sorter"
  43. end
  44. local stacks = {}
  45. for uuid,count in pairs(peripheral.call(direction, "list", directions[invDirection])) do
  46. table.insert(stacks, getStack(uuid, count))
  47. end
  48. return true, stacks
  49. end
  50.  
  51. rednet.open("right")
  52.  
  53. while true do
  54. s,inv = getStacks("back",dir)
  55. if #inv > 0 then
  56. item = { [1]=itemname, [2]=inv[1].amount }
  57. text = textutils.serialize(item)
  58. rednet.broadcast(text)
  59. else
  60. item = { [1]=itemname, [2]=0 }
  61. text = textutils.serialize(item)
  62. rednet.broadcast(text)
  63. end
  64. os.sleep(10)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment