Breeze .java

net.minecraft.world.entity.monster.breeze.Breeze (class, 302 lines): members: FALL_DISTANCE_SOUND_TRIGGER_THRESHOLD, JUMP_TRAIL_PARTICLES_AMOUNT, inhale.

net.minecraft.world.entity.monster.breezeclass302 linescommonextends Monster9.9 KB

API Surface (26)

AttributeSupplier.Builder createAttributes()
Brain<Breeze> getBrain()
Brain<Breeze> makeBrain(final Brain.Packed input)
void onSyncedDataUpdated(final EntityDataAccessor<?> accessor)
void tick()
Breeze resetJumpTrail()
void emitJumpTrailParticles()
void emitGroundParticles(final int amount)
void playAmbientSound()
void playWhirlSound()
ProjectileDeflection deflection(final Projectile projectile)
SoundEvent getDeathSound()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getAmbientSound()
Optional<LivingEntity> getHurtBy()
boolean withinInnerCircleRange(final Vec3 target)
void customServerAiStep(final ServerLevel level)
boolean canAttack(final LivingEntity target)
int getMaxHeadYRot()
int getHeadRotSpeed()
double getFiringYPosition()
boolean isInvulnerableTo(final ServerLevel level, final DamageSource source)
double getFluidJumpThreshold()
boolean causeFallDamage(final double fallDistance, final float damageModifier, final DamageSource damageSource)
Entity.MovementEmission getMovementEmission()
void registerDebugValues(final ServerLevel level, final DebugValueSource.Registration registration)

Fields & Constants (18)

SLIDE_PARTICLES_AMOUNT
IDLE_PARTICLES_AMOUNT
JUMP_TRAIL_PARTICLES_AMOUNT
JUMP_TRAIL_DURATION_TICKS
JUMP_CIRCLE_DISTANCE_Y
FALL_DISTANCE_SOUND_TRIGGER_THRESHOLD
WHIRL_SOUND_FREQUENCY_MIN
WHIRL_SOUND_FREQUENCY_MAX
BRAIN_PROVIDER
PROJECTILE_DEFLECTION
idle
slide
slideBack
longJump
shoot
inhale
jumpTrailStartedTick
soundTick

String literals (2)

"breezeBrain"
"breezeActivityUpdate"

Full Source

Breeze.java302 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.monster.breeze;
2
3
import java.util.List;
4
import java.util.Optional;
5
import net.minecraft.core.particles.BlockParticleOption;
6
import net.minecraft.core.particles.ParticleTypes;
7
import net.minecraft.network.syncher.EntityDataAccessor;
8
import net.minecraft.server.level.ServerLevel;
9
import net.minecraft.sounds.SoundEvent;
10
import net.minecraft.sounds.SoundEvents;
11
import net.minecraft.tags.EntityTypeTags;
12
import net.minecraft.util.debug.DebugBreezeInfo;
13
import net.minecraft.util.debug.DebugSubscriptions;
14
import net.minecraft.util.debug.DebugValueSource;
15
import net.minecraft.util.profiling.Profiler;
16
import net.minecraft.util.profiling.ProfilerFiller;
17
import net.minecraft.world.damagesource.DamageSource;
18
import net.minecraft.world.entity.AnimationState;
19
import net.minecraft.world.entity.Entity;
20
import net.minecraft.world.entity.EntityType;
21
import net.minecraft.world.entity.EntityTypes;
22
import net.minecraft.world.entity.LivingEntity;
23
import net.minecraft.world.entity.Mob;
24
import net.minecraft.world.entity.Pose;
25
import net.minecraft.world.entity.ai.Brain;
26
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
27
import net.minecraft.world.entity.ai.attributes.Attributes;
28
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
29
import net.minecraft.world.entity.ai.sensing.SensorType;
30
import net.minecraft.world.entity.monster.Monster;
31
import net.minecraft.world.entity.projectile.Projectile;
32
import net.minecraft.world.entity.projectile.ProjectileDeflection;
33
import net.minecraft.world.entity.schedule.Activity;
34
import net.minecraft.world.level.Level;
35
import net.minecraft.world.level.block.RenderShape;
36
import net.minecraft.world.level.block.state.BlockState;
37
import net.minecraft.world.level.pathfinder.PathType;
38
import net.minecraft.world.phys.Vec3;
39
import org.jspecify.annotations.Nullable;
40
41
public class Breeze extends Monster {
42
	private static final int SLIDE_PARTICLES_AMOUNT = 20;
43
	private static final int IDLE_PARTICLES_AMOUNT = 1;
44
	private static final int JUMP_TRAIL_PARTICLES_AMOUNT = 3;
45
	private static final int JUMP_TRAIL_DURATION_TICKS = 5;
46
	private static final int JUMP_CIRCLE_DISTANCE_Y = 10;
47
	private static final float FALL_DISTANCE_SOUND_TRIGGER_THRESHOLD = 3.0F;
48
	private static final int WHIRL_SOUND_FREQUENCY_MIN = 1;
49
	private static final int WHIRL_SOUND_FREQUENCY_MAX = 80;
50
	private static final Brain.Provider<Breeze> BRAIN_PROVIDER = Brain.provider(
51
		List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.HURT_BY, SensorType.NEAREST_PLAYERS, SensorType.BREEZE_ATTACK_ENTITY_SENSOR), BreezeAi::getActivities
52
	);
