Use a mixin hook for NetMovingEvents

main
Charlotte Som 2022-03-09 22:27:57 +00:00
parent b0dfd4273b
commit 04186c4d1e
9 changed files with 84 additions and 72 deletions

View File

@ -51,4 +51,5 @@ public abstract class MixinClientPlayerEntity {
private void onInputTick(CallbackInfo ci) {
Hibiscus.bus().fire(PlayerInputTickEvent.INSTANCE);
}
}

View File

@ -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();
}
}

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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>(SendPacketEvent::class.java) {
override fun on(event: SendPacketEvent) {
val packet = event.packet
if (packet is PlayerMoveC2SPacket) {
val player = mc.player!!
requireExtension<MixinExtClientPlayerEntity>(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)
}
}
}
}

View File

@ -22,6 +22,7 @@
"MixinMinecraftClient",
"MixinRenderSectionManager",
"MixinWorldRenderer",
"netmoving.MixinClientPlayerEntity",
"xray.MixinBlock",
"xray.MixinBlockOcclusionCache",
"xray.MixinChunkRenderRebuildTask",