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

View file

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

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

View file

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