diff --git a/Content.Client/GameObjects/Components/Items/HandsComponent.cs b/Content.Client/GameObjects/Components/Items/HandsComponent.cs index 654f7e6c0c..21f112d031 100644 --- a/Content.Client/GameObjects/Components/Items/HandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/HandsComponent.cs @@ -55,7 +55,7 @@ namespace Content.Client.GameObjects.Components.Items return Hands.FirstOrDefault(hand => hand.Name == name); } - private bool TryHand(string name, [MaybeNullWhen(false)] out Hand hand) + private bool TryHand(string name, [NotNullWhen(true)] out Hand? hand) { return (hand = GetHand(name)) != null; } diff --git a/Content.Server/Atmos/AtmosHelpers.cs b/Content.Server/Atmos/AtmosHelpers.cs index f0bdeab213..2761bf3457 100644 --- a/Content.Server/Atmos/AtmosHelpers.cs +++ b/Content.Server/Atmos/AtmosHelpers.cs @@ -13,7 +13,7 @@ namespace Content.Server.Atmos { public static class AtmosHelpers { - public static TileAtmosphere GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null) + public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null) { entityManager ??= IoCManager.Resolve(); @@ -24,19 +24,19 @@ namespace Content.Server.Atmos public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null) { - return coordinates.GetTileAtmosphere(entityManager).Air; + return coordinates.GetTileAtmosphere(entityManager)?.Air; } - public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [MaybeNullWhen(false)] out TileAtmosphere atmosphere) + public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse - return !Equals(atmosphere = coordinates.GetTileAtmosphere()!, default); + return !Equals(atmosphere = coordinates.GetTileAtmosphere(), default); } - public static bool TryGetTileAir(this EntityCoordinates coordinates, [MaybeNullWhen(false)] out GasMixture air, IEntityManager? entityManager = null) + public static bool TryGetTileAir(this EntityCoordinates coordinates, [NotNullWhen(true)] out GasMixture? air, IEntityManager? entityManager = null) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse - return !Equals(air = coordinates.GetTileAir(entityManager)!, default); + return !Equals(air = coordinates.GetTileAir(entityManager), default); } public static bool IsTileAirProbablySafe(this EntityCoordinates coordinates) @@ -56,7 +56,7 @@ namespace Content.Server.Atmos return true; } - public static TileAtmosphere GetTileAtmosphere(this Vector2i indices, GridId gridId) + public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId) { var gridAtmos = EntitySystem.Get().GetGridAtmosphere(gridId); @@ -69,28 +69,25 @@ namespace Content.Server.Atmos } public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId, - [MaybeNullWhen(false)] out TileAtmosphere atmosphere) + [NotNullWhen(true)] out TileAtmosphere? atmosphere) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse - return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default); + return !Equals(atmosphere = indices.GetTileAtmosphere(gridId), default); } - public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air) + public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [NotNullWhen(true)] out GasMixture? air) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse - return !Equals(air = indices.GetTileAir(gridId)!, default); + return !Equals(air = indices.GetTileAir(gridId), default); } public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null) { - return InvalidateTileAir(transform.Coordinates, atmosSystem); + return InvalidateTileAir(transform.Coordinates); } - public static bool InvalidateTileAir(this EntityCoordinates coordinates, AtmosphereSystem? atmosSystem = null, IEntityManager? entityManager = null) + public static bool InvalidateTileAir(this EntityCoordinates coordinates) { - atmosSystem ??= EntitySystem.Get(); - entityManager ??= IoCManager.Resolve(); - if (!coordinates.TryGetTileAtmosphere(out var tileAtmos)) { return false; diff --git a/Content.Server/Atmos/IGridAtmosphereComponent.cs b/Content.Server/Atmos/IGridAtmosphereComponent.cs index c84dd507e9..016551464c 100644 --- a/Content.Server/Atmos/IGridAtmosphereComponent.cs +++ b/Content.Server/Atmos/IGridAtmosphereComponent.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#nullable enable +using System.Collections.Generic; using Content.Server.GameObjects.Components.Atmos; using Content.Server.GameObjects.Components.Atmos.Piping; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; @@ -120,7 +121,7 @@ namespace Content.Server.Atmos /// /// /// - TileAtmosphere GetTile(Vector2i indices, bool createSpace = true); + TileAtmosphere? GetTile(Vector2i indices, bool createSpace = true); /// /// Returns a tile. @@ -128,7 +129,7 @@ namespace Content.Server.Atmos /// /// /// - TileAtmosphere GetTile(EntityCoordinates coordinates, bool createSpace = true); + TileAtmosphere? GetTile(EntityCoordinates coordinates, bool createSpace = true); /// /// Returns if the tile in question is air-blocked. diff --git a/Content.Server/GameObjects/Components/AnchorableComponent.cs b/Content.Server/GameObjects/Components/AnchorableComponent.cs index 2fec6e340c..3e9cfb6f25 100644 --- a/Content.Server/GameObjects/Components/AnchorableComponent.cs +++ b/Content.Server/GameObjects/Components/AnchorableComponent.cs @@ -42,7 +42,7 @@ namespace Content.Server.GameObjects.Components /// The tool being used, can be null if forcing it /// Whether or not to check if the tool is valid /// true if it is valid, false otherwise - private async Task Valid(IEntity user, IEntity? utilizing, [MaybeNullWhen(false)] bool force = false) + private async Task Valid(IEntity user, IEntity? utilizing, [NotNullWhen(true)] bool force = false) { if (!Owner.HasComponent()) { diff --git a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs index 4f3c527292..a63a27d274 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs @@ -130,7 +130,7 @@ namespace Content.Server.GameObjects.Components.Atmos // Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth var pressure = 0f; var gam = EntitySystem.Get().GetGridAtmosphere(Owner.Transform.GridID); - var tile = gam?.GetTile(Owner.Transform.Coordinates).Air; + var tile = gam?.GetTile(Owner.Transform.Coordinates)?.Air; if (tile != null) { pressure = tile.Pressure; @@ -190,7 +190,7 @@ namespace Content.Server.GameObjects.Components.Atmos var atmosSystem = EntitySystem.Get(); var gam = atmosSystem.GetGridAtmosphere(pos.GetGridId(Owner.EntityManager)); - var tile = gam?.GetTile(pos).Air; + var tile = gam.GetTile(pos)?.Air; if (tile == null) { error = "No Atmosphere!"; diff --git a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs index 0c03c2f292..12ee989ebd 100644 --- a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs @@ -2,7 +2,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; using Content.Server.Atmos; @@ -10,7 +9,6 @@ using Content.Server.GameObjects.Components.Atmos.Piping; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems.Atmos; -using Content.Shared; using Content.Shared.Atmos; using Content.Shared.Maps; using Robust.Server.GameObjects.EntitySystems.TileLookup; @@ -19,7 +17,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.GameObjects.Components.Map; using Robust.Shared.GameObjects.Systems; -using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Map; using Robust.Shared.Log; using Robust.Shared.Map; diff --git a/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs b/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs index d6bdd0fa58..df9725041a 100644 --- a/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs +++ b/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs @@ -9,7 +9,6 @@ using Content.Server.GameObjects.Components.Strap; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Alert; using Content.Shared.GameObjects.Components.Buckle; -using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Strap; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.Verbs; @@ -27,7 +26,6 @@ using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; -using Robust.Shared.Physics; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -69,7 +67,7 @@ namespace Content.Server.GameObjects.Components.Buckle public Vector2 BuckleOffset { get; private set; } private StrapComponent? _buckledTo; - + /// /// The strap that this component is buckled to. @@ -157,7 +155,7 @@ namespace Content.Server.GameObjects.Components.Buckle } } - private bool CanBuckle(IEntity? user, IEntity to, [MaybeNullWhen(false)] out StrapComponent strap) + private bool CanBuckle(IEntity? user, IEntity to, [NotNullWhen(true)] out StrapComponent? strap) { strap = null; @@ -421,7 +419,7 @@ namespace Content.Server.GameObjects.Components.Buckle { drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1; } - + return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide); } diff --git a/Content.Server/GameObjects/Components/GUI/HandsComponent.cs b/Content.Server/GameObjects/Components/GUI/HandsComponent.cs index 35b22f0c59..5181d442fe 100644 --- a/Content.Server/GameObjects/Components/GUI/HandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/HandsComponent.cs @@ -105,10 +105,9 @@ namespace Content.Server.GameObjects.Components.GUI return GetHand(handName)?.Entity?.GetComponent(); } - public bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item) + public bool TryGetItem(string handName, [NotNullWhen(true)] out ItemComponent? item) { - item = GetItem(handName); - return item != null; + return (item = GetItem(handName)) != null; } public ItemComponent? GetActiveHand => ActiveHand == null @@ -240,7 +239,7 @@ namespace Content.Server.GameObjects.Components.GUI return true; } - public bool TryHand(IEntity entity, [MaybeNullWhen(false)] out string handName) + public bool TryHand(IEntity entity, [NotNullWhen(true)] out string? handName) { handName = null; diff --git a/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs b/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs index 909b9239b8..64485491b5 100644 --- a/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs +++ b/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#nullable enable +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Content.Server.GameObjects.Components.Conveyor; using Content.Server.GameObjects.Components.Items.Storage; @@ -40,12 +41,12 @@ namespace Content.Server.GameObjects.Components.Recycling private int _efficiency; // TODO private bool Powered => - !Owner.TryGetComponent(out PowerReceiverComponent receiver) || + !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; private void Bloodstain() { - if (Owner.TryGetComponent(out AppearanceComponent appearance)) + if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(RecyclerVisuals.Bloody, true); } @@ -53,7 +54,7 @@ namespace Content.Server.GameObjects.Components.Recycling private void Clean() { - if (Owner.TryGetComponent(out AppearanceComponent appearance)) + if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(RecyclerVisuals.Bloody, false); } @@ -64,7 +65,7 @@ namespace Content.Server.GameObjects.Components.Recycling return entity.HasComponent() && !_safe && Powered; } - private bool CanRecycle(IEntity entity, [MaybeNullWhen(false)] out ConstructionPrototype prototype) + private bool CanRecycle(IEntity entity, [NotNullWhen(true)] out ConstructionPrototype? prototype) { prototype = null; @@ -100,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Recycling private bool CanRun() { - if (Owner.TryGetComponent(out PowerReceiverComponent receiver) && + if (Owner.TryGetComponent(out PowerReceiverComponent? receiver) && !receiver.Powered) { return false; @@ -121,7 +122,7 @@ namespace Content.Server.GameObjects.Components.Recycling return false; } - if (!entity.TryGetComponent(out IPhysicsComponent physics) || + if (!entity.TryGetComponent(out IPhysicsComponent? physics) || physics.Anchored) { return false; @@ -165,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Recycling continue; } - if (entity.TryGetComponent(out IPhysicsComponent physics)) + if (entity.TryGetComponent(out IPhysicsComponent? physics)) { var controller = physics.EnsureController(); controller.Move(direction, frameTime, entity.Transform.WorldPosition - Owner.Transform.WorldPosition); diff --git a/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs b/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs index d2da0870d0..8de07084ff 100644 --- a/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs +++ b/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs @@ -47,7 +47,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items /// The name of the hand to get. /// The item in the held, null if no item is held /// Whether it was holding an item - bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item); + bool TryGetItem(string handName, [NotNullWhen(true)] out ItemComponent? item); /// /// Gets item held by the current active hand @@ -102,7 +102,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items /// /// true if the entity is held, false otherwise /// - bool TryHand(IEntity entity, [MaybeNullWhen(false)] out string handName); + bool TryHand(IEntity entity, [NotNullWhen(true)] out string? handName); /// /// Drops the item contained in the slot to the same position as our entity. diff --git a/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs b/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs index ee0ce1b188..7a8f266e9c 100644 --- a/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs @@ -50,7 +50,7 @@ namespace Content.Shared.GameObjects.EntitySystems } //TODO: reorganize this to make more logical sense - protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics) + protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics) { physics.EnsureController(); @@ -71,7 +71,7 @@ namespace Content.Shared.GameObjects.EntitySystems // TODO: movement check. var (walkDir, sprintDir) = mover.VelocityDir; var combined = walkDir + sprintDir; - if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless) + if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless) { if (physics.TryGetController(out MoverController controller)) { @@ -177,7 +177,7 @@ namespace Content.Shared.GameObjects.EntitySystems moverComp.SetSprinting(subTick, walking); } - private static bool TryGetAttachedComponent(ICommonSession? session, [MaybeNullWhen(false)] out T component) + private static bool TryGetAttachedComponent(ICommonSession? session, [NotNullWhen(true)] out T? component) where T : class, IComponent { component = default;