Entities are the dynamic movable objects in the game. Minecraft tracks every entity with a unique ID number. Whenever an entity is added to the game world, a global counter is incremented and the new entity is assigned the current value.
A large number of game objects are tracked in this way, and so creating any one of them will increment that global counter. To reiterate, this is a global counter, shared for all entities in the game.
Typically, item entities fall to the floor and sit stationary soon after being created. Processing movement for these stationary entities would be wasteful, so an optimization was added in 1.14: if an item is sitting stationary on a block, then only process movement for that item every 4th tick.
However, it would also be wasteful if every 4th tick processed all items, so instead the items are divided into four staggered groups. Each tick stationary items from only one of the four groups check for movement.
Stationary items only begin to fall when their is a multiple of .
In other words, divide the value by 4 and look at the remainder. If the remainder is 0, the item checks for movement. That condition is written as ... % 4 == 0 in Java and as in math.
You can freely add or subtract multiples of 4 to any expression without changing the value . For example, because .
The optimization is implemented as follows:
onGround is only ever updated via move, and this branch is the only place that ItemEntity.move is called. tickCount is the item’s age.
public class ItemEntity extends Entity {
public void tick() {
...
if (this.onGround() && !(this.getDeltaMovement().horizontalDistanceSqr() > (double)1.0E-5F) && (this.tickCount + this.getId()) % 4 != 0) {
...
} else {
this.move(MoverType.SELF, this.getDeltaMovement());
...
}
...
}
}
public class Entity {
public void move(final MoverType moverType, Vec3 delta) {
...
this.setOnGroundWithMovement(this.verticalCollisionBelow, this.horizontalCollision, movement);
...
}
public void setOnGroundWithMovement(final boolean onGround, final boolean horizontalCollision, final Vec3 movement) {
this.onGround = onGround;
...
}
}The effect is that if the item is on a block and has negligible horizontal momentum, it cannot fall until the condition is satisfied, even if it’s no longer on the ground. It can only fall early if it gains horizontal momentum or is pushed.
We can’t control the absolute entity ID a particular item will receive, but we can compare ids of multiple entities. By observing the drop delay for a “reference” item, we can predict the behavior of other items.