diff --git a/geary-papermc-tracking/src/main/kotlin/com/mineinabyss/geary/papermc/tracking/entities/helpers/Helpers.kt b/geary-papermc-tracking/src/main/kotlin/com/mineinabyss/geary/papermc/tracking/entities/helpers/Helpers.kt index 4551856..651ca71 100644 --- a/geary-papermc-tracking/src/main/kotlin/com/mineinabyss/geary/papermc/tracking/entities/helpers/Helpers.kt +++ b/geary-papermc-tracking/src/main/kotlin/com/mineinabyss/geary/papermc/tracking/entities/helpers/Helpers.kt @@ -12,19 +12,22 @@ import org.bukkit.Location import org.bukkit.persistence.PersistentDataContainer -fun Location.spawnFromPrefab(prefab: PrefabKey): Result { +fun Location.spawnFromPrefab(prefab: PrefabKey, initEntityPreEvent: GearyEntity.() -> Unit = {}): Result { val entity = prefabs.manager[prefab] ?: return Result.failure(IllegalArgumentException("No prefab found")) - return spawnFromPrefab(entity) + return spawnFromPrefab(entity, initEntityPreEvent = initEntityPreEvent) } + fun Location.spawnFromPrefab( prefab: GearyEntity, existingPDC: PersistentDataContainer? = null, + initEntityPreEvent: GearyEntity.() -> Unit = {} ): Result { return runCatching { val entity = entity { if (existingPDC != null) loadComponentsFrom(existingPDC) extend(prefab) + initEntityPreEvent() emit(AttemptSpawn(this@spawnFromPrefab)) } val bukkit = entity.get() ?: error("Entity was not created when spawning from prefab")