mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-22 00:19:30 +00:00
Added persistent option to categories
This commit is contained in:
@@ -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<EcoMob>
|
||||
get() = EcoMobs.values().filter { it.category == this }
|
||||
|
||||
val spawnMethod: SpawnMethod
|
||||
|
||||
val isPersistent: Boolean
|
||||
|
||||
/**
|
||||
* Apply category attributes to [mob].
|
||||
*/
|
||||
fun applyToMob(mob: LivingMob)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -394,6 +394,9 @@ internal class ConfigDrivenEcoMob(
|
||||
action(livingMob)
|
||||
}
|
||||
|
||||
// Apply category
|
||||
category.applyToMob(livingMob)
|
||||
|
||||
// Add base tickets
|
||||
livingMob.addTickHandler(TickHandlerDisplayName())
|
||||
livingMob.addTickHandler(TickHandlerLifespan())
|
||||
|
||||
@@ -39,3 +39,7 @@ spawning:
|
||||
|
||||
# The chance for the mob to spawn if a valid spawn point is found (as a percentage)
|
||||
chance: 100
|
||||
|
||||
|
||||
# If the mob is persistent, then it will not despawn naturally.
|
||||
persistent: false
|
||||
|
||||
Reference in New Issue
Block a user