Skip to content

Commit

Permalink
fix: ensure furniture is tracked before adding prefabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 22, 2024
1 parent 6bf7314 commit 3e4502d
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mineinabyss.blocky.helpers

import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.blocky.blocky
import com.mineinabyss.blocky.components.core.BlockyFurniture
import com.mineinabyss.blocky.components.features.BlockyDrops
import com.mineinabyss.blocky.components.features.furniture.BlockyAssociatedSeats
Expand All @@ -14,6 +16,10 @@ import com.mineinabyss.idofront.items.editItemMeta
import com.mineinabyss.idofront.plugin.Plugins
import com.mineinabyss.idofront.spawning.spawn
import com.ticxo.modelengine.api.ModelEngineAPI
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.yield
import io.papermc.paper.math.Position
import net.kyori.adventure.text.Component
import org.bukkit.Location
Expand Down Expand Up @@ -42,6 +48,7 @@ object FurnitureHelpers {

fun collisionHitboxLocations(rotation: Float, center: Location, hitbox: Set<BlockyFurniture.CollisionHitbox>): List<Location> =
hitbox.map { c -> c.location.groundRotate(rotation).add(center) }

fun collisionHitboxPositions(rotation: Float, center: Location, hitbox: Set<BlockyFurniture.CollisionHitbox>): List<Position> =
collisionHitboxLocations(rotation, center, hitbox).map { Position.block(it) }

Expand Down Expand Up @@ -104,7 +111,7 @@ object FurnitureHelpers {
this.itemStack = furnitureItem
} ?: return null

newFurniture.toGeary().extend(gearyEntity)
blocky.plugin.launch { newFurniture.delayUntilTracked().extend(gearyEntity) }
gearyEntity.get<BlockyModelEngine>()?.let { meg ->
if (!Plugins.isEnabled("ModelEngine")) return@let
val activeModel = ModelEngineAPI.createActiveModel(meg.modelId) ?: return@let
Expand Down Expand Up @@ -142,4 +149,11 @@ object FurnitureHelpers {
internal fun ItemDisplay.handleFurnitureDrops(player: Player) {
this.toGearyOrNull()?.get<BlockyDrops>()?.let { GenericHelpers.handleBlockDrop(it, player, location) }
}

internal suspend fun ItemDisplay.delayUntilTracked() = coroutineScope {
async {
while (toGearyOrNull() == null) delay(1)
toGeary()
}
}.await()
}

0 comments on commit 3e4502d

Please sign in to comment.