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

Commit

Permalink
Fix leak with double spawning entities on chunk load
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Dec 18, 2023
1 parent 130f311 commit b0b6d29
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
Expand Down Expand Up @@ -54,7 +53,6 @@ dependencies {
compileOnly(libs.kotlinx.coroutines)
compileOnly(libs.minecraft.mccoroutine)
compileOnly(libs.idofront.di)
compileOnly(libs.minecraft.plugin.modelengine)

// Shaded
api(project(":mobzy-pathfinding"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.mineinabyss.mobzy.mobzy
import com.ticxo.modelengine.api.ModelEngineAPI
import kotlinx.coroutines.yield
import org.bukkit.Color
import com.ticxo.modelengine.api.utils.data.io.SavedData as ModelEngineSaveData

class SetModelEngineModelSystem : GearyListener() {
val Pointers.bukkit by get<BukkitEntity>().whenSetOnTarget()
Expand All @@ -20,6 +21,10 @@ class SetModelEngineModelSystem : GearyListener() {
mobzy.plugin.launch {
yield() // Wait till next tick so some entity stuff gets initialized
if (bukkit.isDead) return@launch

// MEG persists models by default, this ensures any geary entities are handling models on their own
if (bukkit.persistentDataContainer.has(ModelEngineSaveData.DATA_KEY))
bukkit.persistentDataContainer.remove(ModelEngineSaveData.DATA_KEY)
val modelEntity = ModelEngineAPI.getOrCreateModeledEntity(bukkit)
val blueprint =
ModelEngineAPI.getBlueprint(model.modelId) ?: error("No blueprint registered for ${model.modelId}")
Expand All @@ -32,7 +37,8 @@ class SetModelEngineModelSystem : GearyListener() {
}

modelEntity.apply {
addModel(createdModel, true)
setSaved(false)
addModel(createdModel, true).ifPresent { it.destroy() }
this.base.maxStepHeight = model.stepHeight
isBaseEntityVisible = !model.invisible
base.bodyRotationController.rotationDuration = 20
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from("com.mineinabyss:catalog:$idofrontVersion")
version("modelengine", "R4.0.4")
}
create("myLibs").from(files("gradle/myLibs.versions.toml"))
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mineinabyss.mobzy

import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher
import com.mineinabyss.geary.autoscan.autoscan
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.idofront.config.config
Expand All @@ -24,6 +25,7 @@ import com.mineinabyss.mobzy.modelengine.ModelEngineSupport
import com.mineinabyss.mobzy.pathfinding.components.PathfinderComponent
import com.mineinabyss.mobzy.spawning.MobzySpawnFeature
import com.mineinabyss.mobzy.spawning.WorldGuardSpawnFlags
import kotlinx.coroutines.cancel
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin

Expand Down Expand Up @@ -78,6 +80,7 @@ class MobzyPlugin : JavaPlugin() {

override fun onDisable() {
super.onDisable()
minecraftDispatcher.cancel()
}

fun createMobzyContext() {
Expand Down

0 comments on commit b0b6d29

Please sign in to comment.