Skip to content

Commit

Permalink
Fix flying ability being lost on gamemode refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 18, 2020
1 parent 02fdfe2 commit 919040c
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -31,10 +32,22 @@

@Mixin(ServerPlayerInteractionManager.class)
public abstract class ServerPlayerInteractionManagerMixin {
@Unique
private static final ThreadLocal<Boolean> PAL_FLYING = new ThreadLocal<>();

@Shadow
public ServerPlayerEntity player;

@Inject(
method = "setGameMode",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/GameMode;setAbilitites(Lnet/minecraft/entity/player/PlayerAbilities;)V"
))
private void saveFlying(GameMode newMode, GameMode previousMode, CallbackInfo info) {
PAL_FLYING.set(player.abilities.flying);
}

@Inject(
method = "setGameMode",
at = @At(
Expand All @@ -43,6 +56,7 @@ public abstract class ServerPlayerInteractionManagerMixin {
shift = AFTER
))
private void keepAbilities(GameMode newMode, GameMode previousMode, CallbackInfo info) {
player.abilities.flying = PAL_FLYING.get(); // will be overruled if unworthy
PlayerAbilityView.of(this.player).refreshAllPalAbilities(false);
}
}

0 comments on commit 919040c

Please sign in to comment.