CountDownCooldownTicks .java

net.minecraft.world.entity.ai.behavior.CountDownCooldownTicks (class): members: cooldownTicks, timedOut, canStillUse, stop, tick. imports: MemoryStatus.

net.minecraft.world.entity.ai.behaviorclass44 linescommonextends Behavior<LivingEntity>1.5 KB

API Surface (4)

boolean timedOut(final long timestamp)
boolean canStillUse(final ServerLevel level, final LivingEntity body, final long timestamp)
void tick(final ServerLevel level, final LivingEntity body, final long timestamp)
void stop(final ServerLevel level, final LivingEntity body, final long timestamp)

Fields & Constants (1)

cooldownTicks

Code Graph: Dependencies (5)

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

Full Source

CountDownCooldownTicks.java44 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.behavior;
2
3
import com.google.common.collect.ImmutableMap;
4
import java.util.Optional;
5
import net.minecraft.server.level.ServerLevel;
6
import net.minecraft.world.entity.LivingEntity;
7
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
8
import net.minecraft.world.entity.ai.memory.MemoryStatus;
9
10
public class CountDownCooldownTicks extends Behavior<LivingEntity> {
11
	private final MemoryModuleType<Integer> cooldownTicks;
12
13
	public CountDownCooldownTicks(final MemoryModuleType<Integer> cooldownTicks) {
14
		super(ImmutableMap.of(cooldownTicks, MemoryStatus.VALUE_PRESENT));
15
		this.cooldownTicks = cooldownTicks;
16
	}
17
18
	private Optional<Integer> getCooldownTickMemory(final LivingEntity body) {
19
		return body.getBrain().getMemory(this.cooldownTicks);
20
	}
21
22
	@Override
23
	protected boolean timedOut(final long timestamp) {
24
		return false;
25
	}
26
27
	@Override
28
	protected boolean canStillUse(final ServerLevel level, final LivingEntity body, final long timestamp) {
29
		Optional<Integer> calmDownTicks = this.getCooldownTickMemory(body);
30
		return calmDownTicks.isPresent() && calmDownTicks.get() > 0;
31
	}
32
33
	@Override
34
	protected void tick(final ServerLevel level, final LivingEntity body, final long timestamp) {
35
		Optional<Integer> calmDownTicks = this.getCooldownTickMemory(body);
36
		body.getBrain().setMemory(this.cooldownTicks, calmDownTicks.get() - 1);
37
	}
38
39
	@Override
40
	protected void stop(final ServerLevel level, final LivingEntity body, final long timestamp) {
41
		body.getBrain().eraseMemory(this.cooldownTicks);
42
	}
43
}
44

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