diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerEntity.java b/src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerEntity.java index d0d0d1e..a709099 100644 --- a/src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerEntity.java +++ b/src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerEntity.java @@ -51,4 +51,5 @@ public abstract class MixinClientPlayerEntity { private void onInputTick(CallbackInfo ci) { Hibiscus.bus().fire(PlayerInputTickEvent.INSTANCE); } + } diff --git a/src/main/java/codes/som/hibiscus/mixins/netmoving/MixinClientPlayerEntity.java b/src/main/java/codes/som/hibiscus/mixins/netmoving/MixinClientPlayerEntity.java new file mode 100644 index 0000000..c0f2626 --- /dev/null +++ b/src/main/java/codes/som/hibiscus/mixins/netmoving/MixinClientPlayerEntity.java @@ -0,0 +1,75 @@ +package codes.som.hibiscus.mixins.netmoving; + +import codes.som.hibiscus.Hibiscus; +import codes.som.hibiscus.events.NetworkMovingEvent; +import com.mojang.authlib.GameProfile; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.world.ClientWorld; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPlayerEntity.class) +public class MixinClientPlayerEntity extends AbstractClientPlayerEntity { + private NetworkMovingEvent lastNetworkMovingEvent; + + public MixinClientPlayerEntity(ClientWorld clientWorld, GameProfile gameProfile) { + super(clientWorld, gameProfile); + throw new IllegalStateException(); + } + + @Inject(method = "sendMovementPackets", at = @At("HEAD")) + private void onSendMovementPackets(CallbackInfo ci) { + lastNetworkMovingEvent = new NetworkMovingEvent( + this.getX(), this.getY(), this.getZ(), + this.getYaw(), this.getPitch(), + this.isOnGround(), + this.isSneaking(), this.isSprinting() + ); + + Hibiscus.bus().fire(lastNetworkMovingEvent); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getX()D")) + private double onGetX(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getX(); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getY()D")) + private double onGetY(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getY(); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getZ()D")) + private double onGetZ(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getZ(); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F")) + private float onGetYaw(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getYaw(); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F")) + private float onGetPitch(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getPitch(); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSneaking()Z")) + private boolean onGetSneaking(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getSneaking(); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z")) + private boolean onGetSprinting(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getSprinting(); + } + + @Redirect(method = "sendMovementPackets", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;onGround:Z")) + private boolean onGetOnGround(ClientPlayerEntity instance) { + return lastNetworkMovingEvent.getOnGround(); + } +} diff --git a/src/main/kotlin/codes/som/hibiscus/Hibiscus.kt b/src/main/kotlin/codes/som/hibiscus/Hibiscus.kt index 6a7a833..c730edb 100644 --- a/src/main/kotlin/codes/som/hibiscus/Hibiscus.kt +++ b/src/main/kotlin/codes/som/hibiscus/Hibiscus.kt @@ -1,7 +1,6 @@ package codes.som.hibiscus import codes.som.hibiscus.api.event.EventBus -import codes.som.hibiscus.api.event.EventPhase import codes.som.hibiscus.api.keybinds.KeybindRegistry import codes.som.hibiscus.commands.CommandRegistry import codes.som.hibiscus.data.DataManager @@ -18,7 +17,6 @@ import codes.som.hibiscus.subsystems.accounts.AccountsSubsystem import codes.som.hibiscus.subsystems.tps.TPSDetectionSubsystem import codes.som.hibiscus.util.command.ChatCommandListener import codes.som.hibiscus.util.input.KeybindDispatcher -import codes.som.hibiscus.util.netmoving.NetworkMovingDispatcher import net.fabricmc.api.ModInitializer import net.minecraft.client.gui.screen.TitleScreen import org.lwjgl.glfw.GLFW @@ -55,7 +53,6 @@ object Hibiscus : ModInitializer { } } - bus.register(NetworkMovingDispatcher(), EventPhase.AFTER) bus.register(ChatCommandListener()) bus.register(KeybindDispatcher()) TPSDetectionSubsystem.setup() diff --git a/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt b/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt index 4394fa7..437a1e7 100644 --- a/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt +++ b/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt @@ -13,5 +13,7 @@ class NetworkMovingEvent( var z: Double, var yaw: Float, var pitch: Float, - var onGround: Boolean + var onGround: Boolean, + var sneaking: Boolean, + var sprinting: Boolean, ) : Cancellable(), Event diff --git a/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt b/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt index e21bc47..2d23e65 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt @@ -52,7 +52,7 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) { } on(cond = { mode != FlightMode.VANILLA }) { _: PlayerInputTickEvent -> - player.input.sneaking = false + // player.input.sneaking = false } var lastMoveTime: Long = -1 @@ -106,7 +106,7 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) { if (flyKickCounter >= 16) { if (flyKickCounter == 16) - lockY = event.y - 0.03126 + lockY = event.y - 0.0625 val playerNotColliding = world.getBlockCollisions( null, player.boundingBox diff --git a/src/main/kotlin/codes/som/hibiscus/gui/screens/AccountManagerUIScreen.kt b/src/main/kotlin/codes/som/hibiscus/gui/screens/AccountManagerUIScreen.kt index 674598e..438c2d7 100644 --- a/src/main/kotlin/codes/som/hibiscus/gui/screens/AccountManagerUIScreen.kt +++ b/src/main/kotlin/codes/som/hibiscus/gui/screens/AccountManagerUIScreen.kt @@ -45,7 +45,7 @@ object AccountManagerUIScreen : Screen(Text.of("account management hacker menu") } val calculatedHeight = (accounts.size.coerceIn(4, 20) * 28f) - if (ImGui.beginListBox("Accounts", 0f, calculatedHeight)) { + if (ImGui.beginListBox("##Accounts List", 0f, calculatedHeight)) { for (account in accounts) { if (ImGui.selectable(account.name, account.id.value == selectedAccountId)) { selectedAccountId = account.id.value diff --git a/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt b/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt index 3cbc54e..18443f3 100644 --- a/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt +++ b/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt @@ -14,7 +14,7 @@ fun getMoveInputVecFromPlayerInput(input: Input): Vec3d { if (input.sneaking) y -= 1.0 - return Vec3d(input.sidewaysMovement.toDouble().sign, y, input.forwardMovement.toDouble().sign) + return Vec3d(-input.sidewaysMovement.toDouble().sign, y, input.forwardMovement.toDouble().sign) } fun getMoveInputVecFromKeys(): Vec3d { diff --git a/src/main/kotlin/codes/som/hibiscus/util/netmoving/NetworkMovingEvent.kt b/src/main/kotlin/codes/som/hibiscus/util/netmoving/NetworkMovingEvent.kt deleted file mode 100644 index 65a12e5..0000000 --- a/src/main/kotlin/codes/som/hibiscus/util/netmoving/NetworkMovingEvent.kt +++ /dev/null @@ -1,64 +0,0 @@ -package codes.som.hibiscus.util.netmoving - -import codes.som.hibiscus.Hibiscus -import codes.som.hibiscus.api.event.TypedListener -import codes.som.hibiscus.events.NetworkMovingEvent -import codes.som.hibiscus.events.SendPacketEvent -import codes.som.hibiscus.mc -import codes.som.hibiscus.mixins.MixinExtClientPlayerEntity -import codes.som.hibiscus.util.ext.requireExtension -import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket - -class NetworkMovingDispatcher : TypedListener(SendPacketEvent::class.java) { - override fun on(event: SendPacketEvent) { - val packet = event.packet - if (packet is PlayerMoveC2SPacket) { - val player = mc.player!! - requireExtension(player) - - val movingEvent = NetworkMovingEvent( - packet.getX(player.x), packet.getY(player.y), packet.getZ(player.z), - packet.getYaw(player.yaw), packet.getPitch(player.pitch), packet.isOnGround - ) - - Hibiscus.bus.fire(movingEvent) - - if (movingEvent.cancelled) - event.cancel() - - val moving = - movingEvent.x != player.lastX || movingEvent.y != player.lastBaseY || movingEvent.z != player.lastZ - val rotating = movingEvent.yaw != player.lastYaw || movingEvent.pitch != player.lastPitch - - player.lastX = movingEvent.x - player.lastBaseY = movingEvent.y - player.lastZ = movingEvent.z - - player.lastYaw = movingEvent.yaw - player.lastPitch = movingEvent.pitch - - event.packet = when { - moving && rotating -> PlayerMoveC2SPacket.Full( - movingEvent.x, - movingEvent.y, - movingEvent.z, - movingEvent.yaw, - movingEvent.pitch, - movingEvent.onGround - ) - moving -> PlayerMoveC2SPacket.PositionAndOnGround( - movingEvent.x, - movingEvent.y, - movingEvent.z, - movingEvent.onGround - ) - rotating -> PlayerMoveC2SPacket.LookAndOnGround( - movingEvent.yaw, - movingEvent.pitch, - movingEvent.onGround - ) - else -> PlayerMoveC2SPacket.OnGroundOnly(movingEvent.onGround) - } - } - } -} diff --git a/src/main/resources/hibiscus.mixins.json b/src/main/resources/hibiscus.mixins.json index 406efac..f7433fc 100644 --- a/src/main/resources/hibiscus.mixins.json +++ b/src/main/resources/hibiscus.mixins.json @@ -22,6 +22,7 @@ "MixinMinecraftClient", "MixinRenderSectionManager", "MixinWorldRenderer", + "netmoving.MixinClientPlayerEntity", "xray.MixinBlock", "xray.MixinBlockOcclusionCache", "xray.MixinChunkRenderRebuildTask",