Content update for NetEntities (#18935)
This commit is contained in:
@@ -38,7 +38,7 @@ public partial class SharedBodySystem
|
||||
|
||||
var prototype = Prototypes.Index<BodyPrototype>(body.Prototype);
|
||||
|
||||
if (!_netManager.IsClient || bodyId.IsClientSide())
|
||||
if (!_netManager.IsClient || IsClientSide(bodyId))
|
||||
InitBody(body, prototype);
|
||||
|
||||
Dirty(body); // Client doesn't actually spawn the body, need to sync it
|
||||
@@ -72,7 +72,12 @@ public partial class SharedBodySystem
|
||||
body.Root != null)
|
||||
return false;
|
||||
|
||||
slot = new BodyPartSlot(slotId, bodyId.Value, null);
|
||||
slot = new BodyPartSlot
|
||||
{
|
||||
Id = slotId,
|
||||
Parent = bodyId.Value,
|
||||
NetParent = GetNetEntity(bodyId.Value),
|
||||
};
|
||||
body.Root = slot;
|
||||
|
||||
return true;
|
||||
@@ -86,7 +91,13 @@ public partial class SharedBodySystem
|
||||
return;
|
||||
var bodyId = Spawn(root.Part, body.Owner.ToCoordinates());
|
||||
var partComponent = Comp<BodyPartComponent>(bodyId);
|
||||
var slot = new BodyPartSlot(root.Part, body.Owner, partComponent.PartType);
|
||||
var slot = new BodyPartSlot
|
||||
{
|
||||
Id = root.Part,
|
||||
Type = partComponent.PartType,
|
||||
Parent = body.Owner,
|
||||
NetParent = GetNetEntity(body.Owner),
|
||||
};
|
||||
body.Root = slot;
|
||||
partComponent.Body = bodyId;
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Content.Shared.Body.Systems;
|
||||
|
||||
public partial class SharedBodySystem
|
||||
{
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
private void InitializeOrgans()
|
||||
{
|
||||
SubscribeLocalEvent<OrganComponent, ComponentGetState>(OnOrganGetState);
|
||||
@@ -23,7 +25,12 @@ public partial class SharedBodySystem
|
||||
if (!Resolve(parent, ref part, false))
|
||||
return null;
|
||||
|
||||
var slot = new OrganSlot(slotId, parent);
|
||||
var slot = new OrganSlot()
|
||||
{
|
||||
Id = slotId,
|
||||
Parent = parent,
|
||||
NetParent = GetNetEntity(parent),
|
||||
};
|
||||
part.Organs.Add(slotId, slot);
|
||||
|
||||
return slot;
|
||||
@@ -35,12 +42,12 @@ public partial class SharedBodySystem
|
||||
slot.Child == null &&
|
||||
Resolve(organId.Value, ref organ, false) &&
|
||||
Containers.TryGetContainer(slot.Parent, BodyContainerId, out var container) &&
|
||||
container.CanInsert(organId.Value);
|
||||
_container.CanInsert(organId.Value, container);
|
||||
}
|
||||
|
||||
private void OnOrganGetState(EntityUid uid, OrganComponent organ, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new OrganComponentState(organ.Body, organ.ParentSlot);
|
||||
args.State = new OrganComponentState(GetNetEntity(organ.Body), organ.ParentSlot);
|
||||
}
|
||||
|
||||
private void OnOrganHandleState(EntityUid uid, OrganComponent organ, ref ComponentHandleState args)
|
||||
@@ -48,7 +55,7 @@ public partial class SharedBodySystem
|
||||
if (args.Current is not OrganComponentState state)
|
||||
return;
|
||||
|
||||
organ.Body = state.Body;
|
||||
organ.Body = EnsureEntity<OrganComponent>(state.Body, uid);
|
||||
organ.ParentSlot = state.Parent;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public partial class SharedBodySystem
|
||||
private void OnPartGetState(EntityUid uid, BodyPartComponent part, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new BodyPartComponentState(
|
||||
part.Body,
|
||||
GetNetEntity(part.Body),
|
||||
part.ParentSlot,
|
||||
part.Children,
|
||||
part.Organs,
|
||||
@@ -41,7 +41,7 @@ public partial class SharedBodySystem
|
||||
if (args.Current is not BodyPartComponentState state)
|
||||
return;
|
||||
|
||||
part.Body = state.Body;
|
||||
part.Body = EnsureEntity<BodyPartComponent>(state.Body, uid);
|
||||
part.ParentSlot = state.ParentSlot; // TODO use containers. This is broken and does not work.
|
||||
part.Children = state.Children; // TODO use containers. This is broken and does not work.
|
||||
part.Organs = state.Organs; // TODO end my suffering.
|
||||
@@ -54,7 +54,7 @@ public partial class SharedBodySystem
|
||||
{
|
||||
if (part.ParentSlot is { } slot)
|
||||
{
|
||||
slot.Child = null;
|
||||
slot.SetChild(null, GetNetEntity(null));
|
||||
DirtyAllComponents(slot.Parent);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,13 @@ public partial class SharedBodySystem
|
||||
if (!Resolve(parent, ref part, false))
|
||||
return null;
|
||||
|
||||
var slot = new BodyPartSlot(slotId, parent, partType);
|
||||
var slot = new BodyPartSlot
|
||||
{
|
||||
Id = slotId,
|
||||
Type = partType,
|
||||
Parent = parent,
|
||||
NetParent = GetNetEntity(parent),
|
||||
};
|
||||
part.Children.Add(slotId, slot);
|
||||
|
||||
return slot;
|
||||
@@ -91,7 +97,12 @@ public partial class SharedBodySystem
|
||||
!Resolve(parentId.Value, ref parent, false))
|
||||
return false;
|
||||
|
||||
slot = new BodyPartSlot(id, parentId.Value, null);
|
||||
slot = new BodyPartSlot
|
||||
{
|
||||
Id = id,
|
||||
Parent = parentId.Value,
|
||||
NetParent = GetNetEntity(parentId.Value),
|
||||
};
|
||||
if (!parent.Children.TryAdd(id, slot))
|
||||
{
|
||||
slot = null;
|
||||
@@ -171,7 +182,7 @@ public partial class SharedBodySystem
|
||||
Resolve(partId.Value, ref part, false) &&
|
||||
(slot.Type == null || slot.Type == part.PartType) &&
|
||||
Containers.TryGetContainer(slot.Parent, BodyContainerId, out var container) &&
|
||||
container.CanInsert(partId.Value);
|
||||
_container.CanInsert(partId.Value, container);
|
||||
}
|
||||
|
||||
public virtual bool AttachPart(
|
||||
@@ -191,7 +202,7 @@ public partial class SharedBodySystem
|
||||
if (!container.Insert(partId.Value))
|
||||
return false;
|
||||
|
||||
slot.Child = partId;
|
||||
slot.SetChild(partId, GetNetEntity(partId));
|
||||
part.ParentSlot = slot;
|
||||
|
||||
if (TryComp(slot.Parent, out BodyPartComponent? parentPart))
|
||||
@@ -241,7 +252,7 @@ public partial class SharedBodySystem
|
||||
|
||||
var oldBodyNullable = part.Body;
|
||||
|
||||
slot.Child = null;
|
||||
slot.SetChild(null, null);
|
||||
part.ParentSlot = null;
|
||||
part.Body = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user