From 71453bacc49da2ff4c19e3534a96105e5ee2e856 Mon Sep 17 00:00:00 2001 From: Will FP Date: Tue, 28 Nov 2023 14:02:09 +0000 Subject: [PATCH] Added persistent option to categories --- .../kotlin/com/willfp/ecomobs/category/MobCategory.kt | 8 ++++++++ .../ecomobs/category/impl/ConfigDrivenMobCategory.kt | 10 ++++++++++ .../com/willfp/ecomobs/mob/impl/ConfigDrivenEcoMob.kt | 3 +++ .../src/main/resources/categories/_example.yml | 6 +++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/MobCategory.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/MobCategory.kt index 1308b3a..e2c9b76 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/MobCategory.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/MobCategory.kt @@ -4,10 +4,18 @@ import com.willfp.eco.core.registry.KRegistrable import com.willfp.ecomobs.category.spawning.SpawnMethod import com.willfp.ecomobs.mob.EcoMob import com.willfp.ecomobs.mob.EcoMobs +import com.willfp.ecomobs.mob.LivingMob interface MobCategory : KRegistrable { val mobs: List get() = EcoMobs.values().filter { it.category == this } val spawnMethod: SpawnMethod + + val isPersistent: Boolean + + /** + * Apply category attributes to [mob]. + */ + fun applyToMob(mob: LivingMob) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/impl/ConfigDrivenMobCategory.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/impl/ConfigDrivenMobCategory.kt index dfeabfe..48c0333 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/impl/ConfigDrivenMobCategory.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/impl/ConfigDrivenMobCategory.kt @@ -5,6 +5,7 @@ import com.willfp.ecomobs.EcoMobsPlugin import com.willfp.ecomobs.category.MobCategory import com.willfp.ecomobs.category.spawning.SpawnMethodFactories import com.willfp.ecomobs.config.ConfigViolationException +import com.willfp.ecomobs.mob.LivingMob import com.willfp.libreforge.ConfigViolation import com.willfp.libreforge.ViolationContext @@ -30,6 +31,15 @@ class ConfigDrivenMobCategory( it.with("spawning") } + override val isPersistent = config.getBool("persistent") + + override fun applyToMob(mob: LivingMob) { + if (isPersistent) { + mob.entity.isPersistent = true + mob.entity.removeWhenFarAway = false + } + } + override fun onRegister() { spawnMethod.start() } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/impl/ConfigDrivenEcoMob.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/impl/ConfigDrivenEcoMob.kt index 5a3dabc..1b4978c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/impl/ConfigDrivenEcoMob.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/impl/ConfigDrivenEcoMob.kt @@ -394,6 +394,9 @@ internal class ConfigDrivenEcoMob( action(livingMob) } + // Apply category + category.applyToMob(livingMob) + // Add base tickets livingMob.addTickHandler(TickHandlerDisplayName()) livingMob.addTickHandler(TickHandlerLifespan()) diff --git a/eco-core/core-plugin/src/main/resources/categories/_example.yml b/eco-core/core-plugin/src/main/resources/categories/_example.yml index 8435994..ac87a51 100644 --- a/eco-core/core-plugin/src/main/resources/categories/_example.yml +++ b/eco-core/core-plugin/src/main/resources/categories/_example.yml @@ -38,4 +38,8 @@ spawning: conditions: [ ] # The chance for the mob to spawn if a valid spawn point is found (as a percentage) - chance: 100 \ No newline at end of file + chance: 100 + + +# If the mob is persistent, then it will not despawn naturally. +persistent: false