From e76dff8838d7ec05588807a95dc70fd6223f9106 Mon Sep 17 00:00:00 2001 From: 0ffz Date: Wed, 4 May 2022 09:52:31 -0400 Subject: [PATCH] Add prefab component first --- .../com/mineinabyss/geary/prefabs/PrefabManager.kt | 4 ++-- .../configuration/systems/ParseChildOnPrefab.kt | 2 +- .../com/mineinabyss/geary/papermc/helpers/Helpers.kt | 11 +++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt b/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt index 587bb2b08..4b33dfa0f 100644 --- a/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt +++ b/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt @@ -58,11 +58,11 @@ class PrefabManager : GearyContext by GearyContextKoin() { val decoded = formats[ext]?.decodeFromFile(serializer, file.toOkioPath()) ?: error("Unknown file format $ext") val entity = writeTo ?: entity() + entity.set(Prefab(file)) + entity.setRelation(Prefab::class, NoInherit) entity.setAll(decoded) val key = PrefabKey.of(namespace, name) - entity.set(Prefab(file)) - entity.setRelation(Prefab::class, NoInherit) registerPrefab(key, entity) entity }.onFailure { diff --git a/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/configuration/systems/ParseChildOnPrefab.kt b/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/configuration/systems/ParseChildOnPrefab.kt index 9229b5cd3..f472d0a1d 100644 --- a/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/configuration/systems/ParseChildOnPrefab.kt +++ b/geary-prefabs/src/main/kotlin/com/mineinabyss/geary/prefabs/configuration/systems/ParseChildOnPrefab.kt @@ -34,9 +34,9 @@ class ParseChildrenOnPrefab : GearyListener() { private fun TargetScope.convertToRelation() { children.nameToComponents.forEach { (name, components) -> entity { - addParent(entity) set(EntityName(name)) set(Prefab()) + addParent(entity) setRelation(Prefab::class, NoInherit) setAll(components) } diff --git a/platforms/papermc/core/src/main/kotlin/com/mineinabyss/geary/papermc/helpers/Helpers.kt b/platforms/papermc/core/src/main/kotlin/com/mineinabyss/geary/papermc/helpers/Helpers.kt index b5a5a1f46..037c8e64b 100644 --- a/platforms/papermc/core/src/main/kotlin/com/mineinabyss/geary/papermc/helpers/Helpers.kt +++ b/platforms/papermc/core/src/main/kotlin/com/mineinabyss/geary/papermc/helpers/Helpers.kt @@ -17,18 +17,17 @@ internal fun KoinComponent.debug(message: Any?) { if (get().debug) broadcast(message) } -public fun Location.spawnFromPrefab(prefab: PrefabKey): Entity? { +fun Location.spawnFromPrefab(prefab: PrefabKey): Entity? { val entity = globalContextMC.prefabManager[prefab] ?: return null return spawnFromPrefab(entity) } -public fun Location.spawnFromPrefab(prefab: GearyEntity): Entity? { +fun Location.spawnFromPrefab(prefab: GearyEntity): Entity? { val attemptSpawn = GearyAttemptMinecraftSpawnEvent(this, prefab) attemptSpawn.call() - val bukkitEntity = attemptSpawn.bukkitEntity ?: return null - return bukkitEntity + return attemptSpawn.bukkitEntity } -public fun NamespacedKey.toPrefabKey(): PrefabKey = PrefabKey.of(namespace, key) -public fun PrefabKey.toNamespacedKey(): NamespacedKey = NamespacedKey(namespace, key) +fun NamespacedKey.toPrefabKey(): PrefabKey = PrefabKey.of(namespace, key) +fun PrefabKey.toNamespacedKey(): NamespacedKey = NamespacedKey(namespace, key)