Tutorial:Entity stack separation

Entity stack separation refers to the process of separating one or more entities out of a stack of aligned entities. It is commonly used in Ender Pearl stasis chambers, tunneling TNT cannons, item sorters, and other machines that work with entities. The concept of stack separation relies on using either the global entity ticking order or the subchunk entity collection order to allow some entities in the stack to move, then change something in the world, and then allow the rest to move differently.

Global entity ticking order

The order in which entities tick is determined by their position in the global entity ticking list. They are added to the list in the order that they begin ticking. Under most circumstances, this means entities tick in the same order they spawn.

Pressure plates & Tripwire

One common way to separate entities is to use trapdoors, doors, or fence gates together with pressure plates or tripwire. Then, allowing the stack of entities to move into the pressure plate or tripwire will cause the first entity to activate it, which opens or closes a trapdoor, door, or fence gate, and that changes what the rest of the stack will collide with.

Blocking one entity

Top: before items get pushed, they are all clumped together. Bottom: items get pushed. The first item hits the first fence gate and activates the pressure plate, allowing the rest through. The same repeats for all other fence gates. The 4 earliest items in the ticking order are separated.

For blocking one entity and allowing the rest through, fence gates are a good option. They are all closed by default. When the first entity ticks, it will hit the side of the first fence gate and then activate the pressure plate and open it. The rest of the entities can go through the open fence gate. This is particularly useful because it can be chained multiple times, which is most commonly used in high speed item sorters.

Blocking all except one entity

Top: before getting pushed, the items are all clumped together. Bottom: the first item goes through the trapdoor and activates the pressure plate, opening the trapdoor. The rest of the items are blocked by the side of the trapdoor.

For allowing one entity through and blocking the rest, trapdoors are a good option. They are all closed by default so entities fit under them. When the first entity ticks, it will go under the first trapdoor and then activate the pressure plate and close it. The rest of the entities are blocked by the trapdoor.

Blocking a specific number of entities

Although it may seem like they would work, weighted pressure plates actually don't work for entity separation purposes. They update their signal strength level in the block tick phase instead of updating it instantly when entities interact with them. To block a specific number of entities, it is necessary to use a "dummy entity".

The strategy is as follows. The dummy entity needs to be outside the stack, and needs to tick between the two groups of entities you wish to separate. Then this is the order:

  1. The first N entities in the stack tick and move in a certain way.
  2. The dummy entity activates a pressure plate or tripwire and changes the state of a trapdoor or fence gate.
  3. The remaining entities in the stack tick and move in a different way.

Other entities

Another way to separate entities is to use other entities that change the world in some way. These include:

  • All entities that create explosions (since they can both break blocks and change entity velocities)
  • All entities that can give velocity to other entities (all living entities can push other living entities)
  • All entities that can be collided against (boats, shulkers)
  • All entities that can break blocks (zombies breaking doors, endermen picking up blocks)
  • All entities that can place blocks (endermen, any entity with frost walker boots).

All these entities can be used to separate other entities by having some amount of entities in the stack tick, then modifying the world with one of these special entities, then having the rest of the stack move differently after the modification.

Boats

Since boats have a hard hitbox that other boats collide with, stacks of boats have a tendency to separate themselves. This is especially a problem if you want a stack of boats to move quickly and stay in one stack. The first boat moves past all the others, then the second boat hits the back of the first, and so on. For this reason it is not possible for a stack of boats moving further than the width of a boat each tick to stay together.

TNT explosions pushing other TNT

Explosions are shown with small cyan boxes. From top to bottom:
  1. We begin with 30 TNT in the left batch ticking first, which will give velocity to a stack of 20 TNT on the right ticking second.
  2. Left batch explodes. Now we have a stack of TNT with high velocity towards the right.
  3. First TNT hits the side of the end stone and explodes, breaking one layer of blocks.
  4. Second TNT enters the hole created by the first, breaking a second layer of blocks.
  5. After all the TNT has ticked, a complete tunnel has been made.

TNT entities always apply gravity before moving. Because of this, a stack of TNT that is in the air will tend to separate itself vertically. The first TNT entity ticks, moves down due to gravity, explodes below the stack, and accelerates the rest of the stack upwards. The second TNT entity moves up from the velocity it was given, explodes above the stack, and accelerates the rest downwards. This process continues and results in explosions at many different heights. TNT cannoning communities have called this effect "swing" because the explosions alternate between being too high and too low, "swinging" up and down.

This effect happens more generally with any moving stack of TNT. To avoid it, there are a few options:

  • Make the TNT move faster than 8 block per tick. This puts all the explosions at least 1 blast radius away from the stack of TNT.
  • Make the TNT turn a corner. Because of how entity collisions work, TNT with diagonal velocity collides in a zig-zag pattern. This allows it to go around a corner of blocks, which allows the blocks to obstruct the explosions from affecting the rest of the stack.
  • Clip a (blastproof) block into the TNT stack. TNT will be able to move out of the block and explode outside, and the block will obstruct the explosions from affecting the rest of the stack.

TNT explosions breaking blocks

One common instance of this is allowing some entities to hit the side of a block, then using TNT to break the block, which allows the rest of the entities to go past the block. In particular, the entities being separated can also be TNT entities. This allows long tunnels to be dug in one tick as the TNT separate each other into a line, and is the basis for tunneling TNT cannons.

More complex TNT cannons can use this effect to align TNT. A common pattern is to place blocks in specific places to force TNT to collide with them and move in a specific way, then break the blocks to change the trajectory of the TNT. This can be used to dig arbitrarily large 3D areas in one tick, using the "tunneling" behavior to dig many tunnels next to each other.

Subchunk entity collection order

A common strategy for separating a single ender pearl out of a stasis chamber. A piston pushes all the ender pearls out, but the first one to be pushed activates a pressure plate and blocks the rest. The one that gets separated is the first to enter the subchunk, which is not necessarily the first to be thrown.

Each subchunk keeps a list of entities that are inside it. Entities are added to this list in the order they enter the subchunk, and this is independent of their order in the global ticking list. Entities are collected in the order given by this list when the game tries to find all entities within a given space. In particular this means that moving blocks push entities in this order.

This is commonly used in ender pearl stasis chambers. If you have a stack of ender pearls, you can push it with a piston and use the strategy detailed in the Pressure plates & Tripwire section to split one ender pearl out of the stack.

Navigation