53
	public final AnimationState idle = new AnimationState();
54
	public final AnimationState slide = new AnimationState();
55
	public final AnimationState slideBack = new AnimationState();
56
	public final AnimationState longJump = new AnimationState();
57
	public final AnimationState shoot = new AnimationState();
58
	public final AnimationState inhale = new AnimationState();
59
	private int jumpTrailStartedTick = 0;
60
	private int soundTick = 0;
61
	private static final ProjectileDeflection PROJECTILE_DEFLECTION = (projectile, entity, random, power) -> {
62
		entity.level().playSound(null, entity, SoundEvents.BREEZE_DEFLECT, entity.getSoundSource(), 1.0F, 1.0F);
63
		ProjectileDeflection.REVERSE.deflect(projectile, entity, random, power);
64
	};
65
66
	public static AttributeSupplier.Builder createAttributes() {
67
		return Mob.createMobAttributes()
68
			.add(Attributes.MOVEMENT_SPEED, 0.63F)
69
			.add(Attributes.MAX_HEALTH, 30.0)
70
			.add(Attributes.FOLLOW_RANGE, 24.0)
71
			.add(Attributes.ATTACK_DAMAGE, 3.0);
72
	}
73
74
	public Breeze(final EntityType<? extends Monster> type, final Level level) {
75
		super(type, level);
76
		this.setPathfindingMalus(PathType.ON_TOP_OF_TRAPDOOR, -1.0F);
77
		this.setPathfindingMalus(PathType.FIRE, -1.0F);
78
		this.xpReward = 10;
79
	}
80
81
	@Override
82
	public Brain<Breeze> getBrain() {
83
		return super.getBrain();
84
	}
85
86
	@Override
87
	protected Brain<Breeze> makeBrain(final Brain.Packed input) {
88
		Brain<Breeze> brain = BRAIN_PROVIDER.makeBrain(this, input);
89
		brain.setDefaultActivity(Activity.FIGHT);
90
		brain.useDefaultActivity();
91
		return brain;
92
	}
93
94
	@Override
95
	public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
96
		if (this.level().isClientSide() && DATA_POSE.equals(accessor)) {
97
			this.resetAnimations();
98
			Pose pose = this.getPose();
99
			switch (pose) {
100
				case SHOOTING:
101
					this.shoot.startIfStopped(this.tickCount);
102
					break;
103
				case INHALING:
104
					this.inhale.startIfStopped(this.tickCount);
105
					break;
106
				case SLIDING:
107
					this.slide.startIfStopped(this.tickCount);
108
			}
109
		}
110
111
		super.onSyncedDataUpdated(accessor);
112
	}
113
114
	private void resetAnimations() {
115
		this.shoot.stop();
116
		this.idle.stop();
117
		this.inhale.stop();
118
		this.longJump.stop();
119
	}
120
121
	@Override
122
	public void tick() {
123
		Pose pose = this.getPose();
124
		switch (pose) {
125
			case SHOOTING:
126
			case INHALING:
127
			case STANDING:
128
				this.resetJumpTrail().emitGroundParticles(1 + this.getRandom().nextInt(1));
129
				break;
130
			case SLIDING:
131
				this.emitGroundParticles(20);
132
				break;
133
			case LONG_JUMPING:
134
				this.longJump.startIfStopped(this.tickCount);
135
				this.emitJumpTrailParticles();
136
		}
137
138
		this.idle.startIfStopped(this.tickCount);
139
		if (pose != Pose.SLIDING && this.slide.isStarted()) {
140
			this.slideBack.start(this.tickCount);
141
			this.slide.stop();
142
		}
143
144
		this.soundTick = this.soundTick == 0 ? this.random.nextIntBetweenInclusive(1, 80) : this.soundTick - 1;
145
		if (this.soundTick == 0) {
146
			this.playWhirlSound();
147
		}
148
149
		super.tick();
150
	}
151
152
	public Breeze resetJumpTrail() {
153
		this.jumpTrailStartedTick = 0;
154
		return this;
155
	}
156
157
	public void emitJumpTrailParticles() {
158
		if (++this.jumpTrailStartedTick <= 5) {
159
			BlockState ground = !this.getInBlockState().isAir() ? this.getInBlockState() : this.getBlockStateOn();
160
			Vec3 movement = this.getDeltaMovement();
161
			Vec3 centered = this.position().add(movement).add(0.0, 0.1F, 0.0);
162
163
			for (int i = 0; i < 3; i++) {
164
				this.level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, ground), centered.x, centered.y, centered.z, 0.0, 0.0, 0.0);
165
			}
166
		}
167
	}
