Skip to content

Commit

Permalink
Fix magboots not needing a grid to work (#29034)
Browse files Browse the repository at this point in the history
* Fix magboots not needing a grid to work

* ok fix it for realsies
  • Loading branch information
EmoGarbage404 authored and sleepyyapril committed Jan 2, 2025
1 parent 1329ab9 commit b3f917e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Content.Shared/Clothing/MagbootsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void OnIsWeightless(Entity<MagbootsComponent> 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;
Expand Down
32 changes: 28 additions & 4 deletions Content.Shared/Gravity/SharedGravitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public abstract partial class SharedGravitySystem : EntitySystem
[ValidatePrototypeId<AlertPrototype>]
public const string WeightlessAlert = "Weightless";

private EntityQuery<GravityComponent> _gravityQuery;

public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, TransformComponent? xform = null)
{
Resolve(uid, ref body, false);
Expand All @@ -40,15 +42,35 @@ public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, Transform
return true;

// If grid / map has gravity
if (TryComp<GravityComponent>(xform.GridUid, out var gravity) && gravity.Enabled ||
TryComp<GravityComponent>(xform.MapUid, out var mapGravity) && mapGravity.Enabled)
{
if (EntityGridOrMapHaveGravity((uid, xform)))
return false;
}

return true;
}

/// <summary>
/// Checks if a given entity is currently standing on a grid or map that supports having gravity at all.
/// </summary>
public bool EntityOnGravitySupportingGridOrMap(Entity<TransformComponent?> entity)
{
entity.Comp ??= Transform(entity);

return _gravityQuery.HasComp(entity.Comp.GridUid) ||
_gravityQuery.HasComp(entity.Comp.MapUid);
}


/// <summary>
/// Checks if a given entity is currently standing on a grid or map that has gravity of some kind.
/// </summary>
public bool EntityGridOrMapHaveGravity(Entity<TransformComponent?> 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();
Expand All @@ -58,6 +80,8 @@ public override void Initialize()
SubscribeLocalEvent<GravityChangedEvent>(OnGravityChange);
SubscribeLocalEvent<GravityComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<GravityComponent, ComponentHandleState>(OnHandleState);

_gravityQuery = GetEntityQuery<GravityComponent>();
}

public override void Update(float frameTime)
Expand Down

0 comments on commit b3f917e

Please sign in to comment.