LinearInterpolationHandler .java

net.minecraft.world.entity.LinearInterpolationHandler (class): members: DEFAULT_INTERPOLATION_STEPS, setInterpolationLength, InterpolationData, cancel.

net.minecraft.world.entityclass63 linescommonextends AbstractInterpolationHandler2.1 KB

API Surface (8)

InterpolationHandler create(final Entity entity, final int interpolationSteps)
InterpolationHandler create(final Entity entity)
void setInterpolationLength(final int steps)
PositionAndRotation.Mutable interpolationData()
void startInterpolating(final PositionPath position, final float yRot, final float xRot)
void doInterpolate()
boolean hasActiveInterpolation()
void cancel()

Fields & Constants (2)

DEFAULT_INTERPOLATION_STEPS
interpolationData

Code Graph: Dependencies (7)

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

Full Source

LinearInterpolationHandler.java63 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import net.minecraft.core.PositionAndRotation;
4
import net.minecraft.util.Mth;
5
import net.minecraft.world.phys.Vec3;
6
7
public class LinearInterpolationHandler extends AbstractInterpolationHandler {
8
	public static final int DEFAULT_INTERPOLATION_STEPS = 3;
9
	private final LinearInterpolationHandler.InterpolationData interpolationData = new LinearInterpolationHandler.InterpolationData();
10
11
	private LinearInterpolationHandler(final Entity entity, final int interpolationSteps) {
12
		super(entity, interpolationSteps);
13
	}
14
15
	public static InterpolationHandler create(final Entity entity, final int interpolationSteps) {
16
		return entity.level().isClientSide() ? new LinearInterpolationHandler(entity, interpolationSteps) : InterpolationHandler.NO_OP;
17
	}
18
19
	public static InterpolationHandler create(final Entity entity) {
20
		return create(entity, 3);
21
	}
22
23
	public void setInterpolationLength(final int steps) {
24
		this.interpolationSteps = steps;
25
	}
26
27
	@Override
28
	protected PositionAndRotation.Mutable interpolationData() {
29
		return this.interpolationData;
30
	}
31
32
	@Override
33
	protected void startInterpolating(final PositionPath position, final float yRot, final float xRot) {
34
		this.interpolationData.set(position.endPosition(), yRot, xRot);
35
		this.interpolationData.remainingSteps = this.interpolationSteps;
36
	}
37
38
	@Override
39
	protected void doInterpolate() {
40
		double alpha = 1.0 / this.interpolationData.remainingSteps;
41
		Vec3 newPosition = this.entity.position().lerp(this.interpolationData.position(), alpha);
42
		float newYRot = (float)Mth.rotLerp(alpha, this.entity.getYRot(), this.interpolationData.yRot());
43
		float newXRot = (float)Mth.lerp(alpha, this.entity.getXRot(), this.interpolationData.xRot());
44
		this.entity.setPos(newPosition);
45
		this.entity.setRot(newYRot, newXRot);
46
		this.interpolationData.remainingSteps--;
47
	}
48
49
	@Override
50
	public boolean hasActiveInterpolation() {
51
		return this.interpolationData.remainingSteps > 0;
52
	}
53
54
	@Override
55
	public void cancel() {
56
		this.interpolationData.remainingSteps = 0;
57
	}
58
59
	private static class InterpolationData extends PositionAndRotation.Mutable {
60
		private int remainingSteps;
61
	}
62
}
63

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