Files
wireless-docs/content/01-core.typ
2026-06-20 01:13:14 -04:00

70 lines
2.5 KiB
Typst

#import "/lib.typ": note, tip, todo
= Core Mechanics
== Entity IDs
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*.
== Stationary Item Optimization
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 check for gravity every 4 ticks.
Here is the relevant code path for the optimization.
#note[ `onGround` is only ever updated from `move()`, and this branch is the *only* place that
`move()` is called. ]
```java
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;
...
}
}
```
== Observable Drop Delay
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 fall early if
it gains horizontal momentum or is pushed.
#tip[ You can rewrite the condition as `(age % 4 == (-id) % 4)` ]
#todo[ An animation. Spawn a few items, note their ID and age. Let them settle on a block,
then remove that supporting block. There will be a few ticks where the item hovers in place before
it falls. ]
For simplicity, suppose we spawn all our items on the same tick. Then `this.tickCount` will be the
same for all of them, and we only need to consider the ID.
The result of this is that if you spawn several item entities, allow them to settle on a block, then
remove that block