Skip to content

Commit 34650ed

Browse files
authored
Merge pull request #6 from Avanatiker/feature/freecam
Freecam
2 parents b85e659 + 417bd0a commit 34650ed

File tree

20 files changed

+300
-38
lines changed

20 files changed

+300
-38
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.lambda.event.events.MovementEvent;
66
import com.lambda.interaction.PlayerPacketManager;
77
import com.lambda.interaction.RotationManager;
8+
import net.minecraft.client.input.Input;
89
import net.minecraft.client.network.ClientPlayerEntity;
910
import net.minecraft.entity.MovementType;
1011
import net.minecraft.util.math.Vec3d;
@@ -26,6 +27,8 @@ public abstract class ClientPlayerEntityMixin extends EntityMixin {
2627

2728
@Shadow private boolean autoJumpEnabled;
2829

30+
@Shadow public Input input;
31+
2932
@Inject(method = "move", at = @At("HEAD"), cancellable = true)
3033
void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
3134
ClientPlayerEntity self = (ClientPlayerEntity) (Object) this;
@@ -49,12 +52,14 @@ void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
4952
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
5053
boolean onSlowDown(ClientPlayerEntity entity) {
5154
if (EventFlow.post(new MovementEvent.SlowDown()).isCanceled()) return false;
52-
return this.isUsingItem();
55+
return isUsingItem();
5356
}
5457

55-
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(ZF)V", shift = At.Shift.AFTER))
56-
void processMovement(CallbackInfo ci) {
57-
RotationManager.BaritoneProcessor.processPlayerMovement();
58+
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(ZF)V"))
59+
void processMovement(Input input, boolean slowDown, float slowDownFactor) {
60+
if (EventFlow.post(new MovementEvent.InputUpdate(input, slowDown, slowDownFactor)).isCanceled()) return;
61+
62+
input.tick(slowDown, slowDownFactor);
5863
}
5964

6065
@Inject(method = "sendMovementPackets", at = @At(value = "HEAD"), cancellable = true)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.lambda.mixin.input;
2+
3+
import com.lambda.event.EventFlow;
4+
import com.lambda.event.events.InputEvent;
5+
import net.minecraft.client.input.KeyboardInput;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
10+
11+
@Mixin(KeyboardInput.class)
12+
public class KeyboardInputMixin {
13+
@Inject(method = "tick", at = @At("TAIL"))
14+
private void onTick(boolean slowDown, float slowDownFactor, CallbackInfo ci) {
15+
EventFlow.post(new InputEvent());
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lambda.mixin.input;
2+
3+
import com.lambda.module.modules.player.Freecam;
4+
import net.minecraft.client.Mouse;
5+
import net.minecraft.client.network.ClientPlayerEntity;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Redirect;
9+
10+
@Mixin(Mouse.class)
11+
public class MouseMixin {
12+
@Redirect(method = "updateMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;changeLookDirection(DD)V"))
13+
private void updateMouseChangeLookDirection(ClientPlayerEntity player, double cursorDeltaX, double cursorDeltaY) {
14+
if (Freecam.INSTANCE.isEnabled()) {
15+
Freecam.updateRotation(cursorDeltaX, cursorDeltaY);
16+
return;
17+
}
18+
19+
player.changeLookDirection(cursorDeltaX, cursorDeltaY);
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.lambda.module.modules.player.Freecam;
4+
import net.minecraft.entity.Entity;
5+
import net.minecraft.world.BlockView;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import net.minecraft.client.render.Camera;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(Camera.class)
13+
public class CameraMixin {
14+
@Inject(method = "update", at = @At("TAIL"))
15+
private void onUpdate(
16+
BlockView area,
17+
Entity focusedEntity,
18+
boolean thirdPerson,
19+
boolean inverseView,
20+
float tickDelta,
21+
CallbackInfo ci
22+
) {
23+
if (!Freecam.INSTANCE.isEnabled()) return;
24+
25+
Freecam.updateCam();
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.lambda.module.modules.player.Freecam;
4+
import net.minecraft.client.render.GameRenderer;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
@Mixin(GameRenderer.class)
11+
public class GameRendererMixin {
12+
@Inject(method = "updateTargetedEntity", at = @At("HEAD"), cancellable = true)
13+
private void updateTargetedEntityInvoke(float tickDelta, CallbackInfo info) {
14+
if (!Freecam.INSTANCE.isEnabled()) return;
15+
16+
info.cancel();
17+
Freecam.updateTarget();
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.lambda.module.modules.player.Freecam;
4+
import net.minecraft.client.render.Camera;
5+
import net.minecraft.client.render.WorldRenderer;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.ModifyArg;
9+
import org.spongepowered.asm.mixin.injection.Redirect;
10+
11+
@Mixin(WorldRenderer.class)
12+
public class WorldRendererMixin {
13+
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;isThirdPerson()Z"))
14+
private boolean renderIsThirdPerson(Camera camera) {
15+
return Freecam.INSTANCE.isEnabled() || camera.isThirdPerson();
16+
}
17+
18+
@ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;setupTerrain(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/Frustum;ZZ)V"), index = 3)
19+
private boolean renderSetupTerrainModifyArg(boolean spectator) {
20+
return Freecam.INSTANCE.isEnabled() || spectator;
21+
}
22+
}

common/src/main/kotlin/com/lambda/config/RotationSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class RotationSettings(
88
c: Configurable,
99
vis: () -> Boolean = { true }
1010
) : 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)
11+
override var rotationMode by c.setting("Mode", RotationMode.SYNC, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera", vis)
1212
override val keepTicks by c.setting("Keep Rotation", 3, 1..10, 1, "Ticks to keep rotation", vis)
1313
override val resetTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", vis)
1414

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lambda.event.events
2+
3+
import com.lambda.event.Event
4+
5+
class InputEvent : Event

common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ package com.lambda.event.events
33
import com.lambda.event.Event
44
import com.lambda.event.cancellable.Cancellable
55
import com.lambda.event.cancellable.ICancellable
6+
import net.minecraft.client.input.Input
67

78
abstract class MovementEvent : Event {
89
class Pre : MovementEvent()
910
class Post : MovementEvent()
11+
class InputUpdate(
12+
val input: Input,
13+
val slowDown: Boolean,
14+
val slowDownFactor: Float
15+
) : MovementEvent(), ICancellable by Cancellable()
1016
class ClipAtLedge : MovementEvent(), ICancellable by Cancellable()
1117
class Jump(var height: Double) : MovementEvent(), ICancellable by Cancellable()
1218
class SlowDown : Event, ICancellable by Cancellable()

common/src/main/kotlin/com/lambda/event/events/RotationEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class RotationEvent : Event {
2424
init {
2525
// Always check if baritone wants to rotate as well
2626
RotationManager.BaritoneProcessor.baritoneContext?.let { context ->
27-
requests.add(RotationRequest(-1, context.config, context.rotation))
27+
requests.add(RotationRequest(context.config, context.rotation, -1))
2828
}
2929
}
3030

0 commit comments

Comments
 (0)