9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-22 08:29:20 +00:00

Added persistent option to categories

This commit is contained in:
Will FP
2023-11-28 14:02:09 +00:00
parent 09ea053ef7
commit 71453bacc4
4 changed files with 26 additions and 1 deletions

View File

@@ -4,10 +4,18 @@ import com.willfp.eco.core.registry.KRegistrable
import com.willfp.ecomobs.category.spawning.SpawnMethod import com.willfp.ecomobs.category.spawning.SpawnMethod
import com.willfp.ecomobs.mob.EcoMob import com.willfp.ecomobs.mob.EcoMob
import com.willfp.ecomobs.mob.EcoMobs import com.willfp.ecomobs.mob.EcoMobs
import com.willfp.ecomobs.mob.LivingMob
interface MobCategory : KRegistrable { interface MobCategory : KRegistrable {
val mobs: List<EcoMob> val mobs: List<EcoMob>
get() = EcoMobs.values().filter { it.category == this } get() = EcoMobs.values().filter { it.category == this }
val spawnMethod: SpawnMethod val spawnMethod: SpawnMethod
val isPersistent: Boolean
/**
* Apply category attributes to [mob].
*/
fun applyToMob(mob: LivingMob)
} }

View File

@@ -5,6 +5,7 @@ import com.willfp.ecomobs.EcoMobsPlugin
import com.willfp.ecomobs.category.MobCategory import com.willfp.ecomobs.category.MobCategory
import com.willfp.ecomobs.category.spawning.SpawnMethodFactories import com.willfp.ecomobs.category.spawning.SpawnMethodFactories
import com.willfp.ecomobs.config.ConfigViolationException import com.willfp.ecomobs.config.ConfigViolationException
import com.willfp.ecomobs.mob.LivingMob
import com.willfp.libreforge.ConfigViolation import com.willfp.libreforge.ConfigViolation
import com.willfp.libreforge.ViolationContext import com.willfp.libreforge.ViolationContext
@@ -30,6 +31,15 @@ class ConfigDrivenMobCategory(
it.with("spawning") 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() { override fun onRegister() {
spawnMethod.start() spawnMethod.start()
} }

View File

@@ -394,6 +394,9 @@ internal class ConfigDrivenEcoMob(
action(livingMob) action(livingMob)
} }
// Apply category
category.applyToMob(livingMob)
// Add base tickets // Add base tickets
livingMob.addTickHandler(TickHandlerDisplayName()) livingMob.addTickHandler(TickHandlerDisplayName())
livingMob.addTickHandler(TickHandlerLifespan()) livingMob.addTickHandler(TickHandlerLifespan())

View File

@@ -39,3 +39,7 @@ spawning:
# The chance for the mob to spawn if a valid spawn point is found (as a percentage) # The chance for the mob to spawn if a valid spawn point is found (as a percentage)
chance: 100 chance: 100
# If the mob is persistent, then it will not despawn naturally.
persistent: false