Skip to content

Commit f3f3eaf

Browse files
committed
Rotation system and visibility checker
1 parent 680fc56 commit f3f3eaf

37 files changed

+1553
-31
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.lambda.mixin;
2+
3+
import com.lambda.Lambda;
4+
import net.minecraft.client.gui.hud.DebugHud;
5+
import net.minecraft.util.Formatting;
6+
import net.minecraft.util.hit.BlockHitResult;
7+
import net.minecraft.util.hit.EntityHitResult;
8+
import net.minecraft.util.hit.HitResult;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13+
14+
import java.util.List;
15+
16+
@Mixin(DebugHud.class)
17+
public class DebugHudMixin {
18+
@Inject(method = "getRightText", at = @At(value = "TAIL"))
19+
private void onGetRightText(CallbackInfoReturnable<List<String>> cir) {
20+
21+
if (Lambda.getMc().crosshairTarget == null) return;
22+
HitResult hitResult = Lambda.getMc().crosshairTarget;
23+
List<String> list = cir.getReturnValue();
24+
25+
list.add("");
26+
list.add(Formatting.UNDERLINE + "Lambda");
27+
list.add("Hitpos: " + hitResult.getPos());
28+
list.add("Type: " + hitResult.getType());
29+
30+
if (hitResult instanceof BlockHitResult blockHitResult) {
31+
list.add("Side: " + blockHitResult.getSide());
32+
list.add("Blockpos: " + blockHitResult.getBlockPos());
33+
}
34+
35+
if (hitResult instanceof EntityHitResult entityHitResult) {
36+
list.add("Entity: " + entityHitResult.getEntity().getName().getString());
37+
}
38+
}
39+
}

common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.lambda.Lambda;
44
import com.lambda.event.EventFlow;
55
import com.lambda.event.events.MovementEvent;
6+
import com.lambda.manager.PlayerPacketManager;
7+
import com.lambda.manager.RotationManager;
68
import net.minecraft.client.MinecraftClient;
79
import net.minecraft.client.network.ClientPlayerEntity;
810
import net.minecraft.entity.MovementType;
@@ -14,6 +16,8 @@
1416
import org.spongepowered.asm.mixin.injection.Redirect;
1517
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1618

