24,162 ARTICLES
ON THIS WIKI

Interactive Sorter

Interactive Sorter
Interactive Sorter

Name Interactive Sorter
Source Mod Misc Peripherals
ID Name Unknown
Type Block
Stackable Yes (64)
Solid Yes
Transparent No
Affected by Gravity No
Emits Light No
Flammable No
Required Tool Wooden Pickaxe

The Interactive Sorter is a block added by the Misc Peripherals mod.

It used as a part of a storage/ routing system for items. As a ComputerCraft peripheral, it must be "wrapped" to a Computer which uses one of the six sides, leaving five sides with which to sort. If an item enters through one side and exits through a different side, this allows for routing to four different directions, acting in a way not dissimilar to a Diamond Transport Pipe (BuildCraft) or Sorting Machine (Redpower) except without a limit to the amount of items it can sort.

Recipe[edit]

GUI Crafting Table.png
Diamond
Piston
Diamond
Piston
Eye of Ender
Piston
Diamond
Piston
Diamond
Interactive Sorter

Application[edit]

Use with a Computer wrapped as a peripheral. The Interactive Sorter doesn't work on its own; it must be controlled by a Computer or Turtle. This is done with Lua scripts that utilise the following methods:

  • list(int direction)
  • sort(int direction)
  • extract(int from, int uuid, int to, int amount)

Setting Up[edit]

To use the Interactive Sorter it must first be "wrapped" to a Computer. This is done with the function peripheral.wrap(str direction). Example:

sorter = peripheral.wrap("left")

The sorter's functions can then be called using sorter.function().

This page will use the convention of wrapping the Interactive Sorter to the variable "sorter" for clarity, however, it should be noted that any variable name can be chosen.

UUIDs[edit]

UUIDs are integers used to express a block or item's ID and metadata as one value. As of v3.0, UUIDs are expressed as the item ID + (meta * 32768). UUIDs are returned by the Interactive Sorter's internal functions.

UUIDs changed from v2.3 to v3.0. This page will show how to use UUIDs of both types.

Example: Interactive Sorter's ID is 1229:5 so its UUID would be 1229 + (5 * 32768) = 165069

Sorter API by NeverCast (v2.3 only)[edit]

In v2.3 when the Interactive Sorter handles IDs it does not use the actual ID, rather it applies some bitwise operations and returns a UUID. This means that an item ID cannot be recognised on sight and must first be decoded. An API has been written by user NeverCast from the Computercraft Forums that does this.

It supplies the following functions:

  • getID(id, meta): converts actual ID and metadata to UUID
  • getStack(uuid, amount): converts UUID to ID and metadata
  • getStacks(direction, invDirection): returns a table containing a list of each item stack in an adjacent inventory in the form of ID, meta and amount.

As with any API, it can be loaded with os.loadAPI(pathToAPI).

External Links

Sorter API revised for v3.0+ (edited)[edit]

function getUUID(id, meta)

  local uuid = bit.bor(bit.blshift(meta,0xf),id) -- leftshifts "meta" by 15 bits and concatenates with "id" by bitwise or
  return uuid
end
function getID(uuid)
  local id = bit.band(uuid,0x7fff) -- extracts the 15 lower bits by bitwise and
  local meta = bit.blogic_rshift(uuid,0xf) -- truncates the 15 lower bits by rightshifting
  return id, meta
end
function getStacks(direction, invDirection)

  -- check if a peripheral is present
  if not peripheral.isPresent(direction) then
    return false, "no peripheral present"
  end

  -- check if the peripheral is a sorter
  if peripheral.getType(direction) ~= "interactiveSorter" then
    return false, "peripheral is not a sorter"
  end

  local sorter = peripheral.wrap(direction) -- one could also use call to access "list" (this wouldn't require wrapping)
  -- one last check, just to be sure
  if sorter == nil then
    return false,"unknown error - could not wrap peripheral"
  end
  local stacks = {}
  for uuid,count in pairs(sorter.list(invDirection))
    table.insert(stacks,getID(uuid))
  end

  --[[ invDirection can be deceiving. In this case it has to be a numeric value!
  Use a lookup table for use with other representations. Exp.: "directions[InvDirection]" --]]

  return true, stacks
end
External Links

edited by JateZero

Event: isort_item[edit]

A Computer can wait until an item enters the Interactive Sorter's inventory and return the UUID and amount to the computer. This is especially useful for item routing as the os.pullEvent(event) function waits until the specified event and returns information to variables when the event occurs. The computer can then execute other functions using the new data.

Usage: event, param, amount = os.pullEvent("isort_item") where param is the UUID and amount is the stack size.

List[edit]

List displays the contents of the inventory in the specified direction in a table. The table contains the UUID and amount of items for each stack (of any amount). The UUID can be decoded into ID and metadata using bitwise operations in v2.3 however the official forum post states that v3.1 will do away with that and provide the real ID.

List is useful for when one wishes to know what is in an inventory in order to extract from it.

Usage: list(direction) where direction can be the following integer values:

Integer Direction
0 Down
1 Up
2 North (-Z)
3 South (+Z)
4 West (-X)
5 East (+X)

Example (v3.0+):

 os.loadAPI("sorterAPI")
 local stacks = {}
 for uuid,count in pairs(sorter.list(1)) do
   table.insert(stacks, sorterAPI.getID(uuid))
 end

Example (v2.3):

 os.loadAPI("sorterAPI")
 local stacks = {}
 for uuid,count in pairs(sorter.list(1)) do
   table.insert(stacks, sorterAPI.getStack(uuid, amount))
 end

Sort[edit]

Sort ejects a stack from the Interactive Sorter's single slot inventory to a given direction.

Usage: sort(direction) where direction can be the same integer values as above.

Example:

 event, param, amount = os.pullEvent("isort_item")
 itemName = itemNameTable[param]
 if itemName == "stone" then
   sorter.sort(3)
 else
   sorter.sort(1)
 end

Extract[edit]

Extract pulls a stack from an inventory in a specified direction and ejects to a specified direction. The ID and amount (up to a stack) of the item must be specified as well as each direction (which can be identical).

Usage: sorter.extract(from,uuid,to,amount) where from and to can be the same integer values as above, uuid must refer to an item that exists in the inventory and amount can be any value up to 64 (due to only having one inventory slot) but only as many as the stack size will be pulled.

Example (v3.0+):

 os.loadAPI("sorterAPI")
 tArgs = { ... }
 itemID, meta, amount, direction = tArgs[1], tArgs[2], tArgs[3], tArgs[4]
 uuid = sorterAPI.getUUID(itemID, meta)
 sorter.extract(0,uuid,direction,amount)

Example (v2.3):

 os.loadAPI("sorterAPI")
 tArgs = { ... }
 itemID, meta, amount, direction = tArgs[1], tArgs[2], tArgs[3], tArgs[4]
 uuid = sorterAPI.getID(itemID, meta)
 sorter.extract(0,uuid,direction,amount)

Usage[edit]

Interactive Sorter can be used to create the following items:

Known Bugs[edit]

When injecting into an adjacent inventory, if the item stack being injected to the inventory is the same item as a stack within the inventory the old stack will be overwritten rather than added to (v2.3). This can be worked around by placing a pipe between the sorter and the inventory. Any Transport Pipe (BuildCraft) will do.

See Also[edit]

The following items may also be of interest:

Videos[edit]