Skip to content

Commit

Permalink
Add prefab component first
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed May 4, 2022
1 parent d2dac43 commit e76dff8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ internal fun KoinComponent.debug(message: Any?) {
if (get<GearyConfig>().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)

0 comments on commit e76dff8

Please sign in to comment.