1
0
Fork 0

Add persistent flight

When a player disconnects while flying in survival mode, they will
plummet to their deaths while reconnecting. These changes prevent that.
If a player is currently flying, their flight will not be disabled
unless the setGameMode method is called in the ServerPlayerEntity, which
is how the GameMode is usually set. Since the GameMode is initially set
using the interaction manager instead, players should be safe. :-)
This commit is contained in:
Ryan Fox 2020-10-28 00:24:51 +00:00
parent 037342e553
commit cbea81f9ce
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package party._2a03.mc.mixin;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import party._2a03.mc.util.Config;
@Mixin(GameMode.class)
public class MixinGameMode {
private boolean flying;
@Inject(method = "setAbilities", at = @At("HEAD"))
public void checkFlight(PlayerAbilities abilities, CallbackInfo ci) {
this.flying = abilities.flying;
}
@Inject(method = "setAbilities", at = @At("TAIL"))
public void restoreFlight(PlayerAbilities abilities, CallbackInfo ci) {
if (!Config.getBool("persistentFlight"))
return;
if (abilities.flying)
return;
if (this.flying) {
abilities.allowFlying = true;
abilities.flying = true;
}
}
}

View File

@ -3,6 +3,7 @@ package party._2a03.mc.mixin;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -29,4 +30,12 @@ public abstract class MixinServerPlayerEntity extends PlayerEntity {
ci.cancel();
}
}
@Inject(method = "setGameMode", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendAbilitiesUpdate()V"))
public void disableFlightIfSafe(GameMode gameMode, CallbackInfo ci) {
if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR) {
this.abilities.allowFlying = false;
this.abilities.flying = false;
}
}
}

View File

@ -3,6 +3,7 @@
"package": "party._2a03.mc.mixin",
"compatibilityLevel": "JAVA_8",
"server": [
"MixinGameMode",
"MixinGameModeCommand",
"MixinRespawnAnchorBlock",
"MixinServerPlayerEntity",