168
169
	public void emitGroundParticles(final int amount) {
170
		if (!this.isPassenger()) {
171
			Vec3 boundingBoxCenter = this.getBoundingBox().getCenter();
172
			Vec3 position = new Vec3(boundingBoxCenter.x, this.position().y, boundingBoxCenter.z);
173
			BlockState ground = !this.getInBlockState().isAir() ? this.getInBlockState() : this.getBlockStateOn();
174
			if (ground.getRenderShape() != RenderShape.INVISIBLE) {
175
				for (int i = 0; i < amount; i++) {
176
					this.level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, ground), position.x, position.y, position.z, 0.0, 0.0, 0.0);
177
				}
178
			}
179
		}
180
	}
181
182
	@Override
183
	public void playAmbientSound() {
184
		if (this.getTarget() == null || !this.onGround()) {
185
			this.level().playLocalSound(this, this.getAmbientSound(), this.getSoundSource(), 1.0F, 1.0F);
186
		}
187
	}
188
189
	public void playWhirlSound() {
190
		float pitch = 0.7F + 0.4F * this.random.nextFloat();
191
		float volume = 0.8F + 0.2F * this.random.nextFloat();
192
		this.level().playLocalSound(this, SoundEvents.BREEZE_WHIRL, this.getSoundSource(), volume, pitch);
193
	}
194
195
	@Override
196
	public ProjectileDeflection deflection(final Projectile projectile) {
197
		if (!projectile.is(EntityTypes.BREEZE_WIND_CHARGE) && !projectile.is(EntityTypes.WIND_CHARGE)) {
198
			return this.is(EntityTypeTags.DEFLECTS_PROJECTILES) ? PROJECTILE_DEFLECTION : ProjectileDeflection.NONE;
199
		} else {
200
			return ProjectileDeflection.NONE;
201
		}
202
	}
203
204
	@Override
205
	protected SoundEvent getDeathSound() {
206
		return SoundEvents.BREEZE_DEATH;
207
	}
208
209
	@Override
210
	protected SoundEvent getHurtSound(final DamageSource source) {
211
		return SoundEvents.BREEZE_HURT;
212
	}
213
214
	@Override
215
	protected SoundEvent getAmbientSound() {
216
		return this.onGround() ? SoundEvents.BREEZE_IDLE_GROUND : SoundEvents.BREEZE_IDLE_AIR;
217
	}
218
219
	public Optional<LivingEntity> getHurtBy() {
220
		return this.getBrain()
221
			.getMemory(MemoryModuleType.HURT_BY)
222
			.map(DamageSource::getEntity)
223
			.filter(entity -> entity instanceof LivingEntity)
224
			.map(entity -> (LivingEntity)entity);
225
	}
226
227
	public boolean withinInnerCircleRange(final Vec3 target) {
228
		Vec3 ourPosition = Vec3.atCenterOf(this.blockPosition());
229
		return target.closerThan(ourPosition, 4.0, 10.0);
230
	}
231
232
	@Override
233
	protected void customServerAiStep(final ServerLevel level) {
234
		ProfilerFiller profiler = Profiler.get();
235
		profiler.push("breezeBrain");
236
		this.getBrain().tick(level, this);
237
		profiler.popPush("breezeActivityUpdate");
238
		BreezeAi.updateActivity(this);
239
		profiler.pop();
240
		super.customServerAiStep(level);
241
	}
242
243
	@Override
244
	public boolean canAttack(final LivingEntity target) {
245
		return (target.is(EntityTypes.PLAYER) || target.is(EntityTypes.IRON_GOLEM)) && super.canAttack(target);
246
	}
247
248
	@Override
249
	public int getMaxHeadYRot() {
250
		return 30;
251
	}
252
253
	@Override
254
	public int getHeadRotSpeed() {
255
		return 25;
256
	}
257
258
	public double getFiringYPosition() {
259
		return this.getY() + this.getBbHeight() / 2.0F + 0.3F;
260
	}
261
262
	@Override
263
	public boolean isInvulnerableTo(final ServerLevel level, final DamageSource source) {
264
		return source.getEntity() instanceof Breeze || super.isInvulnerableTo(level, source);
265
	}
266
267
	@Override
268
	public double getFluidJumpThreshold() {
269
		return this.getEyeHeight();
270
	}
271
272
	@Override
273
	public boolean causeFallDamage(final double fallDistance, final float damageModifier, final DamageSource damageSource) {
274
		if (fallDistance > 3.0) {
275
			this.playSound(SoundEvents.BREEZE_LAND, 1.0F, 1.0F);
276
		}
277
278
		return super.causeFallDamage(fallDistance, damageModifier, damageSource);
279
	}
280
281
	@Override
282
	protected Entity.MovementEmission getMovementEmission() {
283
		return Entity.MovementEmission.EVENTS;
284
	}
285
286
	@Override
287
	public @Nullable LivingEntity getTarget() {
288
		return this.getTargetFromBrain();
289
	}
290
291
	@Override
292
	public void registerDebugValues(final ServerLevel level, final DebugValueSource.Registration registration) {
293
		super.registerDebugValues(level, registration);
294
		registration.register(
295
			DebugSubscriptions.BREEZES,
296
			() -> new DebugBreezeInfo(
297
				this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).map(Entity::getId), this.getBrain().getMemory(MemoryModuleType.BREEZE_JUMP_TARGET)
298
			)
299
		);
300
	}
301
}
302

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