Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Revert back to coroutine on modelengine, avoid component access error…
Browse files Browse the repository at this point in the history
… from the yield by reading beforehand
  • Loading branch information
0ffz committed Nov 30, 2023
1 parent 8b51660 commit df82e11
Showing 1 changed file with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,50 +1,60 @@
package com.mineinabyss.mobzy.modelengine.intializers

import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.Pointers
import com.mineinabyss.idofront.typealiases.BukkitEntity
import com.mineinabyss.idofront.util.randomOrMin
import com.mineinabyss.mobzy.mobzy
import com.ticxo.modelengine.api.ModelEngineAPI
import kotlinx.coroutines.yield
import org.bukkit.Color

class SetModelEngineModelSystem : GearyListener() {
val Pointers.bukkit by get<BukkitEntity>().whenSetOnTarget()
val Pointers.model by get<SetModelEngineModel>().whenSetOnTarget()

override fun Pointers.handle() {
val modelEntity = ModelEngineAPI.getOrCreateModeledEntity(bukkit)
val blueprint =
ModelEngineAPI.getBlueprint(model.modelId) ?: error("No blueprint registered for ${model.modelId}")
val bukkit = bukkit
val model = model
mobzy.plugin.launch {
yield() // Wait till next tick so some entity stuff gets initialized
if (bukkit.isDead) return@launch
val modelEntity = ModelEngineAPI.getOrCreateModeledEntity(bukkit)
val blueprint =
ModelEngineAPI.getBlueprint(model.modelId) ?: error("No blueprint registered for ${model.modelId}")

val createdModel = ModelEngineAPI.createActiveModel(blueprint).apply {
if (model.damageTint) damageTint = Color.RED
val scale = model.scale.randomOrMin()
setScale(scale)
setHitboxScale(scale)
}
val createdModel = ModelEngineAPI.createActiveModel(blueprint).apply {
if (model.damageTint) damageTint = Color.RED
val scale = model.scale.randomOrMin()
setScale(scale)
setHitboxScale(scale)
}

modelEntity.apply {
addModel(createdModel, true)
this.base.maxStepHeight = model.stepHeight
isBaseEntityVisible = !model.invisible
base.bodyRotationController.rotationDuration = 20
base.data?.let { data ->
model.verticalCull?.let {
data.verticalCull = true
data.verticalCullType = it.type
data.verticalCullDistance = it.distance
}
model.backCull?.let {
data.backCull = true
data.backCullAngle = it.angle
data.backCullType = it.type
data.backCullIgnoreRadius = it.ignoreRadius
}
model.blockedCull?.let {
data.blockedCull = true
data.blockedCullType = it.type
data.blockedCullIgnoreRadius = it.ignoreRadius
modelEntity.apply {
addModel(createdModel, true)
this.base.maxStepHeight = model.stepHeight
isBaseEntityVisible = !model.invisible
base.bodyRotationController.rotationDuration = 20
base.data?.let { data ->
model.verticalCull?.let {
data.verticalCull = true
data.verticalCullType = it.type
data.verticalCullDistance = it.distance
}
model.backCull?.let {
data.backCull = true
data.backCullAngle = it.angle
data.backCullType = it.type
data.backCullIgnoreRadius = it.ignoreRadius
}
model.blockedCull?.let {
data.blockedCull = true
data.blockedCullType = it.type
data.blockedCullIgnoreRadius = it.ignoreRadius
}
}

}
}
}
Expand Down

0 comments on commit df82e11

Please sign in to comment.