My first Sortron program

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

PhilHibbs

Forum Addict
Trusted User
Jan 15, 2013
3,174
1,128
183
Birmingham, United Kingdom
OK here it is, my first foray into Sortron programming!

I have a fairly basic Ender Chest sorting system, but the difference from most set ups is I have no default route. Anything not specifically programmed into the Sorting Machines stays in the chest. The main reason for this is I wanted maximum possible item bandwidth on the chest, so I put 6 Sorting Machines all branching off the same chest in all 6 directions. I thought that it would also mean that all my machines are close together and so would be easier to program, but it turns out I get confused which machine is which and also I have destinations split across multiple machines so I have to hunt around for the right one. Oh well I'm stuck with it now.

One of the benefits of the slightly odd set up is that I can use the pouch as extra storage space on the go, and I can still get at the stuff in it.

So, the purpose of the first Sortron program is to flush unassigned content from the Ender Chest. Not everything, because like I said I keep stuff in it that I want to access. Also there is stuff in transit like Iron Dust, Compressed Coal Balls, etc. that I don't want to flush.

Here's the word, for the benefit of anyone who wants to try to work out what it does:
Code:
0 SORTSLOTS 1 - ?DO
I SORTSLOT@
DUP
0= IF LEAVE THEN
I SORTPULL
DROP DROP
-1 +LOOP ;

I defined a word "flush" for this. What it does is it loops round from the last slot down to 0, checks the item count in the slot, if it's 0 then it stops, otherwise it pulls the items out. Lets break it down:

0 This is the end-of-loop value
SORTSLOTS 1 - Start the loop at the number of slots minus one - so a 27-slot Ender Chest starts at 26. Forth starts counting things at zero, as do all low level languages.
?DO This begins a loop, testing if the start and end values are the same at the start, just in case SORTSLOTS returned 0.
I SORTSLOT@ Get the item count the slot - I is the loop counter variable.
DUP I need the count twice - once to test, and once to drive the SORTPULL command
0= IF LEAVE THEN If the slot is empty, then stop
I SORTPULL Pull Slot I, the item count will still be on the stack from the DUP
DROP DROP I don't care what funky numbers describing the items were
-1 +LOOP Decrease the loop counter by 1
; End the WORD definition

I just realised in writing this that the 0 end-of-loop value is non-inclusive, it will not check Slot 0, I should be ending the loop at -1. Oh well, it's intended to flush a number of items at the back end of the Ender Chest in order to avoid in-transit items, so this isn't a big deal.

So if I want to clear some stuff out of the Ender Chest on the go, I stack it up at the bottom-right of the chest, and run this program.

How do I run this program on the go? Well, that's the next step. I have a Wireless Remote (Chickenbones Edition), which I will be hooking up to some Bundled Cable on an IO Expander, and when the computer detects a signal on the relevant wire, it will run this command. So I shift-right-click on the remote, select the "Flush" frequency, and hit the button. Whoosh, gone.

The next step after that is automatic processing. The loot gets flushed into a different Ender Chest, which will also be connected to a Sortron, and from there it can be flushed into my processing system. I will have frequencies for "Macerate", "Recycle", "Furnace", "Package", etc., and probably "Sort" which will send the results into the sorting system. So if I'm out adventuring and I want to cook up some refined iron, then I stick the iron in the processing pouch, hit "Furnace", and wait for the refined iron to appear back in the pouch. It's going to be awexome.

The problem I have at the moment is I can't set Bus IDs on Sortrons so I will need a separate computer to run the processing unless I can get shift-right-click fixed. Also since all my processed goods at the moment go back into the sorting system, my refined iron will end up in my ingots chest and not in the processing pouch so I need to set up a separate set of machines for the on-the-go processing.