diff --git a/Content.Shared/Clothing/MagbootsSystem.cs b/Content.Shared/Clothing/MagbootsSystem.cs index ef5ac671e42..d41f27fefb0 100644 --- a/Content.Shared/Clothing/MagbootsSystem.cs +++ b/Content.Shared/Clothing/MagbootsSystem.cs @@ -76,7 +76,7 @@ private void OnIsWeightless(Entity ent, ref IsWeightlessEvent return; // do not cancel weightlessness if the person is in off-grid. - if (ent.Comp.RequiresGrid && !_gravity.IsWeightless(ent.Owner)) + if (ent.Comp.RequiresGrid && !_gravity.EntityOnGravitySupportingGridOrMap(ent.Owner)) return; args.IsWeightless = false; diff --git a/Content.Shared/Gravity/SharedGravitySystem.cs b/Content.Shared/Gravity/SharedGravitySystem.cs index f9c65e9477b..7c9d3924655 100644 --- a/Content.Shared/Gravity/SharedGravitySystem.cs +++ b/Content.Shared/Gravity/SharedGravitySystem.cs @@ -18,6 +18,8 @@ public abstract partial class SharedGravitySystem : EntitySystem [ValidatePrototypeId] public const string WeightlessAlert = "Weightless"; + private EntityQuery _gravityQuery; + public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, TransformComponent? xform = null) { Resolve(uid, ref body, false); @@ -40,15 +42,35 @@ public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, Transform return true; // If grid / map has gravity - if (TryComp(xform.GridUid, out var gravity) && gravity.Enabled || - TryComp(xform.MapUid, out var mapGravity) && mapGravity.Enabled) - { + if (EntityGridOrMapHaveGravity((uid, xform))) return false; - } return true; } + /// + /// Checks if a given entity is currently standing on a grid or map that supports having gravity at all. + /// + public bool EntityOnGravitySupportingGridOrMap(Entity entity) + { + entity.Comp ??= Transform(entity); + + return _gravityQuery.HasComp(entity.Comp.GridUid) || + _gravityQuery.HasComp(entity.Comp.MapUid); + } + + + /// + /// Checks if a given entity is currently standing on a grid or map that has gravity of some kind. + /// + public bool EntityGridOrMapHaveGravity(Entity entity) + { + entity.Comp ??= Transform(entity); + + return _gravityQuery.TryComp(entity.Comp.GridUid, out var gravity) && gravity.Enabled || + _gravityQuery.TryComp(entity.Comp.MapUid, out var mapGravity) && mapGravity.Enabled; + } + public override void Initialize() { base.Initialize(); @@ -58,6 +80,8 @@ public override void Initialize() SubscribeLocalEvent(OnGravityChange); SubscribeLocalEvent(OnGetState); SubscribeLocalEvent(OnHandleState); + + _gravityQuery = GetEntityQuery(); } public override void Update(float frameTime)