Fix log component parenting issues (#11073)
This commit is contained in:
@@ -4,6 +4,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
|
|||||||
|
|
||||||
namespace Content.Server.Botany.Components;
|
namespace Content.Server.Botany.Components;
|
||||||
// TODO: This should probably be merged with SliceableFood somehow or made into a more generic Choppable.
|
// TODO: This should probably be merged with SliceableFood somehow or made into a more generic Choppable.
|
||||||
|
// Yeah this is pretty trash. also consolidating this type of behavior will avoid future transform parenting bugs (see #6090).
|
||||||
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[Access(typeof(LogSystem))]
|
[Access(typeof(LogSystem))]
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
using Content.Server.Botany.Components;
|
using Content.Server.Botany.Components;
|
||||||
using Content.Server.Kitchen.Components;
|
using Content.Server.Kitchen.Components;
|
||||||
|
using Content.Shared.Hands.EntitySystems;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Random.Helpers;
|
using Content.Shared.Random.Helpers;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
|
|
||||||
namespace Content.Server.Botany.Systems;
|
namespace Content.Server.Botany.Systems;
|
||||||
|
|
||||||
public sealed class LogSystem : EntitySystem
|
public sealed class LogSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||||
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -16,15 +21,28 @@ public sealed class LogSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnInteractUsing(EntityUid uid, LogComponent component, InteractUsingEvent args)
|
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, Transform(uid).Coordinates);
|
var plank = Spawn(component.SpawnedPrototype, pos);
|
||||||
|
|
||||||
|
if (inContainer)
|
||||||
|
_handsSystem.PickupOrDrop(args.User, plank);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var xform = Transform(plank);
|
||||||
|
_containerSystem.AttachParentToContainerOrGrid(xform);
|
||||||
|
xform.LocalRotation = 0;
|
||||||
plank.RandomOffset(0.25f);
|
plank.RandomOffset(0.25f);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QueueDel(uid);
|
QueueDel(uid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,12 +64,16 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
// Fill new slice
|
// Fill new slice
|
||||||
FillSlice(sliceUid, lostSolution);
|
FillSlice(sliceUid, lostSolution);
|
||||||
|
|
||||||
if (EntityManager.TryGetComponent(user, out HandsComponent? handsComponent))
|
var inCont = _containerSystem.IsEntityInContainer(component.Owner);
|
||||||
|
if (inCont)
|
||||||
{
|
{
|
||||||
if (_containerSystem.IsEntityInContainer(component.Owner))
|
_handsSystem.PickupOrDrop(user, sliceUid);
|
||||||
{
|
|
||||||
_handsSystem.PickupOrDrop(user, sliceUid, handsComp: handsComponent);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var xform = Transform(sliceUid);
|
||||||
|
_containerSystem.AttachParentToContainerOrGrid(xform);
|
||||||
|
xform.LocalRotation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundSystem.Play(component.Sound.GetSound(), Filter.Pvs(uid),
|
SoundSystem.Play(component.Sound.GetSound(), Filter.Pvs(uid),
|
||||||
@@ -84,15 +88,26 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Split last slice
|
// Split last slice
|
||||||
if (component.Count == 1) {
|
if (component.Count > 1)
|
||||||
var lastSlice = EntityManager.SpawnEntity(component.Slice, transform.Coordinates);
|
return true;
|
||||||
|
|
||||||
|
sliceUid = EntityManager.SpawnEntity(component.Slice, transform.Coordinates);
|
||||||
|
|
||||||
// Fill last slice with the rest of the solution
|
// Fill last slice with the rest of the solution
|
||||||
FillSlice(lastSlice, solution);
|
FillSlice(sliceUid, solution);
|
||||||
|
|
||||||
EntityManager.DeleteEntity(uid);
|
if (inCont)
|
||||||
|
{
|
||||||
|
_handsSystem.PickupOrDrop(user, sliceUid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var xform = Transform(sliceUid);
|
||||||
|
_containerSystem.AttachParentToContainerOrGrid(xform);
|
||||||
|
xform.LocalRotation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityManager.DeleteEntity(uid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user