Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.epsilon.events.impl;

import com.github.epsilon.managers.impl.RotationManager;
import com.github.epsilon.managers.rotations.RotationManager;

/**
* 旋转完成标记事件。当前旋转角度通过 {@link RotationManager#getYaw()} / {@link RotationManager#getPitch()} 获取。
Expand Down
23 changes: 22 additions & 1 deletion common/src/main/java/com/github/epsilon/managers/Managers.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.github.epsilon.managers;

import com.github.epsilon.events.bus.EventBus;
import com.github.epsilon.managers.impl.*;
import com.github.epsilon.managers.impl.network.ClientboundPacketManager;
import com.github.epsilon.managers.impl.network.ServerboundPacketManager;
import com.github.epsilon.managers.impl.sound.SoundManager;
import com.github.epsilon.managers.impl.target.TargetManager;
import com.github.epsilon.managers.rotations.RotationManager;
import com.github.epsilon.managers.rotations.SilentRotationManager;
import com.github.epsilon.managers.rotations.SnapRotationManager;
import com.github.epsilon.modules.impl.ClientSetting;

public class Managers {

Expand All @@ -19,7 +24,7 @@ public class Managers {
public static RenderManager RENDER;

public static void initManagers() {
ROTATION = new RotationManager();
switchRotationManager(ClientSetting.INSTANCE.rotationMode.getValue());
TARGET = new TargetManager();
HEALTH = new HealthManager();
RENDER = new RenderManager();
Expand All @@ -30,4 +35,20 @@ public static void initManagers() {
NOTIFICATION = new NotificationManager();
}

public static void switchRotationManager(RotationManager.RotationMode mode) {
RotationManager previous = ROTATION;
RotationManager next = switch (mode) {
case SNAP -> new SnapRotationManager();
case SILENT -> new SilentRotationManager();
};

if (previous != null) {
next.copyStateFrom(previous);
EventBus.INSTANCE.unsubscribe(previous);
}

ROTATION = next;
EventBus.INSTANCE.subscribe(next);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.github.epsilon.managers.impl;
package com.github.epsilon.managers.rotations;

import com.github.epsilon.events.bus.EventBus;
import com.github.epsilon.events.bus.EventHandler;
import com.github.epsilon.events.bus.EventPriority;
import com.github.epsilon.events.impl.*;
import com.github.epsilon.modules.impl.ClientSetting;
import com.github.epsilon.modules.impl.movement.MovementFix;
import com.github.epsilon.utils.rotation.Priority;
import com.github.epsilon.utils.rotation.Rot2f;
import com.github.epsilon.utils.rotation.RotationUtils;
Expand All @@ -17,7 +15,7 @@

import static com.github.epsilon.Constants.mc;

public class RotationManager {
public abstract class RotationManager {

private final Rot2f offset = new Rot2f(0, 0);
public Rot2f rotations = new Rot2f(0, 0);
Expand All @@ -26,19 +24,15 @@ public class RotationManager {
public Rot2f animationRotation = null;
public Rot2f lastAnimationRotation = null;

private boolean active;
private boolean smoothed;
private double rotationSpeed;
private Function<Rot2f, Boolean> raytrace;
protected boolean active;
protected boolean smoothed;
protected double rotationSpeed;
protected Function<Rot2f, Boolean> raytrace;
private float randomAngle;
private boolean s08;

private int priority;
private Runnable callback;

public RotationManager() {
EventBus.INSTANCE.subscribe(this);
}
protected int priority;
protected Runnable callback;

public void setRotations(Rot2f rotations, double rotationSpeed) {
setRotations(rotations, rotationSpeed, null, Priority.Medium, null);
Expand Down Expand Up @@ -66,6 +60,7 @@ public void setRotations(Rot2f rotations, double rotationSpeed, Function<Rot2f,
if (s08) {
this.rotations = this.lastRotations = this.targetRotations = new Rot2f(mc.player.getYRot(), mc.player.getXRot());
this.callback = null;
resetModeState();
s08 = false;
return;
}
Expand All @@ -78,9 +73,16 @@ public void setRotations(Rot2f rotations, double rotationSpeed, Function<Rot2f,
this.active = true;

smooth();
onRotationsSet();
}

protected void onRotationsSet() {
}

private void smooth() {
protected void resetModeState() {
}

protected void smooth() {
if (!smoothed) {
float targetYaw = targetRotations.getYaw();
float targetPitch = targetRotations.getPitch();
Expand Down Expand Up @@ -130,7 +132,7 @@ private void smooth() {
mc.pick(1.0f);
}

private void correctDisabledRotations() {
protected void correctDisabledRotations() {
Rot2f rotations = new Rot2f(mc.player.getYRot(), mc.player.getXRot());
Rot2f fixedRotations = RotationUtils.resetRotation(RotationUtils.applySensitivityPatch(rotations, lastRotations));
mc.player.setYRot(fixedRotations.getYaw());
Expand Down Expand Up @@ -169,8 +171,22 @@ public void setSmoothed(boolean smoothed) {
this.smoothed = smoothed;
}

public void copyStateFrom(RotationManager manager) {
this.rotations = manager.rotations;
this.lastRotations = manager.lastRotations;
this.targetRotations = manager.targetRotations;
this.animationRotation = manager.animationRotation;
this.lastAnimationRotation = manager.lastAnimationRotation;
this.active = manager.active;
this.smoothed = manager.smoothed;
this.rotationSpeed = manager.rotationSpeed;
this.raytrace = manager.raytrace;
this.priority = manager.priority;
this.callback = manager.callback;
}

@EventHandler
private void onRespawn(RespawnEvent event) {
protected void onRespawn(RespawnEvent event) {
offset.set(0, 0);
rotations = new Rot2f(0, 0);
lastRotations = new Rot2f(0, 0);
Expand All @@ -183,35 +199,44 @@ private void onRespawn(RespawnEvent event) {
smoothed = false;
raytrace = null;
randomAngle = 0;
resetModeState();
s08 = false;
}

@EventHandler
private void onPacketReceive(PacketEvent.Receive event) {
protected void onPacketReceive(PacketEvent.Receive event) {
if (event.getPacket() instanceof ClientboundPlayerPositionPacket || event.getPacket() instanceof ClientboundPlayerRotationPacket) {
s08 = true;
}
}

@EventHandler(priority = -1000)
private void onPlayerTick(PlayerTickEvent.Pre event) {
protected void onPlayerTick(PlayerTickEvent.Pre event) {
if (!active || rotations == null || lastRotations == null || targetRotations == null) {
rotations = lastRotations = targetRotations = new Rot2f(mc.player.getYRot(), mc.player.getXRot());
}

if (active) {
smooth();
EventBus.INSTANCE.post(new AfterRotationEvent());
runCallback();
afterPlayerTick();
}
}

if (callback != null) {
callback.run();
callback = null;
}
protected void afterPlayerTick() {
}

protected void runCallback() {
if (callback != null) {
Runnable pendingCallback = callback;
callback = null;
pendingCallback.run();
}
}

@EventHandler
private void onAnimation(RotationAnimationEvent event) {
protected void onAnimation(RotationAnimationEvent event) {
if (active && animationRotation != null && lastAnimationRotation != null) {
event.setYaw(animationRotation.getYaw());
event.setLastYaw(lastAnimationRotation.getYaw());
Expand All @@ -221,15 +246,9 @@ private void onAnimation(RotationAnimationEvent event) {
}

@EventHandler(priority = EventPriority.LOWEST)
private void onSendPosition(SendPositionEvent event) {
protected void onSendPosition(SendPositionEvent event) {
if (active && rotations != null) {
float yaw = rotations.getYaw();
float pitch = rotations.getPitch();

if (!Float.isNaN(yaw) && !Float.isNaN(pitch)) {
event.setYaw(yaw);
event.setPitch(pitch);
}
handleSendPosition(event);

if (Math.abs((rotations.getYaw() - mc.player.getYRot()) % 360) < 1 && Math.abs((rotations.getPitch() - mc.player.getXRot())) < 1) {
active = false;
Expand All @@ -250,73 +269,11 @@ private void onSendPosition(SendPositionEvent event) {
smoothed = false;
}

@EventHandler(priority = EventPriority.HIGH)
private void onMoveInput(KeyboardInputEvent event) {
MovementFix moveFix = MovementFix.INSTANCE;
if (moveFix.isEnabled() && active && rotations != null && !mc.player.isFallFlying()) {
moveFix.fixMovement(event, rotations.getYaw());
}
}
protected abstract void handleSendPosition(SendPositionEvent event);

@EventHandler
private void onRaytrace(RaytraceEvent event) {
if (ClientSetting.INSTANCE.modifyCrosshair.getValue() && active && rotations != null) {
event.setYaw(rotations.getYaw());
event.setPitch(rotations.getPitch());
}
}

@EventHandler
private void onItemRaytrace(UseItemRaytraceEvent event) {
if (active && rotations != null) {
event.setYaw(rotations.getYaw());
event.setPitch(rotations.getPitch());
}
}

@EventHandler
private void onStrafe(StrafeEvent event) {
if (MovementFix.INSTANCE.isEnabled() && active && rotations != null && !mc.player.isFallFlying()) {
event.setYaw(rotations.getYaw());
}
}

@EventHandler
private void onJump(JumpEvent event) {
if (MovementFix.INSTANCE.isEnabled() && active && rotations != null && !mc.player.isFallFlying()) {
event.setYaw(rotations.getYaw());
}
}

@EventHandler
private void onFallFlying(FallFlyingEvent event) {
if (MovementFix.INSTANCE.isEnabled() && active && rotations != null) {
event.setYaw(rotations.getYaw());
event.setPitch(rotations.getPitch());
}
}

@EventHandler
private void onUseItem(UseItemEvent event) {
if (active && rotations != null) {
event.setYaw(rotations.getYaw());
event.setPitch(rotations.getPitch());
}
}

@EventHandler
private void onFireworkUpdate(FireworkUpdateEvent event) {
if (active && rotations != null) {
event.setYaw(rotations.getYaw());
event.setPitch(rotations.getPitch());
}
}

@EventHandler
private void onAttack(AttackYawEvent event) {
if (rotations != null) {
event.setYaw(rotations.getYaw());
}
public enum RotationMode {
SILENT,
SNAP
}

}
Loading
Loading