diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 67a652a19..859d1c1b5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,8 +18,9 @@ jobs: - uses: MineInAbyss/publish-action@master with: maven-metadata-url: https://repo.mineinabyss.com/releases/com/mineinabyss/mobzy/maven-metadata.xml - pages-path: build/dokka/htmlMultiModule/ - dokka: dokkaHtmlMultiModule + maven-snapshot-metadata-url: https://repo.mineinabyss.com/snapshots/com/mineinabyss/mobzy/maven-metadata.xml +# pages-path: build/dokka/htmlMultiModule/ +# dokka: dokkaHtmlMultiModule maven-username: ${{ secrets.MAVEN_PUBLISH_USERNAME }} maven-password: ${{ secrets.MAVEN_PUBLISH_PASSWORD }} release-files: | diff --git a/build.gradle.kts b/build.gradle.kts index cbc7bbcb5..2c41253a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,14 +2,14 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @Suppress("DSL_SCOPE_VIOLATION") plugins { - alias(libs.plugins.mia.kotlin.jvm) - alias(libs.plugins.kotlinx.serialization) - alias(libs.plugins.mia.papermc) - alias(libs.plugins.mia.nms) - alias(libs.plugins.mia.copyjar) - alias(libs.plugins.mia.publication) - alias(libs.plugins.mia.testing) - alias(libs.plugins.mia.autoversion) + alias(idofrontLibs.plugins.mia.kotlin.jvm) + alias(idofrontLibs.plugins.kotlinx.serialization) + alias(idofrontLibs.plugins.mia.papermc) + alias(idofrontLibs.plugins.mia.nms) + alias(idofrontLibs.plugins.mia.copyjar) + alias(idofrontLibs.plugins.mia.publication) + alias(idofrontLibs.plugins.mia.testing) + alias(idofrontLibs.plugins.mia.autoversion) } allprojects { @@ -36,24 +36,24 @@ allprojects { } dependencies { + val idofrontLibs = rootProject.idofrontLibs val libs = rootProject.libs - val myLibs = rootProject.myLibs - compileOnly(myLibs.geary.papermc) + compileOnly(libs.geary.papermc) - implementation(libs.bundles.idofront.core) - implementation(libs.idofront.nms) + implementation(idofrontLibs.bundles.idofront.core) + implementation(idofrontLibs.idofront.nms) } } dependencies { // MineInAbyss platform - compileOnly(libs.kotlin.stdlib) - compileOnly(libs.kotlinx.serialization.json) - compileOnly(libs.kotlinx.serialization.kaml) - compileOnly(libs.kotlinx.coroutines) - compileOnly(libs.minecraft.mccoroutine) - compileOnly(libs.idofront.di) + compileOnly(idofrontLibs.kotlin.stdlib) + compileOnly(idofrontLibs.kotlinx.serialization.json) + compileOnly(idofrontLibs.kotlinx.serialization.kaml) + compileOnly(idofrontLibs.kotlinx.coroutines) + compileOnly(idofrontLibs.minecraft.mccoroutine) + compileOnly(idofrontLibs.idofront.di) // Shaded api(project(":mobzy-pathfinding")) @@ -63,8 +63,8 @@ dependencies { api(project(":mobzy-modelengine")) // Testing - testImplementation(libs.kotlin.statistics) - testImplementation(libs.minecraft.mockbukkit) - testImplementation(libs.kotlinx.serialization.json) - testImplementation(libs.kotlinx.serialization.kaml) + testImplementation(idofrontLibs.kotlin.statistics) + testImplementation(idofrontLibs.minecraft.mockbukkit) + testImplementation(idofrontLibs.kotlinx.serialization.json) + testImplementation(idofrontLibs.kotlinx.serialization.kaml) } diff --git a/gradle.properties b/gradle.properties index addee3b05..954c2990b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss version=0.24 -idofrontVersion=0.21.12 +idofrontVersion=0.22.3 diff --git a/gradle/myLibs.versions.toml b/gradle/libs.versions.toml similarity index 79% rename from gradle/myLibs.versions.toml rename to gradle/libs.versions.toml index 87102aef0..e0571b7d3 100644 --- a/gradle/myLibs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -gearyPaper = "0.29-SNAPSHOT" +gearyPaper = "0.29.12-dev.1" [libraries] geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" } diff --git a/mobzy-core/build.gradle.kts b/mobzy-core/build.gradle.kts index f3351bc7b..c1432057b 100644 --- a/mobzy-core/build.gradle.kts +++ b/mobzy-core/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } dependencies { - compileOnly(libs.kotlinx.serialization.json) + compileOnly(idofrontLibs.kotlinx.serialization.json) // As a rule, core must not depend on any other modules } diff --git a/mobzy-features/build.gradle.kts b/mobzy-features/build.gradle.kts index b7137b2d8..ea2cd3386 100644 --- a/mobzy-features/build.gradle.kts +++ b/mobzy-features/build.gradle.kts @@ -7,12 +7,12 @@ plugins { } dependencies { - compileOnly(libs.kotlinx.serialization.json) - compileOnly(libs.kotlinx.serialization.kaml) - compileOnly(libs.kotlinx.coroutines) - compileOnly(libs.minecraft.mccoroutine) + compileOnly(idofrontLibs.kotlinx.serialization.json) + compileOnly(idofrontLibs.kotlinx.serialization.kaml) + compileOnly(idofrontLibs.kotlinx.coroutines) + compileOnly(idofrontLibs.minecraft.mccoroutine) - compileOnly(libs.minecraft.plugin.protocollib) + compileOnly(idofrontLibs.minecraft.plugin.protocollib) compileOnly(project(":mobzy-core")) } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/bossbar/BossBarDisplaySystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/bossbar/BossBarDisplayListener.kt similarity index 54% rename from mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/bossbar/BossBarDisplaySystem.kt rename to mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/bossbar/BossBarDisplayListener.kt index f039d9fbf..aa79c2a30 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/bossbar/BossBarDisplaySystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/bossbar/BossBarDisplayListener.kt @@ -1,11 +1,13 @@ package com.mineinabyss.mobzy.features.bossbar import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.modules.GearyModule import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.geary.systems.RepeatingSystem -import com.mineinabyss.geary.systems.accessors.Pointer +import com.mineinabyss.geary.systems.builders.system +import com.mineinabyss.geary.systems.query.Query import com.mineinabyss.idofront.entities.toPlayer import com.mineinabyss.idofront.typealiases.BukkitEntity +import com.mineinabyss.mobzy.features.bossbar.BossBarDisplayListener.Companion.updateHealth import org.bukkit.attribute.Attribute import org.bukkit.entity.LivingEntity import org.bukkit.entity.Player @@ -15,32 +17,32 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent import org.bukkit.event.entity.EntityDeathEvent import kotlin.time.Duration.Companion.seconds -/** - * Handles displaying of boss bars to players in range. - * Uses values from the DisplayBossBar component. - */ -@AutoScan -class BossBarDisplaySystem : RepeatingSystem(interval = 0.5.seconds), Listener { - private val Pointer.bossbar by get() - private val Pointer.bukkitentity by get() +fun GearyModule.createBossBarDisplaySystem() = system(object : Query() { + val bossbar by get() + val bukkitentity by get() +}).every(0.5.seconds).exec { + val bukkit = bukkitentity as? LivingEntity ?: return@exec + val playersInRange = bukkitentity.getNearbyEntities(bossbar.range, bossbar.range, bossbar.range) + .filterIsInstance().mapTo(mutableSetOf()) { it.uniqueId } - override fun Pointer.tick() { - val bukkit = bukkitentity as? LivingEntity ?: return - val playersInRange = bukkitentity.getNearbyEntities(bossbar.range, bossbar.range, bossbar.range) - .filterIsInstance().mapTo(mutableSetOf()) { it.uniqueId } + // Gets players to add and remove + val addPlayers = playersInRange - bossbar.playersInRange + val removePlayers = bossbar.playersInRange - playersInRange - // Gets players to add and remove - val addPlayers = playersInRange - bossbar.playersInRange - val removePlayers = bossbar.playersInRange - playersInRange + // Removes and adds the necessary players + bossbar.playersInRange.removeAll(removePlayers) + bossbar.playersInRange.addAll(addPlayers) - // Removes and adds the necessary players - bossbar.playersInRange.removeAll(removePlayers) - bossbar.playersInRange.addAll(addPlayers) + addPlayers.forEach { it.toPlayer()?.showBossBar(bossbar.bossBar) } + removePlayers.forEach { it.toPlayer()?.hideBossBar(bossbar.bossBar) } + bossbar.updateHealth(bukkit) +} - addPlayers.forEach { it.toPlayer()?.showBossBar(bossbar.bossBar) } - removePlayers.forEach { it.toPlayer()?.hideBossBar(bossbar.bossBar) } - bossbar.updateHealth(bukkit) - } +/** + * Handles displaying of boss bars to players in range. + * Uses values from the DisplayBossBar component. + */ +class BossBarDisplayListener : Listener { fun EntityDeathEvent.onDeath() { val bossBar = entity.toGearyOrNull()?.get() ?: return diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/copynbt/CopyNBTSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/copynbt/CopyNBTSystem.kt index 577146fd3..1ece8b800 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/copynbt/CopyNBTSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/copynbt/CopyNBTSystem.kt @@ -1,10 +1,10 @@ package com.mineinabyss.mobzy.features.copynbt -import com.mineinabyss.geary.annotations.optin.UnsafeAccessors import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.modules.GearyModule import com.mineinabyss.geary.papermc.datastore.loadComponentsFrom -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.nms.aliases.toNMS import com.mineinabyss.idofront.typealiases.BukkitEntity @@ -14,14 +14,12 @@ import com.mineinabyss.idofront.typealiases.BukkitEntity * This is useful for getting a duplicate version of an old entity. */ @AutoScan -class CopyNBTSystem : GearyListener() { - private val Pointers.nbt by get().whenSetOnTarget() - private val Pointers.bukkitEntity by get().whenSetOnTarget() - - @OptIn(UnsafeAccessors::class) - override fun Pointers.handle() { - bukkitEntity.toNMS().load(nbt.compound) - target.entity.loadComponentsFrom(bukkitEntity.persistentDataContainer) - target.entity.remove() - } +fun GearyModule.createCopyNBTSystem() = listener(object : ListenerQuery() { + val bukkitEntity by get() + val nbt by get() + override fun ensure() = event.anySet(::bukkitEntity, ::nbt) +}).exec { + bukkitEntity.toNMS().load(nbt.compound) + entity.loadComponentsFrom(bukkitEntity.persistentDataContainer) + entity.remove() } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DropsSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DropsSystem.kt index f2f8b30dd..91972bb54 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DropsSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DropsSystem.kt @@ -1,8 +1,10 @@ package com.mineinabyss.mobzy.features.drops +import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.modules.GearyModule import com.mineinabyss.geary.papermc.bridge.events.entities.Drops -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.spawning.spawn import com.mineinabyss.idofront.typealiases.BukkitEntity import com.mineinabyss.idofront.util.randomOrMin @@ -12,35 +14,34 @@ import org.bukkit.entity.Item import org.bukkit.entity.LivingEntity import org.bukkit.event.entity.EntityDamageEvent.DamageCause -class DropsSystem : GearyListener() { - private val Pointers.drops by get().orNull().on(event) - private val Pointers.bukkit by get().on(target) - private val Pointers.deathLoot by get().on(source) +@AutoScan +fun GearyModule.mobDropsSystem() = listener(object : ListenerQuery() { + val bukkit by get() + val deathLoot by source.get() + val drops by event.get().orNull() +}).exec { + val bukkit = bukkit + val drops = drops - override fun Pointers.handle() { - val bukkit = bukkit - val drops = drops - - // Drop equipped items from rideable entity + // Drop equipped items from rideable entity // if(entity is Saddleable) drops.add(ItemStack(Material.SADDLE)) - val ignoredCauses = mutableListOf() - deathLoot.drops.forEach { mobDrop -> - ignoredCauses.addAll(mobDrop.ignoredCauses) + val ignoredCauses = mutableListOf() + deathLoot.drops.forEach { mobDrop -> + ignoredCauses.addAll(mobDrop.ignoredCauses) + } + val exp = deathLoot.drops.mapNotNull { it.exp?.randomOrMin() }.sum() + if (bukkit.lastDamageCause?.cause !in ignoredCauses) { + drops?.items?.clear() + drops?.exp = 0 + val looting = (bukkit as? LivingEntity) + ?.killer?.inventory?.itemInMainHand + ?.enchantments?.get(Enchantment.LOOT_BONUS_MOBS) ?: 0 + val newDrops = deathLoot.drops.mapNotNull { it.chooseDrop(looting, bukkit.fireTicks > 0) } + newDrops.forEach { + bukkit.location.spawn { itemStack = it } } - val exp = deathLoot.drops.mapNotNull { it.exp?.randomOrMin() }.sum() - if (bukkit.lastDamageCause?.cause !in ignoredCauses) { - drops?.items?.clear() - drops?.exp = 0 - val looting = (bukkit as? LivingEntity) - ?.killer?.inventory?.itemInMainHand - ?.enchantments?.get(Enchantment.LOOT_BONUS_MOBS) ?: 0 - val newDrops = deathLoot.drops.mapNotNull { it.chooseDrop(looting, bukkit.fireTicks > 0) } - newDrops.forEach { - bukkit.location.spawn { itemStack = it } - } - bukkit.location.spawn() { - experience = exp - } + bukkit.location.spawn() { + experience = exp } } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetAlwaysShowName.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetAlwaysShowName.kt index 3d526c85f..72ff5a317 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetAlwaysShowName.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetAlwaysShowName.kt @@ -1,26 +1,27 @@ package com.mineinabyss.mobzy.features.initializers import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import org.bukkit.entity.AbstractSkeleton -import org.bukkit.entity.Phantom -import org.bukkit.entity.Zombie @JvmInline @Serializable @SerialName("mobzy:set.always_show_name") -value class SetAlwaysShowName(val value: Boolean = true) +value class SetAlwaysShowName(val value: Boolean = true) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetAlwaysShowNameSystem : GearyListener() { - private val Pointers.visibility by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - - override fun Pointers.handle() { - bukkit.isCustomNameVisible = visibility.value - } +fun GearyModule.customNameVisibleSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val visibility by source.get() +}).exec { + bukkit.isCustomNameVisible = visibility.value } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetAttributes.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetAttributes.kt index e5b59c6a9..5a472796a 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetAttributes.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetAttributes.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.living import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.nms.aliases.NMSEntity import com.mineinabyss.idofront.nms.aliases.toNMS import com.mineinabyss.idofront.typealiases.BukkitEntity @@ -30,49 +34,49 @@ data class SetMobAttributes( val maxHealth: Double? = null, val movementSpeed: Double? = null, val spawnReinforcements: Double? = null -) +) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetMobAttributesSystem : GearyListener() { - private val Pointers.bukkitEntity by get().whenSetOnTarget() - private val Pointers.attributes by get().whenSetOnTarget() - - override fun Pointers.handle() { - if (attributes.width != null && attributes.height != null) { - bukkitEntity.toNMS().setDimensions(attributes.width!!, attributes.height!!) - } - - // Set attributes - val living: LivingEntity = bukkitEntity as? LivingEntity ?: return +fun GearyModule.createSetMobAttributesAction() = listener(object : ListenerQuery() { + val bukkitEntity by get() + val attributes by source.get() +}).exec { + if (attributes.width != null && attributes.height != null) { + bukkitEntity.toNMS().setDimensions(attributes.width!!, attributes.height!!) + } - fun set(type: Attribute, baseValue: Double?) { - if (baseValue == null) return - living.registerAttribute(type) - living.getAttribute(type)?.baseValue = baseValue - } + // Set attributes + val living: LivingEntity = bukkitEntity as? LivingEntity ?: return@exec - with(attributes) { - set(Attribute.GENERIC_MAX_HEALTH, maxHealth) - maxHealth?.let { living.health = it } - set(Attribute.GENERIC_FOLLOW_RANGE, followRange) - set(Attribute.GENERIC_KNOCKBACK_RESISTANCE, knockbackResistance) - set(Attribute.GENERIC_MOVEMENT_SPEED, movementSpeed) - set(Attribute.GENERIC_FLYING_SPEED, flyingSpeed) - set(Attribute.GENERIC_ATTACK_DAMAGE, attackDamage) - set(Attribute.GENERIC_ATTACK_KNOCKBACK, attackKnockback) - set(Attribute.GENERIC_ATTACK_SPEED, attackSpeed) - set(Attribute.GENERIC_ARMOR, armor) - set(Attribute.GENERIC_ARMOR_TOUGHNESS, armorToughness) - set(Attribute.GENERIC_LUCK, luck) - set(Attribute.ZOMBIE_SPAWN_REINFORCEMENTS, spawnReinforcements) - set(Attribute.HORSE_JUMP_STRENGTH, jumpStrength) - } + fun set(type: Attribute, baseValue: Double?) { + if (baseValue == null) return + living.registerAttribute(type) + living.getAttribute(type)?.baseValue = baseValue } - private fun NMSEntity.setDimensions(width: Float, height: Float) { - val dimensions = NMSEntity::class.java.declaredFields.first { it.type == EntityDimensions::class.java } - dimensions.isAccessible = true - val fixed = (dimensions.get(this) as EntityDimensions).fixed - dimensions.set(this, EntityDimensions(width, height, fixed)) + with(attributes) { + set(Attribute.GENERIC_MAX_HEALTH, maxHealth) + maxHealth?.let { living.health = it } + set(Attribute.GENERIC_FOLLOW_RANGE, followRange) + set(Attribute.GENERIC_KNOCKBACK_RESISTANCE, knockbackResistance) + set(Attribute.GENERIC_MOVEMENT_SPEED, movementSpeed) + set(Attribute.GENERIC_FLYING_SPEED, flyingSpeed) + set(Attribute.GENERIC_ATTACK_DAMAGE, attackDamage) + set(Attribute.GENERIC_ATTACK_KNOCKBACK, attackKnockback) + set(Attribute.GENERIC_ATTACK_SPEED, attackSpeed) + set(Attribute.GENERIC_ARMOR, armor) + set(Attribute.GENERIC_ARMOR_TOUGHNESS, armorToughness) + set(Attribute.GENERIC_LUCK, luck) + set(Attribute.ZOMBIE_SPAWN_REINFORCEMENTS, spawnReinforcements) + set(Attribute.HORSE_JUMP_STRENGTH, jumpStrength) } } + +private fun NMSEntity.setDimensions(width: Float, height: Float) { + val dimensions = NMSEntity::class.java.declaredFields.first { it.type == EntityDimensions::class.java } + dimensions.isAccessible = true + val fixed = (dimensions.get(this) as EntityDimensions).fixed + dimensions.set(this, EntityDimensions(width, height, fixed)) +} diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCanPickupItems.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCanPickupItems.kt index 5819ed4fa..9c1bbf716 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCanPickupItems.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCanPickupItems.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.living import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,15 +14,16 @@ import org.bukkit.entity.LivingEntity @Serializable @SerialName("mobzy:set.can_pickup_items") -class SetCanPickupItems(val value: Boolean = true) +class SetCanPickupItems(val value: Boolean = true) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetCanPickupItemsSystem : GearyListener() { - private val Pointers.pickup by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - override fun Pointers.handle() { - when (val mob = bukkit) { - is LivingEntity -> mob.canPickupItems = pickup.value - } +fun GearyModule.canPickUpItemsSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val pickup by source.get() +}).exec { + when (val mob = bukkit) { + is LivingEntity -> mob.canPickupItems = pickup.value } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCollidable.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCollidable.kt index 03da9bd8b..eab7dbaac 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCollidable.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetCollidable.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.living import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -11,15 +15,15 @@ import org.bukkit.entity.LivingEntity @JvmInline @Serializable @SerialName("mobzy:set.collidable") -value class SetCollidable(val value: Boolean = true) +value class SetCollidable(val value: Boolean = true) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetCollidableSystem : GearyListener() { - private val Pointers.collidable by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - - override fun Pointers.handle() { - val entity = (bukkit as? LivingEntity) ?: return - entity.isCollidable = collidable.value - } +fun GearyModule.collidableSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val collidable by source.get() +}).exec { + val entity = (bukkit as? LivingEntity) ?: return@exec + entity.isCollidable = collidable.value } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetEquipment.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetEquipment.kt index f8586fbdb..9d54649f6 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetEquipment.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetEquipment.kt @@ -1,7 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.living -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.SerializableItemStack import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName @@ -18,19 +23,20 @@ data class SetEquipment( val chestplate: SerializableItemStack? = SerializableItemStack(), val leggings: SerializableItemStack? = SerializableItemStack(), val boots: SerializableItemStack? = SerializableItemStack() -) - -class SetEquipmentSystem : GearyListener() { - private val Pointers.equipment by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() +) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} - override fun Pointers.handle() { - val mob = bukkit as? Mob ?: return - mob.equipment.apply { - equipment.helmet?.toItemStack()?.let { helmet = it } - equipment.chestplate?.toItemStack()?.let { chestplate = it } - equipment.leggings?.toItemStack()?.let { leggings = it } - equipment.boots?.toItemStack()?.let { boots = it } - } +@AutoScan +fun GearyModule.equipmentSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val equipment by source.get() +}).exec { + val mob = bukkit as? Mob ?: return@exec + mob.equipment.apply { + equipment.helmet?.toItemStack()?.let { helmet = it } + equipment.chestplate?.toItemStack()?.let { chestplate = it } + equipment.leggings?.toItemStack()?.let { leggings = it } + equipment.boots?.toItemStack()?.let { boots = it } } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetInvisible.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetInvisible.kt index 4c0ec3012..d25573ea1 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetInvisible.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetInvisible.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.living import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -11,15 +15,15 @@ import org.bukkit.entity.LivingEntity @JvmInline @Serializable @SerialName("mobzy:set.invisible") -value class SetInvisible(val value: Boolean = true) +value class SetInvisible(val value: Boolean = true) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetInvisibleSystem : GearyListener() { - private val Pointers.visibility by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - - override fun Pointers.handle() { - val entity = (bukkit as? LivingEntity) ?: return - entity.isInvisible = visibility.value - } +fun GearyModule.invisibilitySetter() = listener(object : ListenerQuery() { + val bukkit by get() + val visibility by source.get() +}).exec { + val entity = (bukkit as? LivingEntity) ?: return@exec + entity.isInvisible = visibility.value } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetPotionEffects.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetPotionEffects.kt index 5f0a59be6..4f02e7178 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetPotionEffects.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetPotionEffects.kt @@ -1,9 +1,13 @@ package com.mineinabyss.mobzy.features.initializers.living import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn import com.mineinabyss.geary.serialization.serializers.InnerSerializer -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.PotionEffectSerializer import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.Serializable @@ -15,20 +19,20 @@ import org.bukkit.potion.PotionEffect class SetPotionEffects( val effects: List ) { - class Serializer: InnerSerializer, SetPotionEffects>( + class Serializer : InnerSerializer, SetPotionEffects>( "geary:set.potion_effects", ListSerializer(PotionEffectSerializer), { SetPotionEffects(it) }, { it.effects }, ) + + companion object : ComponentDefinition by EventHelpers.defaultTo() } @AutoScan -class SetPotionEffectsSystem : GearyListener() { - val Pointers.bukkit by get().on(target) - val Pointers.potions by get().on(source) - - override fun Pointers.handle() { - (bukkit as? LivingEntity)?.addPotionEffects(potions.effects) - } +fun GearyModule.potionEffectsSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val potions by source.get() +}).exec { + (bukkit as? LivingEntity)?.addPotionEffects(potions.effects) } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetRemoveWhenFarAway.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetRemoveWhenFarAway.kt index ad2b07ff7..b325cb126 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetRemoveWhenFarAway.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/living/SetRemoveWhenFarAway.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.living import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -13,15 +17,15 @@ import org.bukkit.entity.LivingEntity */ @Serializable @SerialName("mobzy:set.remove_when_far_away") -class SetRemoveWhenFarAway(val value: Boolean = true) +class SetRemoveWhenFarAway(val value: Boolean = true) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetRemoveWhenFarAwaySystem : GearyListener() { - private val Pointers.removeWhenFarAway by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - - override fun Pointers.handle() { - val living = bukkit as? LivingEntity ?: return - living.removeWhenFarAway = removeWhenFarAway.value - } +fun GearyModule.removeWhenFarAwaySetter() = listener(object : ListenerQuery() { + val bukkit by get() + val removeWhenFarAway by source.get() +}).exec { + val living = bukkit as? LivingEntity ?: return@exec + living.removeWhenFarAway = removeWhenFarAway.value } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/monster/SetBurnInDay.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/monster/SetBurnInDay.kt index 869a36ab0..4c4a64ca6 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/monster/SetBurnInDay.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/monster/SetBurnInDay.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.monster import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -13,18 +17,18 @@ import org.bukkit.entity.Zombie @JvmInline @Serializable @SerialName("mobzy:set.burn_in_day") -value class SetBurnInDay(val value: Boolean = true) +value class SetBurnInDay(val value: Boolean = true) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetBurnInDaySystem : GearyListener() { - private val Pointers.burn by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - - override fun Pointers.handle() { - when (val mob = bukkit) { - is Phantom -> mob.setShouldBurnInDay(burn.value) - is AbstractSkeleton -> mob.setShouldBurnInDay(burn.value) - is Zombie -> mob.setShouldBurnInDay(burn.value) - } +fun GearyModule.burnInDaySetter() = listener(object : ListenerQuery() { + val bukkit by get() + val burn by source.get() +}).exec { + when (val mob = bukkit) { + is Phantom -> mob.setShouldBurnInDay(burn.value) + is AbstractSkeleton -> mob.setShouldBurnInDay(burn.value) + is Zombie -> mob.setShouldBurnInDay(burn.value) } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/projectile/SetProjectileItemSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/projectile/SetProjectileItemSystem.kt index 5c9cd1906..02fa17b81 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/projectile/SetProjectileItemSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/projectile/SetProjectileItemSystem.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.projectile import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.SerializableItemStack import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName @@ -13,15 +17,15 @@ import org.bukkit.entity.ThrowableProjectile @SerialName("mobzy:set.projectile_item") data class SetProjectileItem( val item: SerializableItemStack -) +) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetProjectileItemSystem : GearyListener() { - private val Pointers.model by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - - override fun Pointers.handle() { - val projectile = bukkit as? ThrowableProjectile ?: return - projectile.item = model.item.toItemStack() - } +fun GearyModule.projectileItemSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val model by source.get() +}).exec { + val projectile = bukkit as? ThrowableProjectile ?: return@exec + projectile.item = model.item.toItemStack() } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt index 22ecf7bfe..2db88b935 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt @@ -1,12 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.sheep -import com.mineinabyss.geary.annotations.optin.UnsafeAccessors import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule import com.mineinabyss.geary.papermc.bridge.events.EventHelpers import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -21,15 +21,12 @@ value class SetWoolColor(val value: DyeColor) { } @AutoScan -class SetWoolColorSystem : GearyListener() { - private val Pointers.bukkit by get().on(target) - private val Pointers.woolColor by get().on(source) - - @OptIn(UnsafeAccessors::class) - override fun Pointers.handle() { - target.entity.set(SetWoolColor(woolColor.value)) - when (val mob = bukkit) { - is Colorable -> mob.color = woolColor.value - } +fun GearyModule.setWoolColorAction() = listener(object : ListenerQuery() { + val bukkit by get() + val woolColor by source.get() +}).exec { + entity.set(SetWoolColor(woolColor.value)) + when (val mob = bukkit) { + is Colorable -> mob.color = woolColor.value } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt index 6a42d4df5..6dbab0138 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt @@ -2,10 +2,11 @@ package com.mineinabyss.mobzy.features.initializers.slime import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule import com.mineinabyss.geary.papermc.bridge.events.EventHelpers import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.IntRangeSerializer import com.mineinabyss.idofront.typealiases.BukkitEntity import com.mineinabyss.idofront.util.randomOrMin @@ -21,12 +22,10 @@ value class SetSlimeSize(@Serializable(with = IntRangeSerializer::class) val siz } @AutoScan -class SetSlimeSizeSystem : GearyListener() { - private val Pointers.bukkit by get().on(target) - private val Pointers.slimeSize by get().on(source) - - override fun Pointers.handle() { - val slime = (bukkit as? Slime) ?: return - slime.size = slimeSize.size.randomOrMin() - } +fun GearyModule.slimeSizeSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val slimeSize by source.get() +}).exec { + val slime = (bukkit as? Slime) ?: return@exec + slime.size = slimeSize.size.randomOrMin() } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/zombie/SetBreakDownDoor.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/zombie/SetBreakDownDoor.kt index 02a437ca6..abfbbe491 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/zombie/SetBreakDownDoor.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/zombie/SetBreakDownDoor.kt @@ -1,8 +1,12 @@ package com.mineinabyss.mobzy.features.initializers.zombie import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -11,16 +15,16 @@ import org.bukkit.entity.Zombie @JvmInline @Serializable @SerialName("mobzy:set.break_down_door") -value class SetBreakDownDoor(val value: Boolean = false) +value class SetBreakDownDoor(val value: Boolean = false) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan -class SetBreakDownDoorListener : GearyListener() { - private val Pointers.breakDoor by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() - - override fun Pointers.handle() { - when (val mob = bukkit) { - is Zombie -> if (mob.supportsBreakingDoors()) mob.setCanBreakDoors(breakDoor.value) - } +fun GearyModule.breakDownDoorSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val breakDoor by source.get() +}).exec { + when (val mob = bukkit) { + is Zombie -> if (mob.supportsBreakingDoors()) mob.setCanBreakDoors(breakDoor.value) } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/AmbientSoundsSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/AmbientSoundsSystem.kt index daac6b93d..212de3f4b 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/AmbientSoundsSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/AmbientSoundsSystem.kt @@ -1,19 +1,19 @@ package com.mineinabyss.mobzy.features.sounds import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.RepeatingSystem -import com.mineinabyss.geary.systems.accessors.Pointer +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.system +import com.mineinabyss.geary.systems.query.Query import com.mineinabyss.idofront.time.ticks import com.mineinabyss.idofront.typealiases.BukkitEntity +import com.mineinabyss.mobzy.features.sounds.OverrideMobSoundsBukkitListener.Companion.makeSound import kotlin.random.Random @AutoScan -class AmbientSoundsSystem : RepeatingSystem(interval = 1.ticks) { - private val Pointer.sounds by get() - private val Pointer.bukkit by get() - - override fun Pointer.tick() { - if (Random.nextDouble() < sounds.ambientChance) - OverrideMobSoundsSystem.makeSound(bukkit, sounds.ambient) - } +fun GearyModule.createAmbientSoundsSystem() = system(object : Query() { + val bukkit by get() + val sounds by get() +}).every(1.ticks).exec { + if (Random.nextDouble() < sounds.ambientChance) + makeSound(bukkit, sounds.ambient) } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/OverrideMobSoundsSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/OverrideMobSoundsBukkitListener.kt similarity index 86% rename from mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/OverrideMobSoundsSystem.kt rename to mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/OverrideMobSoundsBukkitListener.kt index 4f8d513f7..37161cd2e 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/OverrideMobSoundsSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/OverrideMobSoundsBukkitListener.kt @@ -2,9 +2,6 @@ package com.mineinabyss.mobzy.features.sounds import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.idofront.destructure.component1 -import com.mineinabyss.idofront.destructure.component2 -import com.mineinabyss.idofront.destructure.component3 import com.mineinabyss.idofront.typealiases.BukkitEntity import net.kyori.adventure.key.Key import net.kyori.adventure.sound.Sound @@ -13,7 +10,7 @@ import org.bukkit.event.Listener import org.bukkit.event.entity.EntityDamageByEntityEvent import org.bukkit.event.entity.EntityDeathEvent -class OverrideMobSoundsSystem : Listener { +class OverrideMobSoundsBukkitListener : Listener { @EventHandler fun EntityDeathEvent.makeSoundOnDeath() { val sounds = entity.toGeary().get() ?: return diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/SilenceVanillaSoundsSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/SilenceVanillaSoundsSystem.kt index 30efe60f9..7c5a08058 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/SilenceVanillaSoundsSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/sounds/SilenceVanillaSoundsSystem.kt @@ -1,16 +1,16 @@ package com.mineinabyss.mobzy.features.sounds import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity @AutoScan -class SilenceVanillaSoundsSystem : GearyListener() { - private val Pointers.bukkit by get().whenSetOnTarget() - private val Pointers.sounds by get().whenSetOnTarget() - - override fun Pointers.handle() { - bukkit.isSilent = true - } +fun GearyModule.createSilenceVanillaSoundsSystem() = listener(object : ListenerQuery() { + val bukkit by get() + val sounds by get() + override fun ensure() = event.anySet(::sounds, ::bukkit) +}).exec { + bukkit.isSilent = true } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/taming/TamableListener.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/taming/TamingBukkitListener.kt similarity index 97% rename from mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/taming/TamableListener.kt rename to mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/taming/TamingBukkitListener.kt index 9dc4cc49e..f9d0a8e27 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/taming/TamableListener.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/taming/TamingBukkitListener.kt @@ -6,13 +6,12 @@ import org.bukkit.Particle import org.bukkit.Sound import org.bukkit.attribute.Attribute import org.bukkit.entity.LivingEntity -import org.bukkit.entity.Tameable import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerInteractEntityEvent import kotlin.random.Random -class TamableListener : Listener { +class TamingBukkitListener : Listener { /** Tame entities with [Tamable] component on right click */ @EventHandler fun PlayerInteractEntityEvent.tameMob() { diff --git a/mobzy-modelengine/build.gradle.kts b/mobzy-modelengine/build.gradle.kts index 1c1916159..ecb337a34 100644 --- a/mobzy-modelengine/build.gradle.kts +++ b/mobzy-modelengine/build.gradle.kts @@ -1,15 +1,15 @@ @Suppress("DSL_SCOPE_VIOLATION") plugins { - id(libs.plugins.mia.kotlin.jvm.get().pluginId) - id(libs.plugins.mia.papermc.get().pluginId) - id(libs.plugins.mia.publication.get().pluginId) - id(libs.plugins.kotlinx.serialization.get().pluginId) + id(idofrontLibs.plugins.mia.kotlin.jvm.get().pluginId) + id(idofrontLibs.plugins.mia.papermc.get().pluginId) + id(idofrontLibs.plugins.mia.publication.get().pluginId) + id(idofrontLibs.plugins.kotlinx.serialization.get().pluginId) } dependencies { - compileOnly(libs.kotlinx.serialization.json) - compileOnly(libs.minecraft.plugin.modelengine) - compileOnly(libs.minecraft.mccoroutine) + compileOnly(idofrontLibs.kotlinx.serialization.json) + compileOnly(idofrontLibs.minecraft.plugin.modelengine) + compileOnly(idofrontLibs.minecraft.mccoroutine) compileOnly(project(":mobzy-core")) } diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/ModelEngineSupport.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/ModelEngineSupport.kt index 83a83b57c..adb694b96 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/ModelEngineSupport.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/ModelEngineSupport.kt @@ -9,7 +9,7 @@ import com.mineinabyss.mobzy.mobzy import com.mineinabyss.mobzy.modelengine.animation.AnimationController import com.mineinabyss.mobzy.modelengine.animation.ModelEngineAnimationController import com.mineinabyss.mobzy.modelengine.animation.ModelInteractionListener -import com.mineinabyss.mobzy.modelengine.intializers.SetModelEngineModelSystem +import com.mineinabyss.mobzy.modelengine.intializers.createModelEngineListener import com.mineinabyss.mobzy.modelengine.nametag.ModelEngineNameTagListener import com.mineinabyss.mobzy.modelengine.riding.ModelEngineRidingListener @@ -23,12 +23,10 @@ interface ModelEngineSupport { override val animationController = ModelEngineAnimationController() } - override fun ModelEngineSupport.install() { + override fun ModelEngineSupport.install(): Unit = geary.run { DI.add(this) - geary.pipeline.addSystems( - SetModelEngineModelSystem(), - ) + createModelEngineListener() mobzy.plugin.apply { listeners( diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModelSystem.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModelSystem.kt index 05f547dd4..fb58f0324 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModelSystem.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModelSystem.kt @@ -1,8 +1,9 @@ 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.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.typealiases.BukkitEntity import com.mineinabyss.idofront.util.randomOrMin import com.mineinabyss.mobzy.mobzy @@ -11,60 +12,59 @@ 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().whenSetOnTarget() - val Pointers.model by get().whenSetOnTarget() - - override fun Pointers.handle() { - 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 +fun GearyModule.createModelEngineListener() = listener( + object : ListenerQuery() { + val bukkit by get() + val model by get() + override fun ensure() = event.anySet(::bukkit, ::model) + } +).exec { + 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}") + // 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}") - // Clear any old models - modelEntity.models.toList().forEach { (key, value) -> - modelEntity.removeModel(key) - value.destroy() - } + // Clear any old models + modelEntity.models.toList().forEach { (key, value) -> + modelEntity.removeModel(key) + value.destroy() + } - 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 { - setSaved(false) - addModel(createdModel, true).ifPresent { it.destroy() } - 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 { + setSaved(false) + addModel(createdModel, true).ifPresent { it.destroy() } + 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 } } } diff --git a/mobzy-pathfinding/build.gradle.kts b/mobzy-pathfinding/build.gradle.kts index b516d7c76..f7ff91113 100644 --- a/mobzy-pathfinding/build.gradle.kts +++ b/mobzy-pathfinding/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } dependencies { - compileOnly(libs.kotlinx.serialization.json) + compileOnly(idofrontLibs.kotlinx.serialization.json) compileOnly(project(":mobzy-core")) compileOnly(project(":mobzy-modelengine")) diff --git a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/PathfinderAttachSystem.kt b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/PathfinderAttachSystem.kt index d08f2d0c7..c557817e2 100644 --- a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/PathfinderAttachSystem.kt +++ b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/PathfinderAttachSystem.kt @@ -1,9 +1,9 @@ package com.mineinabyss.mobzy.pathfinding -import com.mineinabyss.geary.annotations.optin.UnsafeAccessors import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.nms.aliases.NMSMob import com.mineinabyss.idofront.nms.aliases.toNMS import com.mineinabyss.idofront.typealiases.BukkitEntity @@ -12,46 +12,42 @@ import net.minecraft.world.entity.ai.control.LookControl import org.bukkit.entity.Mob @AutoScan -class PathfinderAttachSystem : GearyListener() { - private val Pointers.bukkit by get().whenSetOnTarget() - private val Pointers.pathfinders by get().whenSetOnTarget() - - - private class NoLookControl(entity: NMSMob) : LookControl(entity) { - override fun tick() {} +fun GearyModule.pathfinderSetter() = listener(object : ListenerQuery() { + val bukkit by get() + val pathfinders by source.get() +}).exec { + val mob = bukkit as? Mob ?: return@exec + val nmsMob = mob.toNMS() + val (targets, goals) = pathfinders + + if (pathfinders.override) { + nmsMob.targetSelector.removeAllGoals { true } + nmsMob.goalSelector.removeAllGoals { true } } - @OptIn(UnsafeAccessors::class) - override fun Pointers.handle() { - val mob = bukkit as? Mob ?: return - val nmsMob = mob.toNMS() - val (targets, goals) = pathfinders - val entity = target.entity - - if (pathfinders.override) { - nmsMob.targetSelector.removeAllGoals { true } - nmsMob.goalSelector.removeAllGoals { true } - } - - if (pathfinders.noLookControl) { - NMSMob::class.java.declaredFields.first { it.type == LookControl::class.java }.apply { - isAccessible = true - set(nmsMob, NoLookControl(nmsMob)) - } - } - - targets?.forEachIndexed { priority, component -> - runCatching { - nmsMob.addTargetSelector(component.preferredPriority ?: priority, component) - entity.set(component) - }.onFailure { - it.printStackTrace() - } + if (pathfinders.noLookControl) { + NMSMob::class.java.declaredFields.first { it.type == LookControl::class.java }.apply { + isAccessible = true + set(nmsMob, NoLookControl(nmsMob)) } + } - goals?.forEachIndexed { priority, component -> - nmsMob.addPathfinderGoal(component.preferredPriority ?: priority, component) + targets?.forEachIndexed { priority, component -> + runCatching { + nmsMob.addTargetSelector(component.preferredPriority ?: priority, component) entity.set(component) + }.onFailure { + it.printStackTrace() } } + + goals?.forEachIndexed { priority, component -> + nmsMob.addPathfinderGoal(component.preferredPriority ?: priority, component) + entity.set(component) + } +} + + +private class NoLookControl(entity: NMSMob) : LookControl(entity) { + override fun tick() {} } diff --git a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt index 3a0c77abb..2318809c1 100644 --- a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt +++ b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt @@ -1,5 +1,8 @@ package com.mineinabyss.mobzy.pathfinding.components +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn import com.mineinabyss.geary.serialization.serializers.PolymorphicListAsMapSerializer import kotlinx.serialization.Polymorphic import kotlinx.serialization.SerialName @@ -19,4 +22,6 @@ data class Pathfinders( val goals: @Serializable(with = PolymorphicListAsMapSerializer::class) List<@Polymorphic PathfinderComponent>? = null, val noLookControl: Boolean = false, val override: Boolean = true, -) +) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} diff --git a/mobzy-spawning/build.gradle.kts b/mobzy-spawning/build.gradle.kts index 99b6d8221..3b37be80a 100644 --- a/mobzy-spawning/build.gradle.kts +++ b/mobzy-spawning/build.gradle.kts @@ -7,15 +7,15 @@ plugins { } dependencies { - compileOnly(libs.minecraft.mccoroutine) - compileOnly(libs.kotlinx.serialization.json) - compileOnly(libs.kotlinx.serialization.kaml) - compileOnly(libs.kotlinx.coroutines) - compileOnly(libs.kotlin.statistics) { + compileOnly(idofrontLibs.minecraft.mccoroutine) + compileOnly(idofrontLibs.kotlinx.serialization.json) + compileOnly(idofrontLibs.kotlinx.serialization.kaml) + compileOnly(idofrontLibs.kotlinx.coroutines) + compileOnly(idofrontLibs.kotlin.statistics) { exclude(group = "org.jetbrains.kotlin") } - compileOnly(libs.minecraft.plugin.worldguard) { exclude(group = "org.bukkit") } + compileOnly(idofrontLibs.minecraft.plugin.worldguard) { exclude(group = "org.bukkit") } compileOnly(project(":mobzy-core")) } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawnFeature.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawnFeature.kt index 83f57c442..6b9062860 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawnFeature.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawnFeature.kt @@ -1,7 +1,6 @@ package com.mineinabyss.mobzy.spawning import com.mineinabyss.geary.modules.geary -import com.mineinabyss.idofront.config.IdofrontConfig import com.mineinabyss.idofront.config.config import com.mineinabyss.idofront.di.DI import com.mineinabyss.idofront.features.Configurable @@ -12,8 +11,8 @@ import com.mineinabyss.mobzy.mobzy val mobzySpawning by DI.observe() -class MobzySpawnFeature: FeatureWithContext(::Context) { - class Context: Configurable { +class MobzySpawnFeature : FeatureWithContext(::Context) { + class Context : Configurable { override val configManager = config("spawning", mobzy.plugin.dataFolder.toPath(), SpawnConfig()) val spawnTask = SpawnTask() val spawnRegistry = SpawnRegistry() @@ -26,7 +25,6 @@ class MobzySpawnFeature: FeatureWithContext(::Context DI.add(this@MobzySpawnFeature) "Spawns" { !"Load spawns" { - geary.pipeline.addSystem(context.spawnRegistry.SpawnTracker()) context.spawnRegistry.reloadSpawns() } !"Start spawn task" { diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnDefinition.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnDefinition.kt index 050f63e64..70d3dcac9 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnDefinition.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnDefinition.kt @@ -4,10 +4,12 @@ package com.mineinabyss.mobzy.spawning import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.modules.GearyModule import com.mineinabyss.geary.papermc.tracking.entities.helpers.spawnFromPrefab import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.geary.systems.GearyListener import com.mineinabyss.geary.systems.accessors.* +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.IntRangeSerializer import com.mineinabyss.idofront.util.randomOrMin import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo @@ -74,10 +76,6 @@ enum class SpawnPosition { * be chosen when compared to other spawns. * @property spawnPos Whether the mob should be spawned directly on the ground, in air, or under cliffs. */ - -/** - * - */ data class DoSpawn( val location: Location ) { @@ -85,48 +83,47 @@ data class DoSpawn( } @AutoScan -class SpawnRequestListener : GearyListener() { - private val Pointers.type by get().on(target) - private val Pointers.amount by get().orNull().map { it?.amount }.on(target) - private val Pointers.spawnPos by get().orDefault { SpawnPosition.GROUND }.on(target) - private val Pointers.radius by get().orNull().map { it?.radius ?: 0.0 }.on(target) - - private val Pointers.spawnEvent by get().on(event) - - override fun Pointers.handle() { - val location = spawnEvent.location - val spawns = amount?.randomOrMin() ?: 1 - for (i in 0 until spawns) { - val chosenLoc = - if (spawnPos != SpawnPosition.AIR) - getSpawnInRadius(location, radius) ?: location - else location - - chosenLoc.spawnFromPrefab(type.prefab) - } - spawnEvent.spawnedAmount = spawns +fun GearyModule.spawnRequestListener() = listener(object : ListenerQuery() { + val type by get() + val amount by get().orNull().map { it?.amount } + val spawnPos by get().orDefault { SpawnPosition.GROUND } + val radius by get().orNull().map { it?.radius ?: 0.0 } + + val spawnEvent by event.get() +}).exec { + val location = spawnEvent.location + val spawns = amount?.randomOrMin() ?: 1 + for (i in 0 until spawns) { + val chosenLoc = + if (spawnPos != SpawnPosition.AIR) + getSpawnInRadius(location, radius) ?: location + else location + + chosenLoc.spawnFromPrefab(type.prefab) } + spawnEvent.spawnedAmount = spawns +} - /** - * Gets a location to spawn in a mob given an original location and min/max radii around it - * - * @param loc the location to check off of - * @param maxRad the maximum radius for the new location to be picked at - * @return a new position to spawn in - */ - private fun getSpawnInRadius(loc: Location, maxRad: Double): Location? { - if (maxRad == 0.0) return loc - if (!loc.chunk.isLoaded) return null - for (i in 0..29) { //TODO, arbitrary number, should instead search all locations around the spawn - val x = sign(Math.random() - 0.5) * Random.nextDouble(maxRad) - val z = sign(Math.random() - 0.5) * Random.nextDouble(maxRad) - val searchLoc: Location = loc.clone().add(Vector(x, 0.0, z)) - - return if (!searchLoc.block.type.isSolid) - searchLoc.checkDown(2) ?: continue - else - searchLoc.checkUp(2) ?: continue - } - return null + +/** + * Gets a location to spawn in a mob given an original location and min/max radii around it + * + * @param loc the location to check off of + * @param maxRad the maximum radius for the new location to be picked at + * @return a new position to spawn in + */ +private fun getSpawnInRadius(loc: Location, maxRad: Double): Location? { + if (maxRad == 0.0) return loc + if (!loc.chunk.isLoaded) return null + for (i in 0..29) { //TODO, arbitrary number, should instead search all locations around the spawn + val x = sign(Math.random() - 0.5) * Random.nextDouble(maxRad) + val z = sign(Math.random() - 0.5) * Random.nextDouble(maxRad) + val searchLoc: Location = loc.clone().add(Vector(x, 0.0, z)) + + return if (!searchLoc.block.type.isSolid) + searchLoc.checkDown(2) ?: continue + else + searchLoc.checkUp(2) ?: continue } + return null } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt index acf4286e5..db280c0c6 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt @@ -1,12 +1,12 @@ package com.mineinabyss.mobzy.spawning -import com.mineinabyss.geary.annotations.optin.UnsafeAccessors import com.mineinabyss.geary.datatypes.GearyEntity +import com.mineinabyss.geary.modules.geary import com.mineinabyss.geary.prefabs.prefabs -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.Pointer -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.systems.builders.cachedQuery +import com.mineinabyss.geary.systems.builders.listener import com.mineinabyss.geary.systems.query.GearyQuery +import com.mineinabyss.geary.systems.query.ListenerQuery import com.sk89q.worldguard.WorldGuard import com.sk89q.worldguard.protection.regions.ProtectedRegion @@ -20,14 +20,14 @@ class SpawnRegistry { private val regionContainer = WorldGuard.getInstance().platform.regionContainer private val regionSpawns: MutableMap> = HashMap() - val spawnConfigsQuery = SpawnConfigs() + val spawnConfigsQuery = geary.cachedQuery(SpawnConfigs()) /** Clears [regionSpawns] */ fun unregisterSpawns() = regionSpawns.clear() fun reloadSpawns() { unregisterSpawns() - spawnConfigsQuery.matchedEntities.forEach { + spawnConfigsQuery.entities().forEach { prefabLoader.reload(it) } } @@ -36,19 +36,17 @@ class SpawnRegistry { fun List.getMobSpawnsForRegions(): List = flatMap { regionSpawns[it.id] ?: setOf() } - inner class SpawnTracker : GearyListener() { - private val Pointers.parentRegions by get().whenSetOnTarget() - private val Pointers.spawn by get().whenSetOnTarget() - - @OptIn(UnsafeAccessors::class) - override fun Pointers.handle() { - parentRegions.keys.forEach { - regionSpawns.getOrPut(it) { mutableSetOf() } += target.entity - } + val spawnTracker = geary.listener(object : ListenerQuery() { + val parentRegions by get() + val spawn by get() + override fun ensure() = event.anySet(::parentRegions, ::spawn) + }).exec { + parentRegions.keys.forEach { + regionSpawns.getOrPut(it) { mutableSetOf() } += entity } } class SpawnConfigs : GearyQuery() { - val Pointer.config by get() + val config by get() } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/spawning/Important.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/components/Important.kt similarity index 82% rename from mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/spawning/Important.kt rename to mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/components/Important.kt index 5efff32d6..5cb88e1bb 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/spawning/Important.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/components/Important.kt @@ -1,4 +1,4 @@ -package com.mineinabyss.mobzy.features.spawning +package com.mineinabyss.mobzy.spawning.components import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/BlockCompositionCondition.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/BlockCompositionCondition.kt index 57e33336c..aed72d1e7 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/BlockCompositionCondition.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/BlockCompositionCondition.kt @@ -1,8 +1,9 @@ package com.mineinabyss.mobzy.spawning.conditions.components import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.events.CheckingListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.DoubleRangeSerializer import com.mineinabyss.idofront.util.DoubleRange import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo @@ -22,12 +23,11 @@ class BlockComposition( ) @AutoScan -class BlockCompositionCondition : CheckingListener() { - private val Pointers.blockComposition by get().on(source) - val Pointers.spawnInfo by get().on(event) - - override fun Pointers.check(): Boolean = - blockComposition.materials.all { (material, range) -> - spawnInfo.blockComposition.percent(material) in range - } +fun GearyModule.blockCompositionChecker() = listener(object : ListenerQuery() { + val blockComposition by source.get() + val spawnInfo by event.get() +}).check { + blockComposition.materials.all { (material, range) -> + spawnInfo.blockComposition.percent(material) in range + } } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/LocalGroupConditions.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/LocalGroupConditions.kt index ed45e311f..b34b290ab 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/LocalGroupConditions.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/LocalGroupConditions.kt @@ -1,8 +1,9 @@ package com.mineinabyss.mobzy.spawning.conditions.components import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.events.CheckingListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.mobzy.spawning.SpawnType import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo import kotlinx.serialization.SerialName @@ -22,12 +23,10 @@ class LocalGroupConditions( ) @AutoScan -class CapFull : CheckingListener() { - val Pointers.conf by get().on(source) - val Pointers.spawnType by get().on(source) - - val Pointers.spawnInfo by get().on(event) - - override fun Pointers.check(): Boolean = - spawnInfo.nearbyEntities(spawnType.prefab, conf.radius) < conf.max +fun GearyModule.mobCapChecker() = listener(object : ListenerQuery() { + val conf by source.get() + val spawnType by source.get() + val spawnInfo by event.get() +}).check { + spawnInfo.nearbyEntities(spawnType.prefab, conf.radius) < conf.max } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnDelayCondition.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnDelayCondition.kt index b11a26df8..01bdc0882 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnDelayCondition.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnDelayCondition.kt @@ -1,8 +1,9 @@ package com.mineinabyss.mobzy.spawning.conditions.components import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.events.CheckingListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.DurationSerializer import com.mineinabyss.mobzy.spawning.GlobalSpawnInfo import com.mineinabyss.mobzy.spawning.mobzySpawning @@ -18,12 +19,10 @@ class SpawnDelay( ) @AutoScan -class SpawnDelayCondition : CheckingListener() { - private val Pointers.delay by get().on(source) - - override fun Pointers.check(): Boolean { - val iterationMod = (delay.attemptEvery / mobzySpawning.config.spawnTaskDelay) - .toInt().coerceAtLeast(1) - return GlobalSpawnInfo.iterationNumber % iterationMod == 0 - } +fun GearyModule.spawnDelayCondition() = listener(object : ListenerQuery() { + val delay by source.get() +}).check { + val iterationMod = (delay.attemptEvery / mobzySpawning.config.spawnTaskDelay) + .toInt().coerceAtLeast(1) + GlobalSpawnInfo.iterationNumber % iterationMod == 0 } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnGapCondition.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnGapCondition.kt index 46a34d838..82c396470 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnGapCondition.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnGapCondition.kt @@ -1,8 +1,9 @@ package com.mineinabyss.mobzy.spawning.conditions.components import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.events.CheckingListener -import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.systems.builders.listener +import com.mineinabyss.geary.systems.query.ListenerQuery import com.mineinabyss.idofront.serialization.IntRangeSerializer import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo import kotlinx.serialization.SerialName @@ -21,11 +22,10 @@ class SpawnGap( ) @AutoScan -class SpawnGapCondition : CheckingListener() { - private val Pointers.spawnGap by get().on(source) +fun GearyModule.spawnGroupChecker() = listener(object : ListenerQuery() { + val spawnGap by source.get() - private val Pointers.spawnInfo by get().on(event) - - override fun Pointers.check(): Boolean = - spawnInfo.gap in spawnGap.range + val spawnInfo by event.get() +}).check { + spawnInfo.gap in spawnGap.range } diff --git a/settings.gradle.kts b/settings.gradle.kts index c82e9c121..d1e22579c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,11 +26,10 @@ dependencyResolutionManagement { } versionCatalogs { - create("libs") { + create("idofrontLibs") { from("com.mineinabyss:catalog:$idofrontVersion") version("modelengine", "R4.0.4") } - create("myLibs").from(files("gradle/myLibs.versions.toml")) } } diff --git a/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt b/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt index be411afe3..45d49443b 100644 --- a/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt @@ -11,16 +11,14 @@ import com.mineinabyss.idofront.features.FeatureManager import com.mineinabyss.idofront.plugin.Plugins import com.mineinabyss.idofront.plugin.actions import com.mineinabyss.idofront.plugin.listeners -import com.mineinabyss.mobzy.features.copynbt.CopyNBTSystem import com.mineinabyss.mobzy.features.despawning.RemoveOnChunkUnloadSystem import com.mineinabyss.mobzy.features.displayname.ShowDisplayNameOnKillerSystem -import com.mineinabyss.mobzy.features.drops.DropsSystem import com.mineinabyss.mobzy.features.prevent.breeding.PreventBreedingSystem import com.mineinabyss.mobzy.features.prevent.interaction.PreventInteractionSystem import com.mineinabyss.mobzy.features.prevent.regen.PreventRegenerationSystem import com.mineinabyss.mobzy.features.prevent.riding.PreventRidingSystem -import com.mineinabyss.mobzy.features.sounds.OverrideMobSoundsSystem -import com.mineinabyss.mobzy.features.taming.TamableListener +import com.mineinabyss.mobzy.features.sounds.OverrideMobSoundsBukkitListener +import com.mineinabyss.mobzy.features.taming.TamingBukkitListener import com.mineinabyss.mobzy.modelengine.ModelEngineSupport import com.mineinabyss.mobzy.pathfinding.components.PathfinderComponent import com.mineinabyss.mobzy.spawning.MobzySpawnFeature @@ -59,16 +57,11 @@ class MobzyPlugin : JavaPlugin() { PreventBreedingSystem(), RemoveOnChunkUnloadSystem(), ShowDisplayNameOnKillerSystem(), - TamableListener(), + TamingBukkitListener(), PreventRidingSystem(), PreventRegenerationSystem(), PreventInteractionSystem(), - OverrideMobSoundsSystem(), - ) - - geary.pipeline.addSystems( - CopyNBTSystem(), - DropsSystem(), + OverrideMobSoundsBukkitListener(), ) geary { diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml index 4e9f8f6ae..86da5b1ed 100644 --- a/src/main/resources/paper-plugin.yml +++ b/src/main/resources/paper-plugin.yml @@ -3,7 +3,6 @@ version: "${plugin_version}" author: Offz main: com.mineinabyss.mobzy.MobzyPlugin api-version: "1.20" - prefix: Mobzy description: A custom entities API