-
-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathResponsiveSmoothAOTE.java
More file actions
79 lines (68 loc) · 2.9 KB
/
Copy pathResponsiveSmoothAOTE.java
File metadata and controls
79 lines (68 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package de.hysky.skyblocker.skyblock.teleport;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.render.RenderHelper;
import net.minecraft.client.CameraType;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
import static de.hysky.skyblocker.skyblock.teleport.PredictiveSmoothAOTE.getItemDistance;
public class ResponsiveSmoothAOTE {
private static final Minecraft CLIENT = Minecraft.getInstance();
private static long startTime;
@Nullable
private static Vec3 lastPosition;
private static double lastProgress;
@Nullable
private static Vec3 cameraStartPos;
public static void playerGoingToTeleport() {
if (CLIENT.player == null || SkyblockerConfigManager.get().uiAndVisuals.smoothAOTE.maximumAddedLag == 0) return;
//make sure teleport is enabled for held item
ItemStack heldItem = CLIENT.player.getMainHandItem();
String itemId = heldItem.getSkyblockId();
CompoundTag customData = ItemUtils.getCustomData(heldItem);
int distance = getItemDistance(itemId, customData);
if (distance == -1) {
return;
}
// make sure the camera is not in 3rd person if disabled
if (CLIENT.options.getCameraType() != CameraType.FIRST_PERSON && !SkyblockerConfigManager.get().uiAndVisuals.smoothAOTE.thirdPerson) {
return;
}
Vec3 currentIntermediatePosition = getInterpolatedPos(RenderHelper.getCamera().position());
lastPosition = currentIntermediatePosition == null ? RenderHelper.getCamera().position() : currentIntermediatePosition;
lastProgress = 0;
startTime = System.currentTimeMillis();
}
@Nullable
public static Vec3 getInterpolatedPos(Vec3 original) {
if (lastPosition == null || CLIENT.player == null) return null;
cameraStartPos = original;
double progress = (double) (System.currentTimeMillis() - startTime) / SkyblockerConfigManager.get().uiAndVisuals.smoothAOTE.maximumAddedLag;
//end if finished
if (progress >= 1) {
lastPosition = null;
lastProgress = 0;
return null;
}
//find vector between last position and current pos
Vec3 teleportVector = original.subtract(lastPosition);
double progressDiff = progress - lastProgress;
double relativeProgress = progressDiff / (1 - lastProgress);
//return interpolated pos
if (lastPosition == null) return null; // some who still a problem here
lastPosition = lastPosition.add(teleportVector.scale(relativeProgress));
lastProgress = progress;
return lastPosition;
}
@Nullable
public static Vec3 getInterpolatedPlayerPos(float partialTicks) {
if (CLIENT.player == null || cameraStartPos == null) return null;
Vec3 diff = CLIENT.player.getPosition(partialTicks).subtract(cameraStartPos);
Vec3 camara = getInterpolatedPos(cameraStartPos);
if (camara == null) return null;
return camara.add(diff);
}
}