DoNothing .java

net.minecraft.world.entity.ai.behavior.DoNothing (class): members: endTimestamp, maxDuration, minDuration, getRequiredMemories, debugString, tickOrStop.

net.minecraft.world.entity.ai.behaviorclass54 linescommon1.5 KB

Implements

API Surface (6)

Behavior.Status getStatus()
Set<MemoryModuleType<?>> getRequiredMemories()
boolean tryStart(final ServerLevel level, final LivingEntity body, final long timestamp)
void tickOrStop(final ServerLevel level, final LivingEntity body, final long timestamp)
void doStop(final ServerLevel level, final LivingEntity body, final long timestamp)
String debugString()

Fields & Constants (4)

minDuration
maxDuration
status
endTimestamp

Code Graph: Dependencies (5)

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

Full Source

DoNothing.java54 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.behavior;
2
3
import java.util.Set;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.world.entity.LivingEntity;
6
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
7
8
public class DoNothing implements BehaviorControl<LivingEntity> {
9
	private final int minDuration;
10
	private final int maxDuration;
11
	private Behavior.Status status = Behavior.Status.STOPPED;
12
	private long endTimestamp;
13
14
	public DoNothing(final int minDuration, final int maxDuration) {
15
		this.minDuration = minDuration;
16
		this.maxDuration = maxDuration;
17
	}
18
19
	@Override
20
	public Behavior.Status getStatus() {
21
		return this.status;
22
	}
23
24
	@Override
25
	public Set<MemoryModuleType<?>> getRequiredMemories() {
26
		return Set.of();
27
	}
28
29
	@Override
30
	public final boolean tryStart(final ServerLevel level, final LivingEntity body, final long timestamp) {
31
		this.status = Behavior.Status.RUNNING;
32
		int duration = this.minDuration + level.getRandom().nextInt(this.maxDuration + 1 - this.minDuration);
33
		this.endTimestamp = timestamp + duration;
34
		return true;
35
	}
36
37
	@Override
38
	public final void tickOrStop(final ServerLevel level, final LivingEntity body, final long timestamp) {
39
		if (timestamp > this.endTimestamp) {
40
			this.doStop(level, body, timestamp);
41
		}
42
	}
43
44
	@Override
45
	public final void doStop(final ServerLevel level, final LivingEntity body, final long timestamp) {
46
		this.status = Behavior.Status.STOPPED;
47
	}
48
49
	@Override
50
	public String debugString() {
51
		return this.getClass().getSimpleName();
52
	}
53
}
54

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