From fd2b089e90c6c79e27a0777cb8d172c5d064e6e3 Mon Sep 17 00:00:00 2001 From: hhhzzzsss Date: Thu, 23 May 2024 16:42:27 -0500 Subject: [PATCH] Cancel velocity while playing songs --- .../mixin/ClientPlayNetworkHandlerMixin.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java index 95c592f..d8843c3 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java @@ -5,10 +5,7 @@ import com.github.hhhzzzsss.songplayer.SongPlayer; import com.github.hhhzzzsss.songplayer.playing.SongHandler; import com.github.hhhzzzsss.songplayer.playing.Stage; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; +import net.minecraft.network.packet.s2c.play.*; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -51,4 +48,11 @@ public class ClientPlayNetworkHandlerMixin { SongPlayer.MC.player.getAbilities().flying = handler.wasFlying; } } + + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setVelocityClient(DDD)V"), method = "onEntityVelocityUpdate", cancellable = true) + public void onOnEntityVelocityUpdate(EntityVelocityUpdateS2CPacket packet, CallbackInfo ci) { + if (!SongHandler.getInstance().isIdle() && packet.getId() == SongPlayer.MC.player.getId()) { + ci.cancel(); + } + } }