19+
import java.util.Objects;
20+
1721
@Mixin(value = ClientPlayerEntity.class, priority = Integer.MAX_VALUE)
1822
public abstract class ClientPlayerEntityMixin extends EntityMixin {
1923

@@ -49,10 +53,25 @@ boolean onSlowDown(ClientPlayerEntity entity) {
4953
return this.isUsingItem();
5054
}
5155

56+
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(ZF)V", shift = At.Shift.AFTER))
57+
void processMovement(CallbackInfo ci) {
58+
RotationManager.BaritoneProcessor.processPlayerMovement();
59+
}
60+
5261
@Inject(method = "sendMovementPackets", at = @At(value = "HEAD"), cancellable = true)
5362
void sendBegin(CallbackInfo ci) {
5463
ci.cancel();
55-
// PlayerPacketManager.sendPlayerPackets();
56-
autoJumpEnabled = MinecraftClient.getInstance().options.getAutoJump().getValue();
64+
PlayerPacketManager.sendPlayerPackets();
65+
autoJumpEnabled = Lambda.getMc().options.getAutoJump().getValue();
66+
}
67+
68+
@Redirect(method = "tickNewAi", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
69+
float fixHeldItemYaw(ClientPlayerEntity instance) {
70+
return Objects.requireNonNullElse(RotationManager.getHandYaw(), instance.getYaw());
71+
}
72+
73+
@Redirect(method = "tickNewAi", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
74+
float fixHeldItemPitch(ClientPlayerEntity instance) {
75+
return Objects.requireNonNullElse(RotationManager.getHandPitch(), instance.getPitch());
5776
}
5877
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,61 @@
11
package com.lambda.mixin.entity;
22

3+
import com.lambda.Lambda;
4+
import com.lambda.manager.RotationManager;
5+
import com.lambda.util.math.Vec2d;
36
import net.minecraft.entity.Entity;
47
import net.minecraft.entity.MovementType;
58
import net.minecraft.util.math.Vec3d;
69
import org.spongepowered.asm.mixin.Mixin;
710
import org.spongepowered.asm.mixin.Shadow;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Redirect;
813

914
@Mixin(Entity.class)
1015
public abstract class EntityMixin {
1116
@Shadow public void move(MovementType movementType, Vec3d movement) {}
17+
18+
@Shadow public abstract float getYaw();
19+
20+
@Redirect(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
21+
public float velocityYaw(Entity entity) {
22+
if ((Object) this != Lambda.getMc().player) return getYaw();
23+
24+
Float y = RotationManager.getMovementYaw();
25+
if (y == null) return getYaw();
26+
27+
return y;
28+
}
29+
30+
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
31+
float fixDirectionYaw(Entity entity, float tickDelta) {
32+
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
33+
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw(tickDelta);
34+
35+
return (float) rot.getX();
36+
}
37+
38+
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
39+
float fixDirectionPitch(Entity entity, float tickDelta) {
40+
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
41+
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch(tickDelta);
42+
43+
return (float) rot.getY();
44+
}
45+
46+
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
47+
float fixDirectionYaw2(Entity entity) {
48+
Vec2d rot = RotationManager.getRotationForVector(1.0);
49+
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw();
50+
51+
return (float) rot.getX();
52+
}
53+
54+
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch()F"))
55+
float fixDirectionPitch2(Entity entity) {
56+
Vec2d rot = RotationManager.getRotationForVector(1.0);
57+
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch();
58+
59+
return (float) rot.getY();
60+
}
1261
}

common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
import com.lambda.Lambda;
44
import com.lambda.event.EventFlow;
55
import com.lambda.event.events.MovementEvent;
6+
import com.lambda.manager.RotationManager;
7+
import net.minecraft.entity.Entity;
68
import net.minecraft.entity.LivingEntity;
9+
import net.minecraft.util.math.MathHelper;
710
import net.minecraft.util.math.Vec3d;
811
import org.spongepowered.asm.mixin.Mixin;
912
import org.spongepowered.asm.mixin.Shadow;
1013
import org.spongepowered.asm.mixin.injection.At;
1114
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.Redirect;
16+
import org.spongepowered.asm.mixin.injection.Slice;
1217
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1318

1419
@Mixin(LivingEntity.class)
@@ -28,16 +33,51 @@ void onJump(CallbackInfo ci) {
2833

2934
if (event.isCanceled()) return;
3035

31-
if (!self.isSprinting()) {
32-
Vec3d velocity = self.getVelocity();
33-
self.setVelocity(velocity.x, event.getHeight(), velocity.z);
34-
} else {
35-
// ToDo: Implement rotation system
36-
// Float yaw = RotationManager.getMovementYaw();
37-
// float f = ((yaw != null) ? yaw : self.getYaw()) * ((float)Math.PI / 180);
38-
// self.setVelocity(self.getVelocity().add(-MathHelper.sin(f) * 0.2f, 0.0, MathHelper.cos(f) * 0.2f));
36+
Vec3d vec3d = self.getVelocity();
37+
self.setVelocity(vec3d.x, event.getHeight(), vec3d.z);
38+
39+
if (self.isSprinting()) {
40+
Float yaw = RotationManager.getMovementYaw();
41+
float f = ((yaw != null) ? yaw : self.getYaw()) * ((float)Math.PI / 180);
42+
self.setVelocity(self.getVelocity().add(-MathHelper.sin(f) * 0.2f, 0.0, MathHelper.cos(f) * 0.2f));
3943
}
4044

4145
self.velocityDirty = true;
4246
}
47+
48+
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isImmobile()Z"))
49+
void onTravelH(CallbackInfo ci) {
50+
Entity self = (Entity) (Object) this;
51+
if (self != Lambda.getMc().player) return;
52+
53+
RotationManager.update();
54+
}
55+
56+
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F"))
57+
private float hookModifyFallFlyingPitch(LivingEntity entity) {
58+
Float pitch = RotationManager.getMovementPitch();
59+
if (entity != Lambda.getMc().player || pitch == null) return entity.getPitch();
60+
61+
return pitch;
62+
}
63+
64+
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"), slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F", ordinal = 1)))
65+
private float rotBody(LivingEntity entity) {
66+
if ((Object) this != Lambda.getMc().player) {
67+
return entity.getYaw();
68+
}
69+
70+
Float yaw = RotationManager.getRenderYaw();
71+
return (yaw == null) ? entity.getYaw() : yaw;
72+
}
73+
74+
@Redirect(method = "turnHead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
75+
private float rotHead(LivingEntity entity) {
76+
if ((Object) this != Lambda.getMc().player) {
77+
return entity.getYaw();
78+
}
79+
80+
Float yaw = RotationManager.getRenderYaw();
81+
return (yaw == null) ? entity.getYaw() : yaw;
82+
}
4383
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.lambda
22

33
interface Loadable {
4-
fun load(): String
4+
fun load() = this::class.simpleName?.let { "Loaded $it" } ?: "Loaded"
55
}

common/src/main/kotlin/com/lambda/Loader.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package com.lambda
22

33
import com.lambda.Lambda.LOG
44
import com.lambda.command.CommandManager
5+
import com.lambda.manager.RotationManager
56
import com.lambda.module.ModuleRegistry
67
import kotlin.system.measureTimeMillis
78

89
object Loader {
910
private val loadables = listOf(
1011
ModuleRegistry,
11-
CommandManager
12+
CommandManager,
13+
RotationManager
1214
)
1315

1416
fun initialize() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.lambda.config
2+
3+
import com.lambda.manager.interaction.InteractionConfig
4+
import com.lambda.util.world.raycast.RayCastMask
5+
6+
class InteractionSettings(
7+
c: Configurable,
8+
vis: () -> Boolean = { true }
9+
) : InteractionConfig {
10+
override val reach by c.setting("Reach", 5.0, 0.1..10.0, 0.1, "Players reach / range", vis)
11+
override val resolution by c.setting("Resolution", 10, 1..100, 1, "Raycast resolution", vis)
12+
override val rayCastMask by c.setting("Raycast Mask", RayCastMask.BOTH, "What to raycast against", vis)
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.lambda.config
2+
3+
import com.lambda.manager.rotation.IRotationConfig
4+
import com.lambda.manager.rotation.RotationMode
5+
import kotlin.random.Random
6+
7+
class RotationSettings(
8+
c: Configurable,
9+
vis: () -> Boolean = { true }
10+
) : IRotationConfig {
11+
override val rotationMode by c.setting("Mode", RotationMode.LOCK, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera", vis)
12+
override val keepTicks by c.setting("Keep Rotation", 3, 1..10, 1, "Ticks to keep rotation", vis)
13+
override val resetTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", vis)
14+
15+
private val r1 by c.setting("Turn Speed 1", 70.0, 1.0..180.0, 0.1, "Rotation Speed 1", vis)
16+
private val r2 by c.setting("Turn Speed 2", 110.0, 1.0..180.0, 0.1, "Rotation Speed 2", vis)
17+
18+
override val turnSpeed get() = Random.nextDouble(r1, r2)
19+
20+
var speedMultiplier = 1.0
21+
22+
fun slowdownIf(flag: Boolean) {
23+
speedMultiplier = (if (flag) 0.0 else 1.0)
24+
.coerceIn(
25+
speedMultiplier - 0.3, // slowdown faster
26+
speedMultiplier + 0.15 // accelerate slower
27+
)
28+
}
29+
}

common/src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.lambda.config.settings
22

33
import com.lambda.config.AbstractSetting
4-
import kotlin.math.round
4+
import com.lambda.util.math.MathUtils.roundToStep
55
import kotlin.reflect.KProperty
66

77
/**
@@ -33,19 +33,4 @@ abstract class NumericSetting<T>(
3333
override operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: T) {
3434
value = valueIn.coerceIn(range).roundToStep(step)
3535
}
36-
37-
private fun <T : Number> T.roundToStep(step: T): T {
38-
val doubleValue = this.toDouble()
39-
val doubleStep = step.toDouble()
40-
val result = round(doubleValue / doubleStep) * doubleStep
41-
return when (this) {
42-
is Byte -> result.toInt().toByte()
43-
is Short -> result.toInt().toShort()
44-
is Int -> result.toInt()
45-
is Long -> result.toLong()
46-
is Float -> result.toFloat()
47-
is Double -> result
48-
else -> throw IllegalArgumentException("Unsupported number type")
49-
} as T
50-
}
5136
}

common/src/main/kotlin/com/lambda/event/EventFlow.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lambda.event
22

33
import com.lambda.Lambda.LOG
4+
import com.lambda.event.cancellable.Cancellable
45
import com.lambda.event.cancellable.ICancellable
56
import com.lambda.event.listener.Listener
67
import com.lambda.threading.runConcurrent
@@ -85,6 +86,16 @@ object EventFlow {
8586
return cancellable
8687
}
8788

89+
fun <T> post(cancellable: T, process: T.() -> Unit) where T : Event, T : ICancellable {
90+
val event = post(cancellable)
91+
process(event)
92+
}
93+
94+
fun <T> postChecked(cancellable: T, process: T.() -> Unit) where T : Event, T : ICancellable {
95+
val event = post(cancellable)
96+
if (!event.isCanceled()) process(event)
97+
}
98+
8899
/**
89100
* Unsubscribes from both synchronous and concurrent event flows for a specific [Event] type [T].
90101
*

0 commit comments

Comments
 (0)