Fields & Constants (3) HEAD_TILT_X
HEAD_TILT_Y
maxYRotFromCenter
Code Graph: Dependencies (3) Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.
Full Source
SmoothSwimmingLookControl.java 38 lines · Minecraft 26.3 · verbatim Copy
1 package net.minecraft.world.entity.ai.control;
2
3 import net.minecraft.util.Mth;
4 import net.minecraft.world.entity.Mob;
5
6 public class SmoothSwimmingLookControl extends LookControl {
7 private final int maxYRotFromCenter;
8 private static final int HEAD_TILT_X = 10;
9 private static final int HEAD_TILT_Y = 20;
10
11 public SmoothSwimmingLookControl(final Mob mob, final int maxYRotFromCenter) {
12 super(mob);
13 this.maxYRotFromCenter = maxYRotFromCenter;
14 }
15
16 @Override
17 public void tick() {
18 if (this.lookAtCooldown > 0) {
19 this.lookAtCooldown--;
20 this.getYRotD().ifPresent(yRotD -> this.mob.yHeadRot = this.rotateTowards(this.mob.yHeadRot, yRotD + 20.0F, this.yMaxRotSpeed));
21 this.getXRotD().ifPresent(xRotD -> this.mob.setXRot(this.rotateTowards(this.mob.getXRot(), xRotD + 10.0F, this.xMaxRotAngle)));
22 } else {
23 if (this.mob.getNavigation().isDone()) {
24 this.mob.setXRot(this.rotateTowards(this.mob.getXRot(), 0.0F, 5.0F));
25 }
26
27 this.mob.yHeadRot = this.rotateTowards(this.mob.yHeadRot, this.mob.yBodyRot, this.yMaxRotSpeed);
28 }
29
30 float headDiffBody = Mth.wrapDegrees(this.mob.yHeadRot - this.mob.yBodyRot);
31 if (headDiffBody < -this.maxYRotFromCenter) {
32 this.mob.yBodyRot -= 4.0F;
33 } else if (headDiffBody > this.maxYRotFromCenter) {
34 this.mob.yBodyRot += 4.0F;
35 }
36 }
37 }
38
Decompiled Minecraft 26.3 source of SmoothSwimmingLookControl (net/minecraft/world/entity/ai/control/SmoothSwimmingLookControl.java) with Mojang official mappings, stored verbatim on the site.