Fix log component parenting issues (#11073)

This commit is contained in:
Leon Friedrich
2022-09-06 17:08:19 +12:00
committed by GitHub
parent 0c8e52c163
commit 2dd804930d
3 changed files with 50 additions and 16 deletions

View File

@@ -1,12 +1,17 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Components;
using Content.Server.Kitchen.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Random.Helpers;
using Robust.Shared.Containers;
namespace Content.Server.Botany.Systems;
public sealed class LogSystem : EntitySystem
{
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
public override void Initialize()
{
base.Initialize();
@@ -16,15 +21,28 @@ public sealed class LogSystem : EntitySystem
private void OnInteractUsing(EntityUid uid, LogComponent component, InteractUsingEvent args)
{
if (HasComp<SharpComponent>(args.Used))
if (!HasComp<SharpComponent>(args.Used))
return;
// if in some container, try pick up, else just drop to world
var inContainer = _containerSystem.IsEntityInContainer(uid);
var pos = Transform(uid).Coordinates;
for (var i = 0; i < component.SpawnCount; i++)
{
for (var i = 0; i < component.SpawnCount; i++)
var plank = Spawn(component.SpawnedPrototype, pos);
if (inContainer)
_handsSystem.PickupOrDrop(args.User, plank);
else
{
var plank = Spawn(component.SpawnedPrototype, Transform(uid).Coordinates);
var xform = Transform(plank);
_containerSystem.AttachParentToContainerOrGrid(xform);
xform.LocalRotation = 0;
plank.RandomOffset(0.25f);
}
QueueDel(uid);
}
QueueDel(uid);
}
}