Inline TryGetComponent completely
This commit is contained in:
@@ -18,8 +18,8 @@ namespace Content.Shared.Lathe
|
||||
|
||||
public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SharedMaterialStorageComponent? storage)
|
||||
|| !Owner.TryGetComponent(out SharedLatheDatabaseComponent? database)) return false;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SharedMaterialStorageComponent? storage)
|
||||
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SharedLatheDatabaseComponent? database)) return false;
|
||||
|
||||
if (!database.Contains(recipe)) return false;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Content.Shared.Movement.EntitySystems
|
||||
|
||||
// For stuff like "Moving out of locker" or the likes
|
||||
if (owner.IsInContainer() &&
|
||||
(!owner.TryGetComponent(out MobStateComponent? mobState) ||
|
||||
(!IoCManager.Resolve<IEntityManager>().TryGetComponent(owner.Uid, out MobStateComponent? mobState) ||
|
||||
mobState.IsAlive()))
|
||||
{
|
||||
var relayMoveEvent = new RelayMovementEntityEvent(owner);
|
||||
@@ -85,7 +85,7 @@ namespace Content.Shared.Movement.EntitySystems
|
||||
if (ent == null || !IoCManager.Resolve<IEntityManager>().EntityExists(ent.Uid))
|
||||
return false;
|
||||
|
||||
if (!ent.TryGetComponent(out T? comp))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ent.Uid, out T? comp))
|
||||
return false;
|
||||
|
||||
component = comp;
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Shared.Storage.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Shared.Storage.EntitySystems
|
||||
{
|
||||
@@ -20,32 +21,32 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
private void CounterEntityInserted(EntityUid uid, ItemCounterComponent itemCounter,
|
||||
EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (!itemCounter.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return;
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemCounter.Owner.Uid, out AppearanceComponent? appearanceComponent)) return;
|
||||
|
||||
var count = GetCount(args, itemCounter);
|
||||
if (count == null)
|
||||
return;
|
||||
|
||||
|
||||
appearanceComponent.SetData(StackVisuals.Actual, count);
|
||||
if (itemCounter.MaxAmount != null)
|
||||
appearanceComponent.SetData(StackVisuals.MaxCount, itemCounter.MaxAmount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void CounterEntityRemoved(EntityUid uid, ItemCounterComponent itemCounter,
|
||||
EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (!itemCounter.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return;
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemCounter.Owner.Uid, out AppearanceComponent? appearanceComponent)) return;
|
||||
|
||||
var count = GetCount(args, itemCounter);
|
||||
if (count == null)
|
||||
return;
|
||||
|
||||
|
||||
appearanceComponent.SetData(StackVisuals.Actual, count);
|
||||
if (itemCounter.MaxAmount != null)
|
||||
appearanceComponent.SetData(StackVisuals.MaxCount, itemCounter.MaxAmount);
|
||||
}
|
||||
|
||||
|
||||
protected abstract int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Shared.Storage.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Shared.Storage.EntitySystems
|
||||
{
|
||||
@@ -20,7 +21,7 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
|
||||
private void InitLayers(EntityUid uid, ItemMapperComponent component, ComponentInit args)
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner.Uid, out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
var list = new List<string>(component.MapLayers.Keys);
|
||||
appearanceComponent.SetData(StorageMapVisuals.InitLayers, new ShowLayerData(list));
|
||||
@@ -30,7 +31,7 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (itemMapper.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(itemMapper.Owner.Uid, out AppearanceComponent? appearanceComponent)
|
||||
&& TryGetLayers(args, itemMapper, out var containedLayers))
|
||||
{
|
||||
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
|
||||
@@ -40,7 +41,7 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (itemMapper.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(itemMapper.Owner.Uid, out AppearanceComponent? appearanceComponent)
|
||||
&& TryGetLayers(args, itemMapper, out var containedLayers))
|
||||
{
|
||||
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
|
||||
@@ -51,4 +52,4 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
ItemMapperComponent itemMapper,
|
||||
out IReadOnlyList<string> containedLayers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user