SubscribeLocalEvent<FoldableComponent, ComponentInit>(OnFoldableInit);
SubscribeLocalEvent<FoldableComponent, ContainerGettingInsertedAttemptEvent>(OnInsertEvent);
SubscribeLocalEvent<FoldableComponent, StorageOpenAttemptEvent>(OnFoldableOpenAttempt);
+ SubscribeLocalEvent<FoldableComponent, EntityStorageInsertedIntoAttemptEvent>(OnEntityStorageAttemptInsert);
SubscribeLocalEvent<FoldableComponent, StrapAttemptEvent>(OnStrapAttempt);
}
args.Cancelled = true;
}
+ private void OnEntityStorageAttemptInsert(Entity<FoldableComponent> entity,
+ ref EntityStorageInsertedIntoAttemptEvent args)
+ {
+ if (entity.Comp.IsFolded)
+ args.Cancelled = true;
+ }
+
/// <summary>
/// Returns false if the entity isn't foldable.
/// </summary>
}
}
+/// <summary>
+/// Raised on the entity being inserted whenever checking if an entity can be inserted into an entity storage.
+/// </summary>
[ByRefEvent]
public record struct InsertIntoEntityStorageAttemptEvent(EntityUid ItemToInsert, bool Cancelled = false);
+/// <summary>
+/// Raised on the entity storage whenever checking if an entity can be inserted into it.
+/// </summary>
+[ByRefEvent]
+public record struct EntityStorageInsertedIntoAttemptEvent(EntityUid ItemToInsert, bool Cancelled = false);
+
[ByRefEvent]
public record struct StorageOpenAttemptEvent(EntityUid User, bool Silent, bool Cancelled = false);
if (attemptEvent.Cancelled)
return false;
+ // Allow other components on the container to prevent inserting the item: e.g. the container is folded
+ var containerAttemptEvent = new EntityStorageInsertedIntoAttemptEvent(toInsert);
+ RaiseLocalEvent(container, ref containerAttemptEvent);
+
+ if (containerAttemptEvent.Cancelled)
+ return false;
+
// Consult the whitelist. The whitelist ignores the default assumption about how entity storage works.
if (component.Whitelist != null)
return _whitelistSystem.IsValid(component.Whitelist, toInsert);