Don't predict body init (#12163)

* Don't predict body init

Client doesn't handle predicted entity spawning so the organs hang around.

* Just use init

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-10-25 11:08:41 +11:00
committed by GitHub
parent 92e92dceb0
commit 70cf361caa
4 changed files with 27 additions and 28 deletions

View File

@@ -1,7 +1,13 @@
using Content.Shared.Body.Systems;
using Content.Shared.Body.Components;
using Content.Shared.Body.Prototypes;
using Content.Shared.Body.Systems;
namespace Content.Client.Body.Systems;
public sealed class BodySystem : SharedBodySystem
{
protected override void InitBody(BodyComponent body, BodyPrototype prototype)
{
return;
}
}

View File

@@ -6,7 +6,9 @@ using Content.Server.Kitchen.Components;
using Content.Server.Mind.Components;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Body.Prototypes;
using Content.Shared.Body.Systems;
using Content.Shared.Coordinates;
using Content.Shared.Humanoid;
using Content.Shared.MobState.Components;
using Content.Shared.Movement.Events;
@@ -113,6 +115,21 @@ public sealed class BodySystem : SharedBodySystem
return true;
}
protected override void InitBody(BodyComponent body, BodyPrototype prototype)
{
var root = prototype.Slots[prototype.Root];
var bodyId = Spawn(root.Part, body.Owner.ToCoordinates());
var partComponent = Comp<BodyPartComponent>(bodyId);
var slot = new BodyPartSlot(root.Part, body.Owner, partComponent.PartType);
body.Root = slot;
partComponent.Body = bodyId;
Containers.EnsureContainer<Container>(body.Owner, BodyContainerId);
AttachPart(bodyId, slot, partComponent);
InitPart(partComponent, prototype, prototype.Root);
}
public override HashSet<EntityUid> GibBody(EntityUid? bodyId, bool gibOrgans = false, BodyComponent? body = null)
{
if (bodyId == null || !Resolve(bodyId.Value, ref body, false))

View File

@@ -14,23 +14,12 @@ public partial class SharedBodySystem
{
public void InitializeBody()
{
SubscribeLocalEvent<BodyComponent, MapInitEvent>(OnBodyMapInit);
SubscribeLocalEvent<BodyComponent, ComponentInit>(OnBodyInit);
SubscribeLocalEvent<BodyComponent, ComponentGetState>(OnBodyGetState);
SubscribeLocalEvent<BodyComponent, ComponentHandleState>(OnBodyHandleState);
}
private void OnBodyMapInit(EntityUid bodyId, BodyComponent body, MapInitEvent args)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (body.Prototype == null || body.Root != null)
return;
var prototype = Prototypes.Index<BodyPrototype>(body.Prototype);
InitBody(body, prototype);
}
private void OnBodyInit(EntityUid bodyId, BodyComponent body, ComponentInit args)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
@@ -75,22 +64,9 @@ public partial class SharedBodySystem
return true;
}
private void InitBody(BodyComponent body, BodyPrototype prototype)
{
var root = prototype.Slots[prototype.Root];
var bodyId = Spawn(root.Part, body.Owner.ToCoordinates());
var partComponent = Comp<BodyPartComponent>(bodyId);
var slot = new BodyPartSlot(root.Part, body.Owner, partComponent.PartType);
body.Root = slot;
partComponent.Body = bodyId;
protected abstract void InitBody(BodyComponent body, BodyPrototype prototype);
Containers.EnsureContainer<Container>(body.Owner, BodyContainerId);
AttachPart(bodyId, slot, partComponent);
InitPart(partComponent, prototype, prototype.Root);
}
private void InitPart(BodyPartComponent parent, BodyPrototype prototype, string slotId, HashSet<string>? initialized = null)
protected void InitPart(BodyPartComponent parent, BodyPrototype prototype, string slotId, HashSet<string>? initialized = null)
{
initialized ??= new HashSet<string>();

View File

@@ -7,7 +7,7 @@ namespace Content.Shared.Body.Systems;
public abstract partial class SharedBodySystem : EntitySystem
{
private const string BodyContainerId = "BodyContainer";
protected const string BodyContainerId = "BodyContainer";
[Dependency] protected readonly IPrototypeManager Prototypes = default!;