!c
iron,diamond,iron,red_doped_wafer,sorting_machine,red_doped_wafer,iron,ribbon_cable,iron=sortron;

Overview

The sortron is a Redbus slave device that provides the ability to interact with inventories (such as chests and machines, including sided inventories) and tube networks. A sortron must be placed in the world and attached to a computer, either by placing it adjacent to the computer or by connecting the two with ribbon cable.

A sortron has two “business ends”. The face with the small hole is its output. The output can be connected to a tube network which will receive processed items; alternatively, it can be left open in which case processed items will be dropped into the world as collectible item stacks. The face with the large hole is the sortron’s input. The input can be connected to a tube network (the “inline configuration”) or to an inventory (the “pulling configuration”).

Sortrons require power to operate and therefore must be connected via blue alloy wire to a power source and/or battery box. Only the [Pull] and [Match] commands actually consume power, but the sortron must have sufficient voltage available in order to do anything.

Identifying items

Sortrons, being in the business of sorting items, need a way to identify a particular type of item (e.g. “dirt”, “cobblestone”, “compass”, or “Blulectric alloy furnace”). Instead of using familiar item numbers, which could differ between servers or between different single player installations due to configuration files, the sortron uses opaque 32-bit IDs, which according to Direwolf20’s sortron video is some sort of hash intended to remain constant even across servers with different configurations. Any reference to “item ID” in this page refers to these 32-bit hashes.

Redbus interface

A newly-placed sortron has Redbus slave ID 4; this can be changed by shift+right-clicking the sortron with a screwdriver in hand.

The sortron exposes the following memory locations over Redbus:
Offset
Length
Function
0x00
1
Command
0x01
1
Quantity
0x02
2
Slot
0x04
4
Item ID
0x08
2
Damage
0x0A
2
Max damage
0x0C
1
Output colour
0x0D
1
Input colour
To use the sortron, software first fills in any necessary parameters then writes the command number for the desired operation into [Command]. Sortron commands do not execute immediately; once a command has finished executing, the sortron changes the [Command] register to 0x00 if the command was successful or 0xFF if it failed. If insufficient power is available to execute a command, [Command] will hold its original value until power becomes available, at which time the command will execute. Software can cancel a command that has not yet executed by writing 0x00 into [Command]; it can also change the parameters of an in-progress command by writing to the relevant other registers.

The sortron understands four commands, detailed below:
Command
Function
0x01
Read inventory size
0x02
Read inventory slot
0x03
Pull
0x04
Match
The [Output colour] and [Input colour] registers both refer to item painting in a tube network, the same as done by filters and sorting machines—each item stack moving through a tube network can be either unpainted or painted a specific colour, and tubes can be painted to restrict which items pass through them. The legal values for both of these registers are as follows:
Value
Colour
0
Unpainted
1
White
2
Orange
3
Magenta
4
Light blue
5
Yellow
6
Lime
7
Pink
8
Grey
9
Light grey
10
Cyan
11
Purple
12
Blue
13
Brown
14
Green
15
Red
16
Black

Read inventory size

This command reads the number of slots in the inventory of a pulling sortron and stores the result into [Slot]. This command fails if the sortron is inline.

Read inventory slot

This command reads information about the item stack in slot [Slot] (zero-based) of the attached inventory. The number of items is stored into [Quantity], the type of item is stored into [Item ID], the item’s damage value is stored into [Damage], and the maximum possible damage value for the item is stored into [Max damage]. This command fails if the sortron is inline or if the slot number in [Slot] is greater than or equal to the number of slots in the inventory.

Pull

This command extracts items from the attached inventory. The items are extracted from slot [Slot]. The number of items extracted is the lesser of [Quantity] or the size of the item stack in slot [Slot]. [Output colour] selects how the extracted item stack is painted. The stack is then injected into the tube network on the output side of the sortron (or dropped on the floor, if no tube network is attached). Finally, [Quantity] is set to the number of items actually pulled (which might be less than its original value if the item stack in the slot was smaller than the requested quantity). If the sortron is backstuffed when software attempts to execute this command, [Command] will hold its value until the backstuff clears and then the command will execute (unless aborted). This command fails if the sortron is inline or if the slot number in [Slot] is greater than or equal to the number of slots in the inventory.

Match

This command allows items to pass an inline sortron from the input tube network to the output tube network. If [Item ID] is nonzero, the sortron becomes a valid destination for only that specific type of item; if zero, it becomes a valid destination for all item types. If [Input colour] is nonzero, the sortron is a valid destination for only items painted that specific colour; if zero, the sortron is a valid destination for items painted any colour and for unpainted items. As items pass through the sortron, [Output colour] selects how the extracted item stack is painted (if a stack enters the sortron painted, the paint will be removed if [Output colour] is zero). Only a maximum of [Quantity] items (individual items, not stacks) will be allowed to pass through the sortron. These may be from multiple item stacks, or even from different types of items, but the sortron will never pass more than the requested quantity—if a single stack arrives which exceeds the requested quantity, the requested number of items will pass and the remainder will bounce back into the input network. While this command executes, [Quantity] will decrease as item stacks enter the sortron (not when they leave—should backstuffing occur, this difference may be important); when [Quantity] reaches zero, [Command] will become 0x00 indicating that the operation is complete, and the sortron will stop being a valid destination. Interestingly, output backstuffing never stops the input accepting items: the only reasons why a sortron may stop being a valid destination for items are that no [Match] command is executing or that there is not enough power available.