1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Ryan Fox cbea81f9ce
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. :-)
2020-10-28 00:24:51 +00:00
Ryan Fox 037342e553
Add config value for persistent flight 2020-10-27 23:48:38 +00:00
4 changed files with 43 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

@ -35,6 +35,7 @@ public class Config {
json = new JSONObject();
}
setDefault("persistentFlight", true);
setDefault("disableTntExplosions", false);
setDefault("disableRespawnAnchorExplosions", false);
setDefault("iphubApiKey", "");

View File

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