Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
xia-mc committed Jun 2, 2024
1 parent 10b10cf commit 73fd5fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void _onTick() {
boolean flagPitch = false;
LivingEntity flagTarget = null;
for (LivingEntity entity : possibleTargets) {
diffYaw = Math.abs(PlayerRotation.getYaw(entity.getEyePosition()) - entity.getYRot());
diffPitch = Math.abs(PlayerRotation.getPitch(entity.getEyePosition()) - entity.getXRot());
diffYaw = Math.abs(PlayerRotation.getYaw(player.fabricPlayer, entity.getEyePosition()) - entity.getYRot());
diffPitch = Math.abs(PlayerRotation.getPitch(player.fabricPlayer, entity.getEyePosition()) - entity.getXRot());

flagYaw = diffYaw < AdvancedConfig.aimAMinDiffYaw;
flagPitch = diffPitch < AdvancedConfig.aimAMinDiffPitch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public void _onTick() {
boolean flagYaw = false;
float stepPitch = 0, stepYaw = 0;
for (int step : STEP) {
if (Math.abs(player.lastRot.x - player.currentRot.x) - step < AdvancedConfig.aimBMinDiffPitch) {
if (Math.abs(Math.abs(player.lastRot.x - player.currentRot.x) - step) < AdvancedConfig.aimBMinDiffPitch) {
flagPitch = true;
stepPitch = player.lastRot.x - player.currentRot.x;
}
if (Math.abs(player.lastRot.y - player.currentRot.y) - step < AdvancedConfig.aimBMinDiffYaw) {
if (Math.abs(Math.abs(player.lastRot.y - player.currentRot.y) - step) < AdvancedConfig.aimBMinDiffYaw) {
flagYaw = true;
stepYaw = player.lastRot.y - player.currentRot.y;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.infsky.cheatdetector.impl.utils.world;

import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
Expand All @@ -12,24 +13,30 @@ public class PlayerRotation {
public static float getYaw(@NotNull BlockPos pos) {
return getYaw(new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5));
}
public static float getYaw(@NotNull AbstractClientPlayer from, @NotNull Vec3 pos) {
return from.getYRot() + Mth.wrapDegrees((float) Math.toDegrees(Math.atan2(pos.z() - from.getZ(), pos.x() - from.getX())) - 90f - from.getYRot());
}

public static float getYaw(@NotNull Vec3 pos) {
LocalPlayer player = TRSelf.getInstance().fabricPlayer;
return player.getYRot() + Mth.wrapDegrees((float) Math.toDegrees(Math.atan2(pos.z() - player.getZ(), pos.x() - player.getX())) - 90f - player.getYRot());
return getYaw(TRSelf.getInstance().fabricPlayer, pos);
}

public static float getPitch(@NotNull BlockPos pos) {
return getPitch(new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5));
}
public static float getPitch(@NotNull Vec3 pos) {
LocalPlayer player = TRSelf.getInstance().fabricPlayer;

double diffX = pos.x() - player.getX();
double diffY = pos.y() - (player.getY() + player.getEyeHeight(player.getPose()));
double diffZ = pos.z() - player.getZ();
public static float getPitch(@NotNull AbstractClientPlayer from, @NotNull Vec3 pos) {
double diffX = pos.x() - from.getX();
double diffY = pos.y() - (from.getY() + from.getEyeHeight(from.getPose()));
double diffZ = pos.z() - from.getZ();

double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);

return player.getXRot() + Mth.wrapDegrees((float) -Math.toDegrees(Math.atan2(diffY, diffXZ)) - player.getXRot());
return from.getXRot() + Mth.wrapDegrees((float) -Math.toDegrees(Math.atan2(diffY, diffXZ)) - from.getXRot());
}

public static float getPitch(@NotNull Vec3 pos) {
return getPitch(TRSelf.getInstance().fabricPlayer, pos);
}

public static void rotate(double yaw, double pitch) {
Expand Down

0 comments on commit 73fd5fe

Please sign in to comment.