From d8f8f96610c4ae396b74f34e40714da6d3619939 Mon Sep 17 00:00:00 2001 From: hhhzzzsss Date: Sun, 26 May 2024 01:11:09 -0500 Subject: [PATCH] Fixed flying consistency issue --- .../songplayer/CommandProcessor.java | 2 +- .../mixin/ClientPlayNetworkHandlerMixin.java | 2 +- .../mixin/ClientPlayerEntityMixin.java | 21 +++++++++++++++++++ .../songplayer/playing/SongHandler.java | 13 ++++++------ src/main/resources/songplayer.mixins.json | 1 + 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayerEntityMixin.java diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java index 3150b38..1840b35 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java @@ -253,7 +253,7 @@ public class CommandProcessor { SongHandler.getInstance().restoreStateAndReset(); SongPlayer.addChatMessage("§6Stopped cleanup"); } else if (Config.getConfig().autoCleanup && SongHandler.getInstance().originalBlocks.size() != 0) { - SongHandler.getInstance().partionResetAndCleanup(); + SongHandler.getInstance().partialResetAndCleanup(); SongPlayer.addChatMessage("§6Stopped playing and switched to cleanup"); } else { SongHandler.getInstance().restoreStateAndReset(); 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 7a03fa8..40f92cb 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java @@ -71,7 +71,7 @@ public class ClientPlayNetworkHandlerMixin { @Inject(at = @At("TAIL"), method = "onPlayerAbilities(Lnet/minecraft/network/packet/s2c/play/PlayerAbilitiesS2CPacket;)V") public void onOnPlayerAbilities(PlayerAbilitiesS2CPacket packet, CallbackInfo ci) { SongHandler handler = SongHandler.getInstance(); - if (handler.wasFlying) { + if (!handler.isIdle()) { SongPlayer.MC.player.getAbilities().flying = handler.wasFlying; } } diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayerEntityMixin.java b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayerEntityMixin.java new file mode 100644 index 0000000..ea86428 --- /dev/null +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayerEntityMixin.java @@ -0,0 +1,21 @@ +package com.github.hhhzzzsss.songplayer.mixin; + +import com.github.hhhzzzsss.songplayer.playing.SongHandler; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.entity.player.PlayerAbilities; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ClientPlayerEntity.class) +public class ClientPlayerEntityMixin { + @Redirect(method = "tickMovement()V", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerAbilities;allowFlying:Z", opcode = Opcodes.GETFIELD)) + private boolean getAllowFlying(PlayerAbilities playerAbilities) { + if (!SongHandler.getInstance().isIdle()) { + return true; + } else { + return playerAbilities.allowFlying; + } + } +} diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java index 86b7f01..7830c72 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java @@ -116,16 +116,14 @@ public class SongHandler { SongPlayer.fakePlayer.getInventory().clone(SongPlayer.MC.player.getInventory()); } - // Allow flying - SongPlayer.MC.player.getAbilities().allowFlying = true; + // Maintain flying status wasFlying = SongPlayer.MC.player.getAbilities().flying; } // Check if doing cleanup if (cleaningUp) { if (tick) { - // Allow flying while doing cleanup - SongPlayer.MC.player.getAbilities().allowFlying = true; + // Maintain flying status wasFlying = SongPlayer.MC.player.getAbilities().flying; handleCleanup(); @@ -153,7 +151,7 @@ public class SongHandler { else { if (dirty) { if (Config.getConfig().autoCleanup && originalBlocks.size() != 0) { - partionResetAndCleanup(); + partialResetAndCleanup(); } else { restoreStateAndReset(); } @@ -634,10 +632,13 @@ public class SongHandler { sendGamemodeCommand(Config.getConfig().survivalCommand); } } + if (SongPlayer.MC.player.getAbilities().allowFlying == false) { + SongPlayer.MC.player.getAbilities().flying = false; + } restoreBuildSlot(); reset(); } - public void partionResetAndCleanup() { + public void partialResetAndCleanup() { restoreBuildSlot(); currentSong = null; currentPlaylist = null; diff --git a/src/main/resources/songplayer.mixins.json b/src/main/resources/songplayer.mixins.json index 98094e1..23d100f 100644 --- a/src/main/resources/songplayer.mixins.json +++ b/src/main/resources/songplayer.mixins.json @@ -8,6 +8,7 @@ "client": [ "ChatInputSuggestorMixin", "ClientCommonNetworkHandlerMixin", + "ClientPlayerEntityMixin", "ClientPlayerInteractionManagerAccessor", "ClientPlayNetworkHandlerAccessor", "ClientPlayNetworkHandlerMixin",