EntityTickList .java

net.minecraft.world.level.entity.EntityTickList (class, 60 lines): members: iterated, passive, active, forEach, contains, remove, add. imports: Entry.

net.minecraft.world.level.entityclass60 linescommon1.6 KB

API Surface (4)

void add(final Entity entity)
void remove(final Entity entity)
boolean contains(final Entity entity)
void forEach(final Consumer<Entity> output)

Fields & Constants (3)

active
passive
iterated

String literals (1)

"Only one concurrent iteration supported"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EntityTickList.java60 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.entity;
2
3
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
4
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
5
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
6
import it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry;
7
import java.util.function.Consumer;
8
import net.minecraft.world.entity.Entity;
9
import org.jspecify.annotations.Nullable;
10
11
public class EntityTickList {
12
	private Int2ObjectMap<Entity> active = new Int2ObjectLinkedOpenHashMap<>();
13
	private Int2ObjectMap<Entity> passive = new Int2ObjectLinkedOpenHashMap<>();
14
	private @Nullable Int2ObjectMap<Entity> iterated;
15
16
	private void ensureActiveIsNotIterated() {
17
		if (this.iterated == this.active) {
18
			this.passive.clear();
19
20
			for (Entry<Entity> entry : Int2ObjectMaps.fastIterable(this.active)) {
21
				this.passive.put(entry.getIntKey(), entry.getValue());
22
			}
23
24
			Int2ObjectMap<Entity> tmp = this.active;
25
			this.active = this.passive;
26
			this.passive = tmp;
27
		}
28
	}
29
30
	public void add(final Entity entity) {
31
		this.ensureActiveIsNotIterated();
32
		this.active.put(entity.getId(), entity);
33
	}
34
35
	public void remove(final Entity entity) {
36
		this.ensureActiveIsNotIterated();
37
		this.active.remove(entity.getId());
38
	}
39
40
	public boolean contains(final Entity entity) {
41
		return this.active.containsKey(entity.getId());
42
	}
43
44
	public void forEach(final Consumer<Entity> output) {
45
		if (this.iterated != null) {
46
			throw new UnsupportedOperationException("Only one concurrent iteration supported");
47
		}
48
49
		this.iterated = this.active;
50
51
		try {
52
			for (Entity entity : this.active.values()) {
53
				output.accept(entity);
54
			}
55
		} finally {
56
			this.iterated = null;
57
		}
58
	}
59
}
60

Decompiled Minecraft 26.3 source of EntityTickList (net/minecraft/world/level/entity/EntityTickList.java) with Mojang official mappings, stored verbatim on the site.