Fixed flying consistency issue

This commit is contained in:
hhhzzzsss 2024-05-26 01:11:09 -05:00
parent 282a7ea451
commit d8f8f96610
5 changed files with 31 additions and 8 deletions

View file

@ -253,7 +253,7 @@ public class CommandProcessor {
SongHandler.getInstance().restoreStateAndReset(); SongHandler.getInstance().restoreStateAndReset();
SongPlayer.addChatMessage("§6Stopped cleanup"); SongPlayer.addChatMessage("§6Stopped cleanup");
} else if (Config.getConfig().autoCleanup && SongHandler.getInstance().originalBlocks.size() != 0) { } else if (Config.getConfig().autoCleanup && SongHandler.getInstance().originalBlocks.size() != 0) {
SongHandler.getInstance().partionResetAndCleanup(); SongHandler.getInstance().partialResetAndCleanup();
SongPlayer.addChatMessage("§6Stopped playing and switched to cleanup"); SongPlayer.addChatMessage("§6Stopped playing and switched to cleanup");
} else { } else {
SongHandler.getInstance().restoreStateAndReset(); SongHandler.getInstance().restoreStateAndReset();

View file

@ -71,7 +71,7 @@ public class ClientPlayNetworkHandlerMixin {
@Inject(at = @At("TAIL"), method = "onPlayerAbilities(Lnet/minecraft/network/packet/s2c/play/PlayerAbilitiesS2CPacket;)V") @Inject(at = @At("TAIL"), method = "onPlayerAbilities(Lnet/minecraft/network/packet/s2c/play/PlayerAbilitiesS2CPacket;)V")
public void onOnPlayerAbilities(PlayerAbilitiesS2CPacket packet, CallbackInfo ci) { public void onOnPlayerAbilities(PlayerAbilitiesS2CPacket packet, CallbackInfo ci) {
SongHandler handler = SongHandler.getInstance(); SongHandler handler = SongHandler.getInstance();
if (handler.wasFlying) { if (!handler.isIdle()) {
SongPlayer.MC.player.getAbilities().flying = handler.wasFlying; SongPlayer.MC.player.getAbilities().flying = handler.wasFlying;
} }
} }

View file

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

View file

@ -116,16 +116,14 @@ public class SongHandler {
SongPlayer.fakePlayer.getInventory().clone(SongPlayer.MC.player.getInventory()); SongPlayer.fakePlayer.getInventory().clone(SongPlayer.MC.player.getInventory());
} }
// Allow flying // Maintain flying status
SongPlayer.MC.player.getAbilities().allowFlying = true;
wasFlying = SongPlayer.MC.player.getAbilities().flying; wasFlying = SongPlayer.MC.player.getAbilities().flying;
} }
// Check if doing cleanup // Check if doing cleanup
if (cleaningUp) { if (cleaningUp) {
if (tick) { if (tick) {
// Allow flying while doing cleanup // Maintain flying status
SongPlayer.MC.player.getAbilities().allowFlying = true;
wasFlying = SongPlayer.MC.player.getAbilities().flying; wasFlying = SongPlayer.MC.player.getAbilities().flying;
handleCleanup(); handleCleanup();
@ -153,7 +151,7 @@ public class SongHandler {
else { else {
if (dirty) { if (dirty) {
if (Config.getConfig().autoCleanup && originalBlocks.size() != 0) { if (Config.getConfig().autoCleanup && originalBlocks.size() != 0) {
partionResetAndCleanup(); partialResetAndCleanup();
} else { } else {
restoreStateAndReset(); restoreStateAndReset();
} }
@ -634,10 +632,13 @@ public class SongHandler {
sendGamemodeCommand(Config.getConfig().survivalCommand); sendGamemodeCommand(Config.getConfig().survivalCommand);
} }
} }
if (SongPlayer.MC.player.getAbilities().allowFlying == false) {
SongPlayer.MC.player.getAbilities().flying = false;
}
restoreBuildSlot(); restoreBuildSlot();
reset(); reset();
} }
public void partionResetAndCleanup() { public void partialResetAndCleanup() {
restoreBuildSlot(); restoreBuildSlot();
currentSong = null; currentSong = null;
currentPlaylist = null; currentPlaylist = null;

View file

@ -8,6 +8,7 @@
"client": [ "client": [
"ChatInputSuggestorMixin", "ChatInputSuggestorMixin",
"ClientCommonNetworkHandlerMixin", "ClientCommonNetworkHandlerMixin",
"ClientPlayerEntityMixin",
"ClientPlayerInteractionManagerAccessor", "ClientPlayerInteractionManagerAccessor",
"ClientPlayNetworkHandlerAccessor", "ClientPlayNetworkHandlerAccessor",
"ClientPlayNetworkHandlerMixin", "ClientPlayNetworkHandlerMixin",