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:
parent
037342e553
commit
cbea81f9ce
32
src/main/java/party/_2a03/mc/mixin/MixinGameMode.java
Normal file
32
src/main/java/party/_2a03/mc/mixin/MixinGameMode.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
"package": "party._2a03.mc.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"server": [
|
||||
"MixinGameMode",
|
||||
"MixinGameModeCommand",
|
||||
"MixinRespawnAnchorBlock",
|
||||
"MixinServerPlayerEntity",
|
||||
|
Loading…
x
Reference in New Issue
Block a user