Skip to content

Commit 2e2157b

Browse files
committed
maybe hopefully fix client compat again? :3
1 parent 8a115e7 commit 2e2157b

File tree

3 files changed

+36
-99
lines changed

3 files changed

+36
-99
lines changed

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.MovementEvent;
2323
import com.lambda.event.events.PlayerEvent;
24+
import com.lambda.event.events.PlayerPacketEvent;
2425
import com.lambda.event.events.TickEvent;
25-
import com.lambda.interaction.PlayerPacketHandler;
2626
import com.lambda.interaction.managers.rotating.RotationManager;
2727
import com.lambda.module.modules.movement.ElytraFly;
2828
import com.lambda.module.modules.movement.NoJumpCooldown;
@@ -37,17 +37,16 @@
3737
import net.minecraft.client.gui.screen.Screen;
3838
import net.minecraft.client.input.Input;
3939
import net.minecraft.client.network.AbstractClientPlayerEntity;
40-
import net.minecraft.client.network.ClientPlayNetworkHandler;
4140
import net.minecraft.client.network.ClientPlayerEntity;
4241
import net.minecraft.client.world.ClientWorld;
4342
import net.minecraft.entity.MovementType;
44-
import net.minecraft.network.packet.Packet;
43+
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
4544
import net.minecraft.util.Hand;
4645
import net.minecraft.util.math.Vec3d;
47-
import org.objectweb.asm.Opcodes;
4846
import org.spongepowered.asm.mixin.Final;
4947
import org.spongepowered.asm.mixin.Mixin;
5048
import org.spongepowered.asm.mixin.Shadow;
49+
import org.spongepowered.asm.mixin.Unique;
5150
import org.spongepowered.asm.mixin.injection.At;
5251
import org.spongepowered.asm.mixin.injection.Inject;
5352
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -57,8 +56,13 @@
5756

5857
@Mixin(value = ClientPlayerEntity.class, priority = Integer.MAX_VALUE)
5958
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity {
60-
@Shadow public Input input;
61-
@Shadow @Final protected MinecraftClient client;
59+
@Shadow
60+
public Input input;
61+
@Shadow
62+
@Final
63+
protected MinecraftClient client;
64+
@Unique
65+
private PlayerPacketEvent.Pre moveEvent;
6266

6367
public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) {
6468
super(world, profile);
@@ -84,36 +88,35 @@ private void injectTickMovement(CallbackInfo ci) {
8488
if (NoJumpCooldown.INSTANCE.isEnabled() || (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getMode() == ElytraFly.FlyMode.Bounce)) jumpingCooldown = 0;
8589
}
8690

87-
@ModifyExpressionValue(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
88-
private float modifyGetYaw(float original) {
89-
final var rot = RotationManager.getHeadYaw();
90-
return rot != null ? rot : original;
91+
@Inject(method = "sendMovementPackets", at = @At("HEAD"))
92+
private void MovementEventPre(CallbackInfo ci) {
93+
moveEvent = EventFlow.post(new PlayerPacketEvent.Pre(pos, RotationManager.getActiveRotation(), isOnGround(), isSprinting(), horizontalCollision));
9194
}
9295

93-
@ModifyExpressionValue(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
94-
private float modifyGetPitch(float original) {
95-
final var rot = RotationManager.getHeadPitch();
96-
return rot != null ? rot : original;
96+
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$Full"))
97+
private PlayerMoveC2SPacket.Full onFullPacket(Vec3d pos, float yaw, float pitch, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.Full> original) {
98+
return original.call(moveEvent.getPosition(), moveEvent.getRotation().getYawF(), moveEvent.getRotation().getPitchF(), moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
9799
}
98100

99-
@ModifyExpressionValue(method = "sendMovementPackets", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;lastYawClient:F", opcode = Opcodes.GETFIELD))
100-
private float modifyLastYawClient(float original) {
101-
return RotationManager.getServerRotation().getYawF();
101+
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$PositionAndOnGround"))
102+
private PlayerMoveC2SPacket.PositionAndOnGround onPositionPacket(Vec3d pos, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.PositionAndOnGround> original) {
103+
return original.call(moveEvent.getPosition(), moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
102104
}
103105

104-
@ModifyExpressionValue(method = "sendMovementPackets", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;lastPitchClient:F", opcode = Opcodes.GETFIELD))
105-
private float modifyLastPitchClient(float original) {
106-
return RotationManager.getServerRotation().getPitchF();
106+
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$LookAndOnGround"))
107+
private PlayerMoveC2SPacket.LookAndOnGround onLookPacket(float yaw, float pitch, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.LookAndOnGround> original) {
108+
return original.call(moveEvent.getRotation().getYawF(), moveEvent.getRotation().getPitchF(), moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
107109
}
108110

109-
@WrapOperation(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V"))
110-
private void wrapSendPacket(ClientPlayNetworkHandler instance, Packet packet, Operation<Void> original) {
111-
PlayerPacketHandler.sendPlayerPackets(packet);
111+
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$OnGroundOnly"))
112+
private PlayerMoveC2SPacket.OnGroundOnly onOnGroundPacket(boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.OnGroundOnly> original) {
113+
return original.call(moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
112114
}
113115

114116
@Inject(method = "sendMovementPackets", at = @At("TAIL"))
115117
private void injectSendMovementPackets(CallbackInfo ci) {
116118
RotationManager.onRotationSend();
119+
EventFlow.post(new PlayerPacketEvent.Post());
117120
}
118121

119122
@ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z"))
@@ -171,6 +174,7 @@ public void damage(float health, CallbackInfo ci) {
171174

172175
/**
173176
* Prevents the game from closing Guis when the player is in a nether portal
177+
*
174178
* <pre>{@code
175179
* if (this.client.currentScreen != null
176180
* && !this.client.currentScreen.shouldPause()

src/main/kotlin/com/lambda/interaction/PlayerPacketHandler.kt

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

src/main/kotlin/com/lambda/module/modules/network/Rubberband.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
package com.lambda.module.modules.network
1919

2020
import com.lambda.event.events.PacketEvent
21+
import com.lambda.event.events.PlayerPacketEvent
2122
import com.lambda.event.listener.SafeListener.Companion.listen
22-
import com.lambda.interaction.PlayerPacketHandler
2323
import com.lambda.module.Module
2424
import com.lambda.module.tag.ModuleTag
2525
import com.lambda.util.Communication.warn
26+
import com.lambda.util.collections.LimitedOrderedSet
2627
import com.lambda.util.math.dist
2728
import com.lambda.util.math.distSq
2829
import com.lambda.util.text.buildText
@@ -43,25 +44,27 @@ object Rubberband : Module(
4344
private val showConnectionState by setting("Show Connection State", true)
4445
private val showRubberbandInfo by setting("Show Rubberband Info", true)
4546

47+
val configurations = LimitedOrderedSet<PlayerPacketEvent.Pre>(100)
48+
4649
init {
4750
listen<PacketEvent.Receive.Pre> { event ->
4851
if (!showRubberbandInfo) return@listen
4952
if (event.packet !is PlayerPositionLookS2CPacket) return@listen
5053

51-
if (PlayerPacketHandler.configurations.isEmpty()) {
54+
if (configurations.isEmpty()) {
5255
this@Rubberband.warn("Position was reverted")
5356
return@listen
5457
}
5558

5659
val newPos = event.packet.change.position
57-
val last = PlayerPacketHandler.configurations.minBy {
60+
val last = configurations.minBy {
5861
it.position distSq newPos
5962
}
6063

6164
this@Rubberband.warn(buildText {
6265
literal("Reverted position by ")
6366
color(Color.YELLOW) {
64-
literal("${PlayerPacketHandler.configurations.toList().asReversed().indexOf(last) + 1}")
67+
literal("${configurations.toList().asReversed().indexOf(last) + 1}")
6568
}
6669
literal(" ticks (deviation: ")
6770
color(Color.YELLOW) {
@@ -70,5 +73,7 @@ object Rubberband : Module(
7073
literal(")")
7174
})
7275
}
76+
77+
listen<PlayerPacketEvent.Pre> { configurations.add(it) }
7378
}
7479
}

0 commit comments

Comments
 (0)