ElytraAnimationState .java

net.minecraft.world.entity.ElytraAnimationState (class): members: DEFAULT_X_ROT, DEFAULT_Z_ROT, getRotZ, rotXOld, rotYOld, rotZOld, rotZ, getRotX, getRotY.

net.minecraft.world.entityclass66 linescommon1.9 KB

API Surface (4)

void tick()
float getRotX(final float partialTicks)
float getRotY(final float partialTicks)
float getRotZ(final float partialTicks)

Fields & Constants (9)

DEFAULT_X_ROT
DEFAULT_Z_ROT
rotX
rotY
rotZ
rotXOld
rotYOld
rotZOld
entity

Code Graph: Dependencies (3)

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

Full Source

ElytraAnimationState.java66 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import net.minecraft.util.Mth;
4
import net.minecraft.world.phys.Vec3;
5
6
public class ElytraAnimationState {
7
	private static final float DEFAULT_X_ROT = (float) (Math.PI / 12);
8
	private static final float DEFAULT_Z_ROT = (float) (-Math.PI / 12);
9
	private float rotX;
10
	private float rotY;
11
	private float rotZ;
12
	private float rotXOld;
13
	private float rotYOld;
14
	private float rotZOld;
15
	private final LivingEntity entity;
16
17
	public ElytraAnimationState(final LivingEntity entity) {
18
		this.entity = entity;
19
	}
20
21
	public void tick() {
22
		this.rotXOld = this.rotX;
23
		this.rotYOld = this.rotY;
24
		this.rotZOld = this.rotZ;
25
		float targetXRot;
26
		float targetZRot;
27
		float targetYRot;
28
		if (this.entity.isFallFlying()) {
29
			float ratio = 1.0F;
30
			Vec3 movement = this.entity.getDeltaMovement();
31
			if (movement.y < 0.0) {
32
				Vec3 vec = movement.normalize();
33
				ratio = 1.0F - (float)Math.pow(-vec.y, 1.5);
34
			}
35
36
			targetXRot = Mth.lerp(ratio, (float) (Math.PI / 12), (float) (Math.PI / 9));
37
			targetZRot = Mth.lerp(ratio, (float) (-Math.PI / 12), (float) (-Math.PI / 2));
38
			targetYRot = 0.0F;
39
		} else if (this.entity.isCrouching()) {
40
			targetXRot = (float) (Math.PI * 2.0 / 9.0);
41
			targetZRot = (float) (-Math.PI / 4);
42
			targetYRot = 0.08726646F;
43
		} else {
44
			targetXRot = (float) (Math.PI / 12);
45
			targetZRot = (float) (-Math.PI / 12);
46
			targetYRot = 0.0F;
47
		}
48
49
		this.rotX = this.rotX + (targetXRot - this.rotX) * 0.3F;
50
		this.rotY = this.rotY + (targetYRot - this.rotY) * 0.3F;
51
		this.rotZ = this.rotZ + (targetZRot - this.rotZ) * 0.3F;
52
	}
53
54
	public float getRotX(final float partialTicks) {
55
		return Mth.lerp(partialTicks, this.rotXOld, this.rotX);
56
	}
57
58
	public float getRotY(final float partialTicks) {
59
		return Mth.lerp(partialTicks, this.rotYOld, this.rotY);
60
	}
61
62
	public float getRotZ(final float partialTicks) {
63
		return Mth.lerp(partialTicks, this.rotZOld, this.rotZ);
64
	}
65
}
66

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