Add command to disable Gravity (#1955)

Allow disabling gravity (flying) for servers that allow this.
/move gravity: show gravity handling status
/move gravity on: enable gravity handling (falling)
/move gravity off: disable gravity handling (flying)

Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
Marko von Oppen 2022-03-06 19:37:27 +01:00 committed by GitHub
parent 288994aeec
commit 8795aab810
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 14 deletions

View file

@ -8,7 +8,7 @@ namespace MinecraftClient.Commands
public class Move : Command public class Move : Command
{ {
public override string CmdName { get { return "move"; } } public override string CmdName { get { return "move"; } }
public override string CmdUsage { get { return "move <on|off|get|up|down|east|west|north|south|x y z> [-f]"; } } public override string CmdUsage { get { return "move <on|off|get|up|down|east|west|north|south|x y z|gravity [on|off]> [-f]"; } }
public override string CmdDesc { get { return "walk or start walking. \"-f\": force unsafe movements like falling or touching fire"; } } public override string CmdDesc { get { return "walk or start walking. \"-f\": force unsafe movements like falling or touching fire"; } }
public override string Run(McClient handler, string command, Dictionary<string, object> localVars) public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
@ -35,6 +35,14 @@ namespace MinecraftClient.Commands
handler.SetTerrainEnabled(false); handler.SetTerrainEnabled(false);
return Translations.Get("cmd.move.disable"); return Translations.Get("cmd.move.disable");
} }
else if (args[0] == "gravity")
{
if (args.Count >= 2)
Settings.GravityEnabled = (args[1] == "on");
if (Settings.GravityEnabled)
return Translations.Get("cmd.move.gravity.enabled");
else return Translations.Get("cmd.move.gravity.disabled");
}
else if (handler.GetTerrainEnabled()) else if (handler.GetTerrainEnabled())
{ {
if (args.Count == 1) if (args.Count == 1)

View file

@ -21,21 +21,24 @@ namespace MinecraftClient.Mapping
/// <returns>Updated location after applying gravity</returns> /// <returns>Updated location after applying gravity</returns>
public static Location HandleGravity(World world, Location location, ref double motionY) public static Location HandleGravity(World world, Location location, ref double motionY)
{ {
Location onFoots = new Location(location.X, Math.Floor(location.Y), location.Z); if (Settings.GravityEnabled)
Location belowFoots = Move(location, Direction.Down);
if (location.Y > Math.Truncate(location.Y) + 0.0001)
{ {
belowFoots = location; Location onFoots = new Location(location.X, Math.Floor(location.Y), location.Z);
belowFoots.Y = Math.Truncate(location.Y); Location belowFoots = Move(location, Direction.Down);
if (location.Y > Math.Truncate(location.Y) + 0.0001)
{
belowFoots = location;
belowFoots.Y = Math.Truncate(location.Y);
}
if (!IsOnGround(world, location) && !IsSwimming(world, location))
{
while (!IsOnGround(world, belowFoots) && belowFoots.Y >= 1)
belowFoots = Move(belowFoots, Direction.Down);
location = Move2Steps(location, belowFoots, ref motionY, true).Dequeue();
}
else if (!(world.GetBlock(onFoots).Type.IsSolid()))
location = Move2Steps(location, onFoots, ref motionY, true).Dequeue();
} }
if (!IsOnGround(world, location) && !IsSwimming(world, location))
{
while (!IsOnGround(world, belowFoots) && belowFoots.Y >= 1)
belowFoots = Move(belowFoots, Direction.Down);
location = Move2Steps(location, belowFoots, ref motionY, true).Dequeue();
}
else if (!(world.GetBlock(onFoots).Type.IsSolid()))
location = Move2Steps(location, onFoots, ref motionY, true).Dequeue();
return location; return location;
} }

View file

@ -311,6 +311,9 @@ cmd.move.dir_fail=Kann nicht in diese Richtung laufen.
cmd.move.walk=Gehe nach {0} cmd.move.walk=Gehe nach {0}
cmd.move.fail=Konnte Pfad nach {0} nicht berechnen. cmd.move.fail=Konnte Pfad nach {0} nicht berechnen.
cmd.move.suggestforce=Weg nach {0} konnte nicht berechnet werden. Benutze den -f Parameter, um unsichere Wege zu aktivieren. cmd.move.suggestforce=Weg nach {0} konnte nicht berechnet werden. Benutze den -f Parameter, um unsichere Wege zu aktivieren.
cmd.move.gravity.enabled=Gravitation ist aktiv.
cmd.move.gravity.disabled=Gravitation ist deaktiviert.
# Reco # Reco
cmd.reco.desc=Starte neu und verbinde erneut zum Server. cmd.reco.desc=Starte neu und verbinde erneut zum Server.

View file

@ -311,6 +311,8 @@ cmd.move.dir_fail=Cannot move in that direction.
cmd.move.walk=Walking to {0} cmd.move.walk=Walking to {0}
cmd.move.fail=Failed to compute path to {0} cmd.move.fail=Failed to compute path to {0}
cmd.move.suggestforce=Failed to compute a safe path to {0}. Try -f parameter to allow unsafe movements. cmd.move.suggestforce=Failed to compute a safe path to {0}. Try -f parameter to allow unsafe movements.
cmd.move.gravity.enabled=Gravity is enabled.
cmd.move.gravity.disabled=Gravity is disabled.
# Reco # Reco
cmd.reco.desc=restart and reconnect to the server. cmd.reco.desc=restart and reconnect to the server.

View file

@ -311,6 +311,8 @@ cmd.move.dir_fail=Impossible de se déplacer dans cette direction.
cmd.move.walk=Marche vers {0} cmd.move.walk=Marche vers {0}
cmd.move.fail=Échec de calcul du chemin vers {0} cmd.move.fail=Échec de calcul du chemin vers {0}
cmd.move.suggestforce=Échec de calcul du chemin vers {0}. Utilisez -f pour autoriser les mouvements risqués. cmd.move.suggestforce=Échec de calcul du chemin vers {0}. Utilisez -f pour autoriser les mouvements risqués.
cmd.move.gravity.enabled=La gravité est activée.
cmd.move.gravity.disabled=La gravité est désactivée.
# Reco # Reco
cmd.reco.desc=Relancer le programme et se reconnecter au serveur cmd.reco.desc=Relancer le programme et se reconnecter au serveur

View file

@ -93,6 +93,7 @@ namespace MinecraftClient
public static bool DisplayChatLinks = true; public static bool DisplayChatLinks = true;
public static bool DisplayInventoryLayout = true; public static bool DisplayInventoryLayout = true;
public static bool TerrainAndMovements = false; public static bool TerrainAndMovements = false;
public static bool GravityEnabled = true;
public static bool InventoryHandling = false; public static bool InventoryHandling = false;
public static string PrivateMsgsCmdName = "tell"; public static string PrivateMsgsCmdName = "tell";
public static CacheType SessionCaching = CacheType.Disk; public static CacheType SessionCaching = CacheType.Disk;