diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/PlayerMoveMixin.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/PlayerMoveMixin.java new file mode 100644 index 0000000..c4eadd3 --- /dev/null +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/PlayerMoveMixin.java @@ -0,0 +1,20 @@ +package org.muellerssoftware.openproximitychatfabric.mixins; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +@Mixin(PlayerMoveC2SPacket.class) +public class PlayerMoveMixin { + @ModifyArgs(method = "(DDDFFZZZ)V", at = @At("HEAD")) + private static void doHandshake(Args args) { + if (ViewLock.isLocked()) { + if (MinecraftClient.getInstance().player == null) return; + args.set(3, ViewLock.yaw); + args.set(4, ViewLock.pitch); + } + } +} diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/TickMixin.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/TickMixin.java new file mode 100644 index 0000000..e8d27f8 --- /dev/null +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/TickMixin.java @@ -0,0 +1,37 @@ +package org.muellerssoftware.openproximitychatfabric.mixins; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; +import org.muellerssoftware.openproximitychatfabric.connect.Stage1HandshakeBuilder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(PlayerEntity.class) +public class TickMixin { + private static Stage1HandshakeBuilder.Movement[] movements = { + new Stage1HandshakeBuilder.Movement(0.031, 0.041), + new Stage1HandshakeBuilder.Movement(-0.059, -0.026), + new Stage1HandshakeBuilder.Movement(0.053, 0.058), + new Stage1HandshakeBuilder.Movement(-0.097, -0.093), + new Stage1HandshakeBuilder.Movement(0.023, 0.084), + new Stage1HandshakeBuilder.Movement(0.049, -0.064), + new Stage1HandshakeBuilder.Movement(0.033, 0.083), + new Stage1HandshakeBuilder.Movement(-0.033, -0.083), + new Stage1HandshakeBuilder.Movement(0.027, 0.095), + new Stage1HandshakeBuilder.Movement(-0.027, -0.095), + new Stage1HandshakeBuilder.Movement(0.032, 0), + new Stage1HandshakeBuilder.Movement(-0.032, -0) + }; + + @Inject(method = "tick()V", at = @At("TAIL")) + private void sendMovePacket(CallbackInfo ci) { + Entity entity = (Entity)(Object)this; + ViewLock.setLocked(false); + MinecraftClient.getInstance().player.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(entity.getX(), entity.getY(), entity.getZ(), entity.getYaw(), entity.getPitch(), entity.isOnGround())); + ViewLock.setLocked(true); + } +} diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/ViewLock.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/ViewLock.java new file mode 100644 index 0000000..4260a35 --- /dev/null +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/ViewLock.java @@ -0,0 +1,23 @@ +package org.muellerssoftware.openproximitychatfabric.mixins; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; + +public class ViewLock { + private static boolean locked; + public static float yaw; + public static float pitch; + + public static boolean isLocked() { + return locked; + } + + public static void setLocked(boolean locked) { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + if (player != null) { + yaw = player.getYaw(); + pitch = player.getPitch(); + ViewLock.locked = locked; + } + } +} diff --git a/src/main/resources/OpenProximityChatFabric.mixins.json b/src/main/resources/OpenProximityChatFabric.mixins.json index 1f5255f..53eee69 100644 --- a/src/main/resources/OpenProximityChatFabric.mixins.json +++ b/src/main/resources/OpenProximityChatFabric.mixins.json @@ -6,7 +6,9 @@ "mixins": [ ], "client": [ - "ClientPlayNetworkHandlerMixin" + "ClientPlayNetworkHandlerMixin", + "PlayerMoveMixin", + "TickMixin" ], "injectors": { "defaultRequire": 1