From b51b8cb182c3cea04224caff9702ca6f9631cd14 Mon Sep 17 00:00:00 2001 From: collinlunn <60152240+collinlunn@users.noreply.github.com> Date: Mon, 1 Feb 2021 10:19:43 -0600 Subject: [PATCH] Some Power nullable & ComponentDependency (#3050) * Power nullability * AME nullability * re-adds EnsureComponents * conflict fix * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs Co-authored-by: Paul Ritter * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs Co-authored-by: Paul Ritter * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs Co-authored-by: Paul Ritter * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs Co-authored-by: Paul Ritter * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs Co-authored-by: Paul Ritter * removes duplicate component assignment Co-authored-by: py01 Co-authored-by: Paul Ritter --- .../Power/AME/AMEFuelContainerComponent.cs | 3 +- .../Components/Power/AME/AMEPartComponent.cs | 6 ++-- .../Power/ApcNetComponents/ApcComponent.cs | 4 +++ .../ApcNetComponents/BaseApcNetComponent.cs | 3 +- .../PowerProviderComponent.cs | 6 ++-- .../Power/BaseNetConnectorComponent.cs | 2 +- .../Components/Power/BatteryComponent.cs | 3 +- .../Components/Power/PowerCellComponent.cs | 5 ++-- .../BasePowerNetComponent.cs | 3 +- .../BatteryDischargerComponent.cs | 23 ++++++++++---- .../BatteryStorageComponent.cs | 30 +++++++++++++------ .../PowerNetComponents/IPowerNetManager.cs | 3 +- .../PowerConsumerComponent.cs | 5 ++-- .../PowerSupplierComponent.cs | 3 +- .../RadiationCollectorComponent.cs | 25 +++++----------- .../PowerNetComponents/SolarPanelComponent.cs | 11 ++++--- .../Components/Power/WireComponent.cs | 10 +++++-- .../Components/Power/WirePlacerComponent.cs | 11 ++++--- 18 files changed, 94 insertions(+), 62 deletions(-) diff --git a/Content.Server/GameObjects/Components/Power/AME/AMEFuelContainerComponent.cs b/Content.Server/GameObjects/Components/Power/AME/AMEFuelContainerComponent.cs index 98e336608e..6367ac9002 100644 --- a/Content.Server/GameObjects/Components/Power/AME/AMEFuelContainerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/AME/AMEFuelContainerComponent.cs @@ -1,4 +1,5 @@ -using Robust.Shared.GameObjects; +#nullable enable +using Robust.Shared.GameObjects; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.AME diff --git a/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs b/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs index 776dfb6309..5817fe5882 100644 --- a/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs +++ b/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs @@ -1,3 +1,4 @@ +#nullable enable using System.Threading.Tasks; using System.Linq; using Content.Server.GameObjects.Components.Interactable; @@ -28,14 +29,13 @@ namespace Content.Server.GameObjects.Components.Power.AME async Task IInteractUsing.InteractUsing(InteractUsingEventArgs args) { - if (!args.User.TryGetComponent(out IHandsComponent hands)) + if (!args.User.TryGetComponent(out var hands)) { Owner.PopupMessage(args.User, Loc.GetString("You have no hands.")); return true; } - var activeHandEntity = hands.GetActiveHand.Owner; - if (activeHandEntity.TryGetComponent(out var multitool) && multitool.Qualities == ToolQuality.Multitool) + if (args.Using.TryGetComponent(out var multitool) && multitool.Qualities == ToolQuality.Multitool) { var mapGrid = _mapManager.GetGrid(args.ClickLocation.GetGridId(_serverEntityManager)); diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs index 4edd7f3df8..c2a2b6b431 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs @@ -179,6 +179,10 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents return ApcExternalPowerState.None; } var consumer = batteryStorage.Consumer; + + if (consumer == null) + return ApcExternalPowerState.None; + if (consumer.ReceivedPower == 0 && consumer.DrawRate != 0) { return ApcExternalPowerState.None; diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/BaseApcNetComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/BaseApcNetComponent.cs index b8f6c13d15..d13f3fecfe 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/BaseApcNetComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/BaseApcNetComponent.cs @@ -1,4 +1,5 @@ -using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; +#nullable enable +using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; namespace Content.Server.GameObjects.Components.Power.ApcNetComponents { diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs index f1c14043dd..96c2b5e9e9 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs @@ -1,6 +1,6 @@ +#nullable enable using System; using System.Collections.Generic; -using System.Diagnostics; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; @@ -20,7 +20,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents void UpdateReceiverLoad(int oldLoad, int newLoad); - public IEntity ProviderOwner { get; } + public IEntity? ProviderOwner { get; } public bool HasApcPower { get; } } @@ -172,7 +172,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents public void AddReceiver(PowerReceiverComponent receiver) { } public void RemoveReceiver(PowerReceiverComponent receiver) { } public void UpdateReceiverLoad(int oldLoad, int newLoad) { } - public IEntity ProviderOwner => default; + public IEntity? ProviderOwner => default; } } } diff --git a/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs b/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs index fc2148f85f..66ac85b62d 100644 --- a/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs +++ b/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; diff --git a/Content.Server/GameObjects/Components/Power/BatteryComponent.cs b/Content.Server/GameObjects/Components/Power/BatteryComponent.cs index 5235cf69fe..c7dce26485 100644 --- a/Content.Server/GameObjects/Components/Power/BatteryComponent.cs +++ b/Content.Server/GameObjects/Components/Power/BatteryComponent.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using Robust.Shared.GameObjects; using Robust.Shared.Maths; using Robust.Shared.Serialization; diff --git a/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs b/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs index 61c321c497..8806e69272 100644 --- a/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using Content.Server.Explosions; using Content.Server.GameObjects.Components.Chemistry; using Content.Shared.GameObjects.Components.Power; @@ -11,8 +12,6 @@ using Robust.Shared.Serialization; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; -#nullable enable - namespace Content.Server.GameObjects.Components.Power { /// diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BasePowerNetComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BasePowerNetComponent.cs index 3482d225a0..a80fc4ed9d 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BasePowerNetComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BasePowerNetComponent.cs @@ -1,4 +1,5 @@ -using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; +#nullable enable +using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents { diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs index 65eaafb285..332b2abcbb 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs @@ -1,6 +1,9 @@ -using Robust.Shared.GameObjects; +#nullable enable +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; +using System; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents { @@ -13,10 +16,10 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents public override string Name => "BatteryDischarger"; [ViewVariables] - private BatteryComponent _battery; + [ComponentDependency] private BatteryComponent? _battery = default!; [ViewVariables] - private PowerSupplierComponent _supplier; + [ComponentDependency] private PowerSupplierComponent? _supplier = default!; [ViewVariables(VVAccess.ReadWrite)] public int ActiveSupplyRate { get => _activeSupplyRate; set => SetActiveSupplyRate(value); } @@ -31,14 +34,16 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents public override void Initialize() { base.Initialize(); - - _battery = Owner.EnsureComponent(); - _supplier = Owner.EnsureComponent(); + Owner.EnsureComponentWarn(); + Owner.EnsureComponentWarn(); UpdateSupplyRate(); } public void Update(float frameTime) { + if (_battery == null) + return; + //Simplified implementation - if the battery is empty, and charge is being added to the battery //at a lower rate that this is using it, the charge is used without creating power supply. _battery.CurrentCharge -= ActiveSupplyRate * frameTime; @@ -47,6 +52,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private void UpdateSupplyRate() { + if (_battery == null) + return; + if (_battery.BatteryState == BatteryState.Empty) { SetSupplierSupplyRate(0); @@ -59,6 +67,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private void SetSupplierSupplyRate(int newSupplierSupplyRate) { + if (_supplier == null) + return; + if (_supplier.SupplyRate != newSupplierSupplyRate) { _supplier.SupplyRate = newSupplierSupplyRate; diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs index 416ac17a5c..e87ccb96f8 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs @@ -1,4 +1,6 @@ -using Robust.Shared.GameObjects; +#nullable enable +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -17,10 +19,12 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private int _activeDrawRate; [ViewVariables] - private BatteryComponent _battery; + [ComponentDependency] private BatteryComponent? _battery = default!; [ViewVariables] - public PowerConsumerComponent Consumer { get; private set; } + public PowerConsumerComponent? Consumer => _consumer; + + [ComponentDependency] private PowerConsumerComponent? _consumer = default!; public override void ExposeData(ObjectSerializer serializer) { @@ -31,21 +35,26 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents public override void Initialize() { base.Initialize(); - - _battery = Owner.EnsureComponent(); - Consumer = Owner.EnsureComponent(); + Owner.EnsureComponentWarn(); + Owner.EnsureComponentWarn(); UpdateDrawRate(); } public void Update(float frameTime) { + if (_consumer == null || _battery == null) + return; + //Simplified implementation - If a frame adds more power to a partially full battery than it can hold, the power is lost. - _battery.CurrentCharge += Consumer.ReceivedPower * frameTime; + _battery.CurrentCharge += _consumer.ReceivedPower * frameTime; UpdateDrawRate(); } private void UpdateDrawRate() { + if (_battery == null) + return; + if (_battery.BatteryState == BatteryState.Full) { SetConsumerDraw(0); @@ -58,9 +67,12 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private void SetConsumerDraw(int newConsumerDrawRate) { - if (Consumer.DrawRate != newConsumerDrawRate) + if (_consumer == null) + return; + + if (_consumer.DrawRate != newConsumerDrawRate) { - Consumer.DrawRate = newConsumerDrawRate; + _consumer.DrawRate = newConsumerDrawRate; } } diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/IPowerNetManager.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/IPowerNetManager.cs index 808f3f564b..2f8b8230b2 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/IPowerNetManager.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/IPowerNetManager.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#nullable enable +using System.Collections.Generic; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs index 54dd3437d2..c6118c87f3 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using System.Diagnostics; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; @@ -34,7 +35,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents public int ReceivedPower { get => _receivedPower; set => SetReceivedPower(value); } private int _receivedPower; - public event EventHandler OnReceivedPowerChanged; + public event EventHandler? OnReceivedPowerChanged; public override void ExposeData(ObjectSerializer serializer) { diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs index b843c1bee7..02047fe80c 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs @@ -1,4 +1,5 @@ -using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; +#nullable enable +using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs index b6b63ffc2c..90e5ea562f 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs @@ -1,20 +1,18 @@ +#nullable enable using System; -using System.Threading; using Content.Server.Utility; using Content.Shared.GameObjects.Components; -using Content.Shared.GameObjects.Components.Doors; using Content.Shared.GameObjects.Components.Singularity; using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.GameObjects.Components; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Log; -using Timer = Robust.Shared.Timers.Timer; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents { @@ -27,19 +25,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private bool _enabled; private TimeSpan _coolDownEnd; - private PhysicsComponent _collidableComponent; + [ComponentDependency] private readonly PhysicsComponent? _collidableComponent = default!; - public override void Initialize() - { - base.Initialize(); - if (!Owner.TryGetComponent(out _collidableComponent)) - { - Logger.Error("RadiationCollectorComponent created with no CollidableComponent"); - return; - } - } - - public override void HandleMessage(ComponentMessage message, IComponent component) + public override void HandleMessage(ComponentMessage message, IComponent? component) { base.HandleMessage(message, component); switch (message) @@ -52,7 +40,8 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private void OnAnchoredChanged() { - if(_collidableComponent.Anchored) Owner.SnapToGrid(); + if(_collidableComponent != null && _collidableComponent.Anchored) + Owner.SnapToGrid(); } bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs) @@ -99,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents protected void SetAppearance(RadiationCollectorVisualState state) { - if (Owner.TryGetComponent(out AppearanceComponent appearance)) + if (Owner.TryGetComponent(out var appearance)) { appearance.SetData(RadiationCollectorVisuals.VisualState, state); } diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs index 6a3f46efcc..89fca08196 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems; using Robust.Server.GameObjects; @@ -62,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private void UpdateSupply() { - if (Owner.TryGetComponent(out PowerSupplierComponent supplier)) + if (Owner.TryGetComponent(out var supplier)) { supplier.SupplyRate = (int) (_maxSupply * _coverage); } @@ -72,7 +73,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents { base.Initialize(); - Owner.EnsureComponentWarn(out PowerSupplierComponent _); + Owner.EnsureComponentWarn(); UpdateSupply(); } @@ -86,7 +87,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents public void OnBreak(BreakageEventArgs args) { - var sprite = Owner.GetComponent(); + if (!Owner.TryGetComponent(out var sprite)) + return; + sprite.LayerSetState(0, "broken"); MaxSupply = 0; } diff --git a/Content.Server/GameObjects/Components/Power/WireComponent.cs b/Content.Server/GameObjects/Components/Power/WireComponent.cs index ad9cf19602..8fd1efad13 100644 --- a/Content.Server/GameObjects/Components/Power/WireComponent.cs +++ b/Content.Server/GameObjects/Components/Power/WireComponent.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +#nullable enable +using System.Threading.Tasks; using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Stack; using Content.Shared.GameObjects.Components.Interactable; @@ -18,7 +19,7 @@ namespace Content.Server.GameObjects.Components.Power public override string Name => "Wire"; [ViewVariables] - private string _wireDroppedOnCutPrototype; + private string? _wireDroppedOnCutPrototype; /// /// Checked by to determine if there is @@ -37,7 +38,10 @@ namespace Content.Server.GameObjects.Components.Power public async Task InteractUsing(InteractUsingEventArgs eventArgs) { - if (!eventArgs.Using.TryGetComponent(out ToolComponent tool)) return false; + if (_wireDroppedOnCutPrototype == null) + return false; + + if (!eventArgs.Using.TryGetComponent(out var tool)) return false; if (!await tool.UseTool(eventArgs.User, Owner, 0.25f, ToolQuality.Cutting)) return false; Owner.Delete(); diff --git a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs index 0330bd1c4a..81d8654360 100644 --- a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs @@ -1,7 +1,7 @@ -using Content.Server.GameObjects.Components.Stack; +#nullable enable +using Content.Server.GameObjects.Components.Stack; using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Utility; -using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.Interfaces.Map; @@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Power public override string Name => "WirePlacer"; [ViewVariables] - private string _wirePrototypeID; + private string? _wirePrototypeID; [ViewVariables] private WireType _blockingWireType; @@ -36,6 +36,9 @@ namespace Content.Server.GameObjects.Components.Power /// public async Task AfterInteract(AfterInteractEventArgs eventArgs) { + if (_wirePrototypeID == null) + return; + if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return; if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager), out var grid)) return; @@ -50,7 +53,7 @@ namespace Content.Server.GameObjects.Components.Power return; } } - if (Owner.TryGetComponent(out StackComponent stack) && !stack.Use(1)) + if (Owner.TryGetComponent(out var stack) && !stack.Use(1)) return; Owner.EntityManager.SpawnEntity(_wirePrototypeID, grid.GridTileToLocal(snapPos)); }