Skip to content

Commit 08165dd

Browse files
committed
Raycast improve
1 parent ea8330f commit 08165dd

6 files changed

Lines changed: 43 additions & 309 deletions

File tree

src/main/java/com/nekiplay/hypixelcry/mixins/entity/PlayerEntityRendererMixin.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,4 @@
1414
@Mixin(PlayerEntityRenderer.class)
1515
public abstract class PlayerEntityRendererMixin {
1616
// Rotations
17-
18-
@Inject(method = "updateRenderState(Lnet/minecraft/client/network/AbstractClientPlayerEntity;Lnet/minecraft/client/render/entity/state/PlayerEntityRenderState;F)V", at = @At("RETURN"))
19-
private void updateRenderState$rotations(AbstractClientPlayerEntity abstractClientPlayerEntity, PlayerEntityRenderState playerEntityRenderState, float f, CallbackInfo ci) {
20-
if (Rotations.rotating && abstractClientPlayerEntity == mc.player) {
21-
playerEntityRenderState.bodyYaw = Rotations.serverYaw;
22-
playerEntityRenderState.pitch = Rotations.serverPitch;
23-
}
24-
}
2517
}
Lines changed: 10 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package com.nekiplay.hypixelcry.utils;
22

3-
import com.nekiplay.hypixelcry.annotations.Init;
4-
import com.nekiplay.hypixelcry.events.SendMovementPacketsEvent;
53
import com.nekiplay.hypixelcry.utils.helper.*;
6-
import com.nekiplay.hypixelcry.utils.misc.Pool;
7-
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
8-
import net.minecraft.client.MinecraftClient;
94
import net.minecraft.entity.Entity;
10-
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
115
import net.minecraft.util.math.BlockPos;
126
import net.minecraft.util.math.MathHelper;
137
import net.minecraft.util.math.Vec3d;
@@ -17,141 +11,6 @@
1711
import static com.nekiplay.hypixelcry.HypixelCry.mc;
1812

1913
public class Rotations {
20-
private static final Pool<Rotation> rotationPool = new Pool<>(Rotation::new);
21-
private static final List<Rotation> rotations = new ArrayList<>();
22-
public static float serverYaw;
23-
public static float serverPitch;
24-
public static int rotationTimer;
25-
private static float preYaw, prePitch;
26-
private static int i = 0;
27-
28-
private static Rotation lastRotation;
29-
private static int lastRotationTimer;
30-
private static boolean sentLastRotation;
31-
public static boolean rotating = false;
32-
33-
@Init
34-
public static void init() {
35-
SendMovementPacketsEvent.PRE.register(Rotations::onSendMovementPacketsPre);
36-
SendMovementPacketsEvent.POST.register(Rotations::onSendMovementPacketsPost);
37-
ClientTickEvents.END_CLIENT_TICK.register(Rotations::onTick);
38-
}
39-
40-
public static void rotate(double yaw, double pitch, int priority, boolean clientSide, Runnable callback) {
41-
Rotation rotation = rotationPool.get();
42-
rotation.set(yaw, pitch, priority, clientSide, callback);
43-
44-
int i = 0;
45-
for (; i < rotations.size(); i++) {
46-
if (priority > rotations.get(i).priority) break;
47-
}
48-
49-
rotations.add(i, rotation);
50-
}
51-
52-
public static void rotate(double yaw, double pitch, int priority, Runnable callback) {
53-
rotate(yaw, pitch, priority, false, callback);
54-
}
55-
56-
public static void rotate(double yaw, double pitch, Runnable callback) {
57-
rotate(yaw, pitch, 0, callback);
58-
}
59-
60-
public static void rotate(double yaw, double pitch, int priority) {
61-
rotate(yaw, pitch, priority, null);
62-
}
63-
64-
public static void rotate(double yaw, double pitch) {
65-
rotate(yaw, pitch, 0, null);
66-
}
67-
68-
private static void resetLastRotation() {
69-
if (lastRotation != null) {
70-
rotationPool.free(lastRotation);
71-
72-
lastRotation = null;
73-
lastRotationTimer = 0;
74-
}
75-
}
76-
77-
private static void onSendMovementPacketsPre() {
78-
if (mc.cameraEntity != mc.player) return;
79-
sentLastRotation = false;
80-
81-
if (!rotations.isEmpty()) {
82-
rotating = true;
83-
resetLastRotation();
84-
85-
Rotation rotation = rotations.get(i);
86-
setupMovementPacketRotation(rotation);
87-
88-
if (rotations.size() > 1) rotationPool.free(rotation);
89-
90-
i++;
91-
} else if (lastRotation != null) {
92-
if (lastRotationTimer >= 1) {
93-
resetLastRotation();
94-
rotating = false;
95-
} else {
96-
setupMovementPacketRotation(lastRotation);
97-
sentLastRotation = true;
98-
99-
lastRotationTimer++;
100-
}
101-
}
102-
}
103-
104-
private static void setupMovementPacketRotation(Rotation rotation) {
105-
setClientRotation(rotation);
106-
setCamRotation(rotation.yaw, rotation.pitch);
107-
}
108-
109-
private static void setClientRotation(Rotation rotation) {
110-
preYaw = mc.player.getYaw();
111-
prePitch = mc.player.getPitch();
112-
113-
mc.player.setYaw((float) rotation.yaw);
114-
mc.player.setPitch((float) rotation.pitch);
115-
}
116-
117-
private static void onSendMovementPacketsPost() {
118-
if (!rotations.isEmpty()) {
119-
if (mc.cameraEntity == mc.player) {
120-
rotations.get(i - 1).runCallback();
121-
122-
if (rotations.size() == 1) lastRotation = rotations.get(i - 1);
123-
124-
resetPreRotation();
125-
}
126-
127-
for (; i < rotations.size(); i++) {
128-
Rotation rotation = rotations.get(i);
129-
130-
setCamRotation(rotation.yaw, rotation.pitch);
131-
if (rotation.clientSide) setClientRotation(rotation);
132-
rotation.sendPacket();
133-
if (rotation.clientSide) resetPreRotation();
134-
135-
if (i == rotations.size() - 1) lastRotation = rotation;
136-
else rotationPool.free(rotation);
137-
}
138-
139-
rotations.clear();
140-
i = 0;
141-
} else if (sentLastRotation) {
142-
resetPreRotation();
143-
}
144-
}
145-
146-
private static void resetPreRotation() {
147-
mc.player.setYaw(preYaw);
148-
mc.player.setPitch(prePitch);
149-
}
150-
151-
private static void onTick(MinecraftClient client) {
152-
rotationTimer++;
153-
}
154-
15514
public static double getYaw(Entity entity) {
15615
return mc.player.getYaw() + MathHelper.wrapDegrees((float) Math.toDegrees(Math.atan2(entity.getZ() - mc.player.getZ(), entity.getX() - mc.player.getX())) - 90f - mc.player.getYaw());
15716
}
@@ -196,33 +55,16 @@ public static double getPitch(BlockPos pos) {
19655
return mc.player.getPitch() + MathHelper.wrapDegrees((float) -Math.toDegrees(Math.atan2(diffY, diffXZ)) - mc.player.getPitch());
19756
}
19857

199-
public static void setCamRotation(double yaw, double pitch) {
200-
serverYaw = (float) yaw;
201-
serverPitch = (float) pitch;
202-
rotationTimer = 0;
203-
}
58+
public static Vec3d getDirectionFromYawPitch(float yaw, float pitch) {
59+
// Конвертируем градусы в радианы
60+
float yawRad = (float) Math.toRadians(yaw);
61+
float pitchRad = (float) Math.toRadians(pitch);
62+
63+
// Вычисляем компоненты вектора
64+
double x = -MathHelper.sin(yawRad) * MathHelper.cos(pitchRad);
65+
double y = -MathHelper.sin(pitchRad);
66+
double z = MathHelper.cos(yawRad) * MathHelper.cos(pitchRad);
20467

205-
private static class Rotation {
206-
public double yaw, pitch;
207-
public int priority;
208-
public boolean clientSide;
209-
public Runnable callback;
210-
211-
public void set(double yaw, double pitch, int priority, boolean clientSide, Runnable callback) {
212-
this.yaw = yaw;
213-
this.pitch = pitch;
214-
this.priority = priority;
215-
this.clientSide = clientSide;
216-
this.callback = callback;
217-
}
218-
219-
public void sendPacket() {
220-
mc.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.LookAndOnGround((float) yaw, (float) pitch, mc.player.isOnGround(), mc.player.horizontalCollision));
221-
runCallback();
222-
}
223-
224-
public void runCallback() {
225-
if (callback != null) callback.run();
226-
}
68+
return new Vec3d(x, y, z).normalize();
22769
}
22870
}

src/main/java/com/nekiplay/hypixelcry/utils/SmoothRotator.java

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)