BreakDoorGoal .java

net.minecraft.world.entity.ai.goal.BreakDoorGoal (class): members: DEFAULT_DOOR_BREAK_TIME, lastBreakProgress, validDifficulties, getDoorBreakTime, canUse.

net.minecraft.world.entity.ai.goalclass89 linescommonextends DoorInteractGoal2.6 KB

API Surface (6)

int getDoorBreakTime()
boolean canUse()
void start()
boolean canContinueToUse()
void stop()
void tick()

Fields & Constants (5)

DEFAULT_DOOR_BREAK_TIME
validDifficulties
breakTime
lastBreakProgress
doorBreakTime

Code Graph: Dependencies (6)

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

Full Source

BreakDoorGoal.java89 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.goal;
2
3
import java.util.function.Predicate;
4
import net.minecraft.world.Difficulty;
5
import net.minecraft.world.entity.Mob;
6
import net.minecraft.world.level.block.Block;
7
import net.minecraft.world.level.gamerules.GameRules;
8
9
public class BreakDoorGoal extends DoorInteractGoal {
10
	private static final int DEFAULT_DOOR_BREAK_TIME = 240;
11
	private final Predicate<Difficulty> validDifficulties;
12
	protected int breakTime;
13
	protected int lastBreakProgress = -1;
14
	protected int doorBreakTime = -1;
15
16
	public BreakDoorGoal(final Mob mob, final Predicate<Difficulty> validDifficulties) {
17
		super(mob);
18
		this.validDifficulties = validDifficulties;
19
	}
20
21
	public BreakDoorGoal(final Mob mob, final int seconds, final Predicate<Difficulty> validDifficulties) {
22
		this(mob, validDifficulties);
23
		this.doorBreakTime = seconds;
24
	}
25
26
	protected int getDoorBreakTime() {
27
		return Math.max(240, this.doorBreakTime);
28
	}
29
30
	@Override
31
	public boolean canUse() {
32
		if (!super.canUse()) {
33
			return false;
34
		} else {
35
			return !getServerLevel(this.mob).getGameRules().get(GameRules.MOB_GRIEFING)
36
				? false
37
				: this.isValidDifficulty(this.mob.level().getDifficulty()) && !this.isOpen();
38
		}
39
	}
40
41
	@Override
42
	public void start() {
43
		super.start();
44
		this.breakTime = 0;
45
	}
46
47
	@Override
48
	public boolean canContinueToUse() {
49
		return this.breakTime <= this.getDoorBreakTime()
50
			&& !this.isOpen()
51
			&& this.doorPos.closerToCenterThan(this.mob.position(), 2.0)
52
			&& this.isValidDifficulty(this.mob.level().getDifficulty());
53
	}
54
55
	@Override
56
	public void stop() {
57
		super.stop();
58
		this.mob.level().destroyBlockProgress(this.mob.getId(), this.doorPos, -1);
59
	}
60
61
	@Override
62
	public void tick() {
63
		super.tick();
64
		if (this.mob.getRandom().nextInt(20) == 0) {
65
			this.mob.level().levelEvent(1019, this.doorPos, 0);
66
			if (!this.mob.isSwinging()) {
67
				this.mob.swingForAttack(this.mob.getUsedItemHand());
68
			}
69
		}
70
71
		this.breakTime++;
72
		int progress = (int)((float)this.breakTime / this.getDoorBreakTime() * 10.0F);
73
		if (progress != this.lastBreakProgress) {
74
			this.mob.level().destroyBlockProgress(this.mob.getId(), this.doorPos, progress);
75
			this.lastBreakProgress = progress;
76
		}
77
78
		if (this.breakTime == this.getDoorBreakTime() && this.isValidDifficulty(this.mob.level().getDifficulty())) {
79
			this.mob.level().removeBlock(this.doorPos, false);
80
			this.mob.level().levelEvent(1021, this.doorPos, 0);
81
			this.mob.level().levelEvent(2001, this.doorPos, Block.getId(this.mob.level().getBlockState(this.doorPos)));
82
		}
83
	}
84
85
	private boolean isValidDifficulty(final Difficulty difficulty) {
86
		return this.validDifficulties.test(difficulty);
87
	}
88
}
89

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