SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --[[ Code by NeverCast |
| 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 | - | function getID(id, meta) |
| 12 | + | |
| 13 | - | if meta == nil then |
| 13 | + | function getUUID(id, meta) |
| 14 | - | meta = 27268 |
| 14 | + | uuid = id + meta * 32768 |
| 15 | - | else |
| 15 | + | |
| 16 | - | meta = bit.bxor(meta, 0x6E6C) |
| 16 | + | |
| 17 | ||
| 18 | - | local uuid = bit.bxor(id, 0x4F89) * 0x8000 + bit.bxor(meta, 0x3A69) |
| 18 | + | |
| 19 | -- Valid for version 3.0 | |
| 20 | function getID(uuid) | |
| 21 | id = uuid | |
| 22 | meta = 0 | |
| 23 | - | -- This does all the math to reverse the unique ID algorithm that RG wrote. |
| 23 | + | if uuid > 32768 then |
| 24 | - | -- Valid for version 2.3 |
| 24 | + | meta = uuid%32768 |
| 25 | - | function getStack(uuid, c) |
| 25 | + | id = id - (meta * 32768) |
| 26 | - | -- Reverse RG's fancy math |
| 26 | + | |
| 27 | - | local subt = bit.band(uuid, 0x7fff) |
| 27 | + | |
| 28 | - | local dexorm = bit.bxor(subt, 0x3a69) |
| 28 | + | |
| 29 | - | local metadata = nil |
| 29 | + | |
| 30 | - | if dexorm ~= 28262 then -- item takes dmg |
| 30 | + | |
| 31 | - | metadata = bit.bxor(dexorm, 0x6e6c) |
| 31 | + | |
| 32 | - | end |
| 32 | + | |
| 33 | - | local id = bit.bxor((uuid-subt)/0x8000, 0x4f89) |
| 33 | + | |
| 34 | - | -- put it in to a nice table |
| 34 | + | |
| 35 | - | local stack = {}
|
| 35 | + | |
| 36 | - | stack.amount = c |
| 36 | + | if not peripheral.isPresent(direction) then |
| 37 | - | stack.id = id |
| 37 | + | return false, "No Peripheral" |
| 38 | - | stack.meta = metadata |
| 38 | + | |
| 39 | - | return stack |
| 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 |