SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- Code by NeverCast |
| 1 | + | --[[ Code by NeverCast |
| 2 | This should be loaded like a typical api | |
| 3 | Feel free to name it what you like | |
| 4 | --]] | |
| 5 | 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}
| |
| 6 | directions.south = directions["+Z"] | |
| 7 | directions.east = directions["+X"] | |
| 8 | directions.north = directions["-Z"] | |
| 9 | directions.west = directions["-X"] | |
| 10 | ||
| 11 | -- Get a stack table from a single uuid and amount | |
| 12 | -- This does all the math to reverse the unique ID algorithm that RG wrote. | |
| 13 | -- Valid for version 2.3 | |
| 14 | function getStack(uuid, c) | |
| 15 | -- Reverse RG's fancy math | |
| 16 | subt = bit.band(uuid, 0xffff) | |
| 17 | dexorm = bit.bxor(subt, 0x3a69) | |
| 18 | metadata = nil | |
| 19 | if dexorm ~= 28262 then -- item takes dmg | |
| 20 | metadata = bit.bxor(dexorm, 0x6e6c) | |
| 21 | end | |
| 22 | id = bit.bxor((uuid-subt)/0x8000, 0x4f89) | |
| 23 | -- put it in to a nice table | |
| 24 | stack = {}
| |
| 25 | stack.amount = c | |
| 26 | stack.id = id | |
| 27 | stack.meta = metadata | |
| 28 | return stack | |
| 29 | end | |
| 30 | ||
| 31 | -- Get stacks from an Interactive Sorter | |
| 32 | -- direction : the direction of the Interactive Sorter Peripheral | |
| 33 | -- invDirection: the direction of the inventory from the peripheral | |
| 34 | -- valid options for invDirection are 0,1,2,3,4,5 ( original values), | |
| 35 | -- north, south, east, west, up, down, and the +/-X,Y,Z strings. | |
| 36 | - | return stacks |
| 36 | + | -- (see directions variable) |
| 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 |