From 19a9f5c4e88e508d9e1f7e910d014e04f48882f4 Mon Sep 17 00:00:00 2001 From: Boy Date: Sat, 30 Sep 2023 21:44:19 +0200 Subject: [PATCH] Bump Idofront, Geary and ModelEngine 4 --- build.gradle.kts | 10 ++ gradle.properties | 2 +- .../features/bossbar/BossBarDisplaySystem.kt | 9 +- .../mobzy/features/copynbt/CopyNBTSystem.kt | 16 +- .../features/initializers/SetBreakDownDoor.kt | 10 +- .../features/initializers/SetBurnsInDay.kt | 10 +- .../initializers/SetCanPickupItems.kt | 11 +- .../features/initializers/SetEquipment.kt | 10 +- .../features/initializers/SetMobAttributes.kt | 12 +- .../initializers/SetProjectileItemSystem.kt | 10 +- .../initializers/SetRemoveWhenFarAway.kt | 10 +- .../features/initializers/SetSlimeSize.kt | 10 +- .../DisableMobInteractionsSystem.kt | 10 +- .../features/sounds/AmbientSoundsSystem.kt | 8 +- .../sounds/SilenceVanillaSoundsSystem.kt | 10 +- mobzy-modelengine/build.gradle.kts | 4 + .../mineinabyss/mobzy/modelengine/Helpers.kt | 26 +++ .../ModelEngineAnimationController.kt | 13 +- .../animation/ModelInteractionListener.kt | 2 +- .../intializers/SetModelEngineModel.kt | 31 +++- .../intializers/SetModelEngineModelSystem.kt | 43 +++-- .../nametag/ModelEngineNameTagListener.kt | 6 +- .../riding/ModelEngineRidingListener.kt | 50 ++---- .../mobzy/modelengine/riding/Rideable.kt | 16 +- .../pathfinding/PathfinderAttachSystem.kt | 35 +++- .../pathfinding/components/Pathfinders.kt | 1 + .../mobzy/spawning/MobzySpawning.kt | 3 - .../mobzy/spawning/SpawnDefinition.kt | 21 +-- .../mobzy/spawning/SpawnRegistry.kt | 21 +-- .../components/BlockCompositionCondition.kt | 18 +- .../components/LocalGroupConditions.kt | 20 +-- .../components/SpawnCategoryCapCondition.kt | 3 - .../components/SpawnDelayCondition.kt | 12 +- .../components/SpawnGapCondition.kt | 17 +- .../mobzy/spawning/vertical/SpawnInfo.kt | 6 - settings.gradle.kts | 4 +- .../com/mineinabyss/mobzy/MobzyCommands.kt | 164 +----------------- .../com/mineinabyss/mobzy/MobzyPlugin.kt | 8 +- 38 files changed, 287 insertions(+), 385 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index cacc58c3..0aa1fe83 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.net.URI @Suppress("DSL_SCOPE_VIOLATION") plugins { @@ -12,6 +13,8 @@ plugins { alias(libs.plugins.mia.autoversion) } +val mavenUser: String by project +val mavenPassword: String by project allprojects { apply(plugin = "java") apply(plugin = "org.jetbrains.dokka") @@ -28,6 +31,13 @@ allprojects { mavenCentral() maven("https://repo.mineinabyss.com/releases") maven("https://repo.mineinabyss.com/snapshots") + maven { + url = URI("https://${mavenUser}:${mavenPassword}@repo.mineinabyss.com/private") + credentials { + username = mavenUser + password = mavenPassword + } + } maven("https://repo.dmulloy2.net/nexus/repository/public/") //ProtocolLib maven("https://maven.enginehub.org/repo/") //WorldGuard/Edit maven("https://mvn.lumine.io/repository/maven-public/") { metadataSources { artifact() } } // Model Engine diff --git a/gradle.properties b/gradle.properties index 5056317f..34ece6fa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss version=0.21 -idofrontVersion=0.18.15 +idofrontVersion=0.18.27 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/BossBarDisplaySystem.kt index 1b08b72e..f039d9fb 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/BossBarDisplaySystem.kt @@ -1,10 +1,9 @@ package com.mineinabyss.mobzy.features.bossbar import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.geary.systems.RepeatingSystem -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointer import com.mineinabyss.idofront.entities.toPlayer import com.mineinabyss.idofront.typealiases.BukkitEntity import org.bukkit.attribute.Attribute @@ -22,10 +21,10 @@ import kotlin.time.Duration.Companion.seconds */ @AutoScan class BossBarDisplaySystem : RepeatingSystem(interval = 0.5.seconds), Listener { - private val TargetScope.bossbar by get() - private val TargetScope.bukkitentity by get() + private val Pointer.bossbar by get() + private val Pointer.bukkitentity by get() - override fun TargetScope.tick() { + 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 } 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 d40d27ff..577146fd 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.Handler +import com.mineinabyss.geary.annotations.optin.UnsafeAccessors import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.papermc.datastore.loadComponentsFrom import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.nms.aliases.toNMS import com.mineinabyss.idofront.typealiases.BukkitEntity @@ -15,13 +15,13 @@ import com.mineinabyss.idofront.typealiases.BukkitEntity */ @AutoScan class CopyNBTSystem : GearyListener() { - private val TargetScope.nbt by onSet() - private val TargetScope.bukkitEntity by onSet() + private val Pointers.nbt by get().whenSetOnTarget() + private val Pointers.bukkitEntity by get().whenSetOnTarget() - @Handler - fun TargetScope.copyNBT() { + @OptIn(UnsafeAccessors::class) + override fun Pointers.handle() { bukkitEntity.toNMS().load(nbt.compound) - entity.loadComponentsFrom(bukkitEntity.persistentDataContainer) - entity.remove() + target.entity.loadComponentsFrom(bukkitEntity.persistentDataContainer) + target.entity.remove() } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetBreakDownDoor.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetBreakDownDoor.kt index 655b73b0..2b929c5a 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetBreakDownDoor.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetBreakDownDoor.kt @@ -1,9 +1,8 @@ package com.mineinabyss.mobzy.features.initializers -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -16,11 +15,10 @@ value class SetBreakDownDoor(val value: Boolean = false) @AutoScan class SetBreakDownDoorListener : GearyListener() { - private val TargetScope.breakDoor by onSet() - private val TargetScope.bukkit by onSet() + private val Pointers.breakDoor by get().whenSetOnTarget() + private val Pointers.bukkit by get().whenSetOnTarget() - @Handler - fun TargetScope.apply() { + override fun Pointers.handle() { 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/initializers/SetBurnsInDay.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetBurnsInDay.kt index 810f6a07..7d96b12e 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetBurnsInDay.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetBurnsInDay.kt @@ -1,9 +1,8 @@ package com.mineinabyss.mobzy.features.initializers -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -18,11 +17,10 @@ value class SetBurnInDay(val value: Boolean = true) @AutoScan class SetBurnInDaySystem : GearyListener() { - private val TargetScope.burn by onSet() - private val TargetScope.bukkit by onSet() + private val Pointers.burn by get().whenSetOnTarget() + private val Pointers.bukkit by get().whenSetOnTarget() - @Handler - fun TargetScope.apply() { + override fun Pointers.handle() { when (val mob = bukkit) { is Phantom -> mob.setShouldBurnInDay(burn.value) is AbstractSkeleton -> mob.setShouldBurnInDay(burn.value) diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetCanPickupItems.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetCanPickupItems.kt index 0c071129..62a1f278 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetCanPickupItems.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetCanPickupItems.kt @@ -1,9 +1,8 @@ package com.mineinabyss.mobzy.features.initializers -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,11 +14,9 @@ class SetCanPickupItems(val value: Boolean) @AutoScan class SetCanPickupItemsSystem : GearyListener() { - private val TargetScope.pickup by onSet() - private val TargetScope.bukkit by onSet() - - @Handler - fun TargetScope.apply() { + 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 } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetEquipment.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetEquipment.kt index 13942dff..2351ad7a 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetEquipment.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetEquipment.kt @@ -1,13 +1,12 @@ package com.mineinabyss.mobzy.features.initializers import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.serialization.SerializableItemStack import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.bukkit.entity.Mob -import org.bukkit.event.EventHandler /** * A component for adding equipment to spawned mobs. @@ -22,11 +21,10 @@ data class SetEquipment( ) class SetEquipmentSystem : GearyListener() { - private val TargetScope.equipment by onSet() - private val TargetScope.bukkit by onSet() + private val Pointers.equipment by get().whenSetOnTarget() + private val Pointers.bukkit by get().whenSetOnTarget() - @EventHandler - fun TargetScope.apply() { + override fun Pointers.handle() { val mob = bukkit as? Mob ?: return mob.equipment.apply { equipment.helmet?.toItemStack()?.let { helmet = it } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetMobAttributes.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetMobAttributes.kt index b7924fa1..a72fd80c 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetMobAttributes.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetMobAttributes.kt @@ -1,9 +1,8 @@ package com.mineinabyss.mobzy.features.initializers -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.nms.aliases.NMSEntity import com.mineinabyss.idofront.nms.aliases.toNMS import com.mineinabyss.idofront.typealiases.BukkitEntity @@ -37,12 +36,11 @@ data class SetMobAttributes( @AutoScan class SetMobAttributesSystem : GearyListener() { - private val TargetScope.bukkitEntity by onSet() - private val TargetScope.attributes by onSet() + private val Pointers.bukkitEntity by get().whenSetOnTarget() + private val Pointers.attributes by get().whenSetOnTarget() - @Handler - fun TargetScope.setAttributes() { - if(attributes.width != null && attributes.height != null) { + override fun Pointers.handle() { + if (attributes.width != null && attributes.height != null) { bukkitEntity.toNMS().setDimensions(attributes.width!!, attributes.height!!) } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetProjectileItemSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetProjectileItemSystem.kt index 5b88a9f0..ff9d119b 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetProjectileItemSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetProjectileItemSystem.kt @@ -1,9 +1,8 @@ package com.mineinabyss.mobzy.features.initializers -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.serialization.SerializableItemStack import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName @@ -18,11 +17,10 @@ data class SetProjectileItem( @AutoScan class SetProjectileItemSystem : GearyListener() { - private val TargetScope.model by onSet() - private val TargetScope.bukkit by onSet() + private val Pointers.model by get().whenSetOnTarget() + private val Pointers.bukkit by get().whenSetOnTarget() - @Handler - fun TargetScope.applyModel() { + override fun Pointers.handle() { val projectile = bukkit as? ThrowableProjectile ?: return projectile.item = model.item.toItemStack() } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetRemoveWhenFarAway.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetRemoveWhenFarAway.kt index 2d4d0f8b..b6dca236 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetRemoveWhenFarAway.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetRemoveWhenFarAway.kt @@ -1,9 +1,8 @@ package com.mineinabyss.mobzy.features.initializers -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -20,11 +19,10 @@ class SetRemoveWhenFarAway(val value: Boolean) @AutoScan class SetRemoveWhenFarAwaySystem : GearyListener() { - private val TargetScope.removeWhenFarAway by onSet() - private val TargetScope.bukkit by onSet() + private val Pointers.removeWhenFarAway by get().whenSetOnTarget() + private val Pointers.bukkit by get().whenSetOnTarget() - @Handler - fun TargetScope.setRemoveWhenFarAway() { + override fun Pointers.handle() { val living = bukkit as? LivingEntity ?: return living.removeWhenFarAway = removeWhenFarAway.value } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetSlimeSize.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetSlimeSize.kt index 655ad785..4c90cb4c 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetSlimeSize.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/SetSlimeSize.kt @@ -1,9 +1,8 @@ package com.mineinabyss.mobzy.features.initializers -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.serialization.IntRangeSerializer import com.mineinabyss.idofront.typealiases.BukkitEntity import com.mineinabyss.idofront.util.randomOrMin @@ -18,11 +17,10 @@ value class SetSlimeSize(@Serializable(with = IntRangeSerializer::class) val siz @AutoScan class SetSlimeSizeSystem : GearyListener() { - private val TargetScope.slimeSize by onSet() - private val TargetScope.bukkit by onSet() + private val Pointers.slimeSize by get().whenSetOnTarget() + private val Pointers.bukkit by get().whenSetOnTarget() - @Handler - fun TargetScope.apply() { + override fun Pointers.handle() { val slime = (bukkit as? Slime) ?: return slime.size = slimeSize.size.randomOrMin() } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/nointeractions/DisableMobInteractionsSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/nointeractions/DisableMobInteractionsSystem.kt index cdb7a02b..38b3d79f 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/nointeractions/DisableMobInteractionsSystem.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/nointeractions/DisableMobInteractionsSystem.kt @@ -1,10 +1,9 @@ package com.mineinabyss.mobzy.features.nointeractions -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity import io.papermc.paper.event.entity.EntityMoveEvent import org.bukkit.event.EventHandler @@ -12,11 +11,10 @@ import org.bukkit.event.Listener @AutoScan class DisableMobInteractionsSystem : GearyListener(), Listener { - val TargetScope.bukkit by onSet() - val TargetScope.cancel by onSet() + val Pointers.bukkit by get().whenSetOnTarget() + val Pointers.cancel by get().whenSetOnTarget() - @Handler - fun TargetScope.handle() { + override fun Pointers.handle() { bukkit.isInvulnerable = true bukkit.setGravity(false) } 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 a4418ffb..daac6b93 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 @@ -2,17 +2,17 @@ package com.mineinabyss.mobzy.features.sounds import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.RepeatingSystem -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointer import com.mineinabyss.idofront.time.ticks import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlin.random.Random @AutoScan class AmbientSoundsSystem : RepeatingSystem(interval = 1.ticks) { - private val TargetScope.sounds by get() - private val TargetScope.bukkit by get() + private val Pointer.sounds by get() + private val Pointer.bukkit by get() - override fun TargetScope.tick() { + override fun Pointer.tick() { if (Random.nextDouble() < sounds.ambientChance) OverrideMobSoundsSystem.makeSound(bukkit, sounds.ambient) } 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 e5a4aa63..30efe60f 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,18 +1,16 @@ package com.mineinabyss.mobzy.features.sounds -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity @AutoScan class SilenceVanillaSoundsSystem : GearyListener() { - private val TargetScope.bukkit by onSet() - private val TargetScope.sounds by onSet() + private val Pointers.bukkit by get().whenSetOnTarget() + private val Pointers.sounds by get().whenSetOnTarget() - @Handler - fun TargetScope.removeSounds() { + override fun Pointers.handle() { bukkit.isSilent = true } } diff --git a/mobzy-modelengine/build.gradle.kts b/mobzy-modelengine/build.gradle.kts index aef58638..1c191615 100644 --- a/mobzy-modelengine/build.gradle.kts +++ b/mobzy-modelengine/build.gradle.kts @@ -13,3 +13,7 @@ dependencies { compileOnly(project(":mobzy-core")) } + +/*configurations.all { + resolutionStrategy.cacheChangingModulesFor( 0, "seconds") +}*/ diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/Helpers.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/Helpers.kt index ce53bce2..db34868d 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/Helpers.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/Helpers.kt @@ -1,7 +1,33 @@ package com.mineinabyss.mobzy.modelengine +import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.idofront.typealiases.BukkitEntity +import com.mineinabyss.mobzy.modelengine.intializers.SetModelEngineModel import com.ticxo.modelengine.api.ModelEngineAPI import com.ticxo.modelengine.api.model.ModeledEntity +import com.ticxo.modelengine.api.model.bone.behavior.BoneBehavior +import com.ticxo.modelengine.api.model.bone.manager.BehaviorManager +import com.ticxo.modelengine.api.model.bone.manager.MountManager +import com.ticxo.modelengine.api.model.bone.type.Mount +import java.util.* +import kotlin.jvm.optionals.getOrNull fun BukkitEntity.toModelEntity(): ModeledEntity? = ModelEngineAPI.getModeledEntity(uniqueId) + +class MountManagerWithBehavior( + mountManager: MountManager, + behaviorManager: BehaviorManager, +): MountManager by mountManager, BehaviorManager by behaviorManager + +fun BukkitEntity.getMountManager() : MountManagerWithBehavior<*>? { + val mountManager = (toModelEntity() + ?.getModel(toGearyOrNull()?.get()?.modelId) + ?.getOrNull() + ?.getMountManager() as Optional<*>?) + ?.getOrNull() ?: return null + + return MountManagerWithBehavior( + mountManager as MountManager, + mountManager as BehaviorManager<*> + ) +} diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelEngineAnimationController.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelEngineAnimationController.kt index dee2762b..4ef3f596 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelEngineAnimationController.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelEngineAnimationController.kt @@ -2,6 +2,8 @@ package com.mineinabyss.mobzy.modelengine.animation import com.mineinabyss.idofront.typealiases.BukkitEntity import com.mineinabyss.mobzy.modelengine.toModelEntity +import com.ticxo.modelengine.api.animation.ModelState +import com.ticxo.modelengine.api.animation.handler.AnimationHandler class ModelEngineAnimationController : AnimationController { @@ -9,17 +11,20 @@ class ModelEngineAnimationController : AnimationController { override fun playAnimation( entity: BukkitEntity, - state: String, + stateName: String, lerpIn: Double, lerpOut: Double, speed: Double, force: Boolean - ): Unit? = + ) { entity.toModelEntity()?.models?.values?.forEach { - it.animationHandler.playAnimation(state, lerpIn, lerpOut, speed, force) + val state = ModelState.get(stateName) ?: return + val defaultProperty = AnimationHandler.DefaultProperty(state, stateName, lerpIn, lerpOut, speed) + it.animationHandler.setDefaultProperty(defaultProperty) } + } override fun stopAnimation(entity: BukkitEntity, state: String, ignoreLerp: Boolean) = entity.toModelEntity()?.models?.values - ?.forEach { it.animationHandler.stopAnimation(state) } + ?.forEach { it.animationHandler.getDefaultProperty(ModelState.get(state)) } } diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelInteractionListener.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelInteractionListener.kt index c7236354..13400367 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelInteractionListener.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/animation/ModelInteractionListener.kt @@ -9,6 +9,6 @@ class ModelInteractionListener: Listener { /** Switch to the hit model of the entity, then shortly after, back to the normal one to create a hit effect. */ @EventHandler(ignoreCancelled = true) fun EntityDamageEvent.onHit() { - entity.toModelEntity()?.mountManager?.model?.hurt() + entity.toModelEntity()?.markHurt() } } diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModel.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModel.kt index f7d5575a..08660296 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModel.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/intializers/SetModelEngineModel.kt @@ -1,5 +1,8 @@ package com.mineinabyss.mobzy.modelengine.intializers +import com.mineinabyss.idofront.serialization.DoubleRangeSerializer +import com.mineinabyss.idofront.util.DoubleRange +import com.ticxo.modelengine.api.entity.CullType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -12,4 +15,30 @@ class SetModelEngineModel( val damageTint: Boolean = true, val nametag: Boolean = true, val stepHeight: Double = 0.0, -) + val scale: @Serializable(DoubleRangeSerializer::class) DoubleRange = 1.0..1.0, + val verticalCull: VerticalCull? = null, + val backCull: BackCull? = null, + val blockedCull: BlockedCull? = null, +) { + + @Serializable + data class VerticalCull( + val type: CullType, + val distance: Double, + val ignoreRadius: Double + ) + + @Serializable + data class BackCull( + val type: CullType, + val angle: Double, + val ignoreRadius: Double + ) + + @Serializable + data class BlockedCull( + val type: CullType, + val angle: Double, + val ignoreRadius: Double + ) +} 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 5ab9ecc0..fa8e8332 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,22 +1,20 @@ package com.mineinabyss.mobzy.modelengine.intializers import com.github.shynixn.mccoroutine.bukkit.launch -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope -import com.mineinabyss.idofront.textcomponents.serialize +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity +import com.mineinabyss.idofront.util.randomOrMin import com.mineinabyss.mobzy.mobzy import com.ticxo.modelengine.api.ModelEngineAPI import kotlinx.coroutines.yield import org.bukkit.Color class SetModelEngineModelSystem : GearyListener() { - val TargetScope.bukkit by onSet() - val TargetScope.model by onSet() + val Pointers.bukkit by get().whenSetOnTarget() + val Pointers.model by get().whenSetOnTarget() - @Handler - fun TargetScope.registerModelEngine() { + override fun Pointers.handle() { mobzy.plugin.launch { yield() // Wait till next tick so some entity stuff gets initialized val modelEntity = ModelEngineAPI.getOrCreateModeledEntity(bukkit) @@ -24,19 +22,36 @@ class SetModelEngineModelSystem : GearyListener() { ModelEngineAPI.getBlueprint(model.modelId) ?: error("No blueprint registered for ${model.modelId}") val createdModel = ModelEngineAPI.createActiveModel(blueprint).apply { - if (model.damageTint) rendererHandler.setColor(Color.RED) + if (model.damageTint) damageTint = Color.RED + val scale = model.scale.randomOrMin() + setScale(scale) + setHitboxScale(scale) } modelEntity.apply { addModel(createdModel, true) - bukkit.customName()?.let { - modelEntity.getModel(model.modelId).nametagHandler.bones["nametag"]?.apply { - customName = it.serialize() - isCustomNameVisible = model.nametag + 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 } } - setStepHeight(model.stepHeight) - isBaseEntityVisible = !model.invisible + } } } diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/nametag/ModelEngineNameTagListener.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/nametag/ModelEngineNameTagListener.kt index b591a985..cff6dfb6 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/nametag/ModelEngineNameTagListener.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/nametag/ModelEngineNameTagListener.kt @@ -1,8 +1,6 @@ package com.mineinabyss.mobzy.modelengine.nametag import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.idofront.textcomponents.serialize -import com.mineinabyss.mobzy.modelengine.intializers.SetModelEngineModel import com.mineinabyss.mobzy.modelengine.toModelEntity import org.bukkit.Material import org.bukkit.event.EventHandler @@ -17,11 +15,11 @@ class ModelEngineNameTagListener : Listener { val modelEntity = rightClicked.toModelEntity() ?: return if (itemInHand.type == Material.NAME_TAG) { - modelEntity.getModel(gearyEntity.get()?.modelId).nametagHandler.fakeEntity + /*modelEntity.getModel(gearyEntity.get()?.modelId).nametagHandler.fakeEntity .firstNotNullOfOrNull { it.value }?.run { customName = itemInHand.itemMeta.displayName()?.serialize() isCustomNameVisible = true - } + }*/ } } } diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/ModelEngineRidingListener.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/ModelEngineRidingListener.kt index c7552c76..69af0dc6 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/ModelEngineRidingListener.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/ModelEngineRidingListener.kt @@ -2,9 +2,8 @@ package com.mineinabyss.mobzy.modelengine.riding import com.mineinabyss.geary.helpers.with import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull +import com.mineinabyss.mobzy.modelengine.getMountManager import com.mineinabyss.mobzy.modelengine.intializers.SetModelEngineModel -import com.mineinabyss.mobzy.modelengine.toModelEntity -import com.ticxo.modelengine.api.ModelEngineAPI import io.papermc.paper.event.entity.EntityMoveEvent import org.bukkit.Material import org.bukkit.entity.LivingEntity @@ -15,31 +14,17 @@ import org.bukkit.event.Listener import org.bukkit.event.entity.EntityDamageEvent import org.bukkit.event.entity.EntityDeathEvent import org.bukkit.event.player.PlayerInteractEntityEvent -import org.bukkit.event.player.PlayerQuitEvent class ModelEngineRidingListener : Listener { + /** Ride entities with [Rideable] component on right click. */ @EventHandler fun PlayerInteractEntityEvent.rideOnRightClick() { if (player.isSneaking || player.inventory.itemInMainHand.type == Material.LEAD) return - val gearyEntity = rightClicked.toGearyOrNull() ?: return - val modelEntity = rightClicked.toModelEntity() ?: return - - gearyEntity.with { rideable: Rideable, modelengine: SetModelEngineModel -> - val mount = modelEntity.mountManager - - // If player is not riding this or another entity, mount it - if (!mount.hasRider(player) && ModelEngineAPI.getMountPair(player.uniqueId) == null) { - mount.isCanSteer = true - mount.isCanRide = true - val controller = ModelEngineAPI.getControllerRegistry().get(rideable.controllerID) - if (mount.driver == null) - mount.setDriver(player, controller) - else if (rideable.canTakePassengers && mount.passengers.size < rideable.maxPassengerCount) - mount.addPassengerToSeat(modelengine.modelId, "p_${mount.passengers.size + 1}", player, controller) - mount.setCanDamageMount(player.uniqueId, rideable.canDamageMount) - } + rightClicked.toGearyOrNull()?.with { rideable: Rideable, modelengine: SetModelEngineModel -> + val mountManager = rightClicked.getMountManager() ?: return@with + if (mountManager.driver == null) mountManager.mountDriver(player, rideable.controller) } } @@ -47,8 +32,9 @@ class ModelEngineRidingListener : Listener { @EventHandler fun EntityMoveEvent.onMountControl() { val gearyEntity = entity.toGearyOrNull() ?: return - val mount = entity.toModelEntity()?.mountManager ?: return - val player = (mount.driver ?: return) as? Player ?: return + if (!gearyEntity.has()) return + val mountManager = entity.getMountManager() ?: return + val player = (mountManager.driver ?: return) as? Player ?: return //TODO Make mob move on its own if not holding correct item gearyEntity.with { rideable: Rideable -> @@ -60,38 +46,38 @@ class ModelEngineRidingListener : Listener { /** Apply remaining damage to driver and passengers of a [Rideable] entity when it dies */ @EventHandler fun EntityDamageEvent.onMountFallDamage() { - val mount = entity.toModelEntity()?.mountManager ?: return + val mountManager = entity.getMountManager() ?: return val health = (entity as? LivingEntity)?.health ?: return if (entity.toGearyOrNull() == null) return if (cause != EntityDamageEvent.DamageCause.FALL) return if (health - finalDamage > 0) return - if (mount.driver != null && mount.driver is Player) { - val driver = mount.driver as Player + if (mountManager.driver != null && mountManager.driver is Player) { + val driver = mountManager.driver as Player driver.damage(damage - health) driver.lastDamageCause = this driver.noDamageTicks = 0 } - if (mount.hasPassengers()) mount.passengers.keys.filterIsInstance().forEach { + /*if (mountManager.hasPassengers()) mountManager.passengers.keys.filterIsInstance().forEach { it.damage(damage - health) it.lastDamageCause = this it.noDamageTicks = 0 - } + }*/ } @EventHandler(priority = EventPriority.LOW) fun EntityDeathEvent.dismountPassengers() { - val mountHandler = entity.toModelEntity()?.mountManager - if (mountHandler?.driver != null || mountHandler?.hasPassengers() == true) mountHandler.dismountAll() + val mountHandler = entity.getMountManager() ?: return + if (mountHandler.hasRiders()) mountHandler.dismountAll() } - @EventHandler(priority = EventPriority.LOWEST) + /*@EventHandler(priority = EventPriority.LOWEST) fun PlayerQuitEvent.dismountOnQuit() { - ModelEngineAPI.getMountPair(player.uniqueId)?.mountManager?.let { + ModelEngineAPI.getMountPairManager().getMountedPair(player.uniqueId)?.mountManager?.let { if (it.driver.uniqueId == player.uniqueId) it.removeDriver() else it.removePassenger(player) } - } + }*/ } diff --git a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/Rideable.kt b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/Rideable.kt index b332b107..cec6fa6e 100644 --- a/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/Rideable.kt +++ b/mobzy-modelengine/src/main/kotlin/com/mineinabyss/mobzy/modelengine/riding/Rideable.kt @@ -1,6 +1,8 @@ package com.mineinabyss.mobzy.modelengine.riding import com.mineinabyss.idofront.serialization.SerializableItemStack +import com.ticxo.modelengine.api.mount.controller.MountControllerType +import com.ticxo.modelengine.api.mount.controller.MountControllerTypes import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,9 +12,19 @@ import kotlinx.serialization.Serializable @Serializable @SerialName("mobzy:modelengine.rideable") class Rideable( - val controllerID: String = "walking", + val controllerID: String = "WALKING", val steerItem: SerializableItemStack? = null, val canTakePassengers: Boolean = false, val maxPassengerCount: Int = 1, val canDamageMount: Boolean = false -) +) { + val controller: MountControllerType + get() = + when (controllerID.uppercase()) { + "WALKING" -> MountControllerTypes.WALKING + "WALKING_FORCE" -> MountControllerTypes.WALKING_FORCE + "FLYING" -> MountControllerTypes.FLYING + "FLYING_FORCE" -> MountControllerTypes.FLYING_FORCE + else -> MountControllerTypes.WALKING + } +} 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 90f4f5fb..dbe987c7 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,33 +1,52 @@ package com.mineinabyss.mobzy.pathfinding -import com.mineinabyss.geary.annotations.Handler +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.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.idofront.nms.aliases.NMSMob import com.mineinabyss.idofront.nms.aliases.toNMS import com.mineinabyss.idofront.typealiases.BukkitEntity import com.mineinabyss.mobzy.pathfinding.components.Pathfinders +import net.minecraft.world.entity.ai.control.LookControl import org.bukkit.entity.Mob @AutoScan class PathfinderAttachSystem : GearyListener() { - private val TargetScope.bukkit by onSet() - private val TargetScope.pathfinders by onSet() + private val Pointers.bukkit by get().whenSetOnTarget() + private val Pointers.pathfinders by get().whenSetOnTarget() - @Handler - fun TargetScope.attachPathfinders() { + + private class NoLookControl(entity: NMSMob) : LookControl(entity) { + override fun tick() {} + } + + @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?.forEach { (priority, component) -> - nmsMob.addTargetSelector(priority.toInt(), component) - entity.set(component) + runCatching { + nmsMob.addTargetSelector(priority.toInt(), component) + entity.set(component) + }.onFailure { + it.printStackTrace() + } } goals?.forEach { (priority, component) -> 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 17ddc4d1..44f8abbf 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 @@ -16,5 +16,6 @@ import kotlinx.serialization.Serializable data class Pathfinders( val targets: Map? = null, val goals: Map? = null, + val noLookControl: Boolean = false, val override: Boolean = true, ) diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawning.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawning.kt index 3b37b911..9ce6ea42 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawning.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/MobzySpawning.kt @@ -29,9 +29,6 @@ interface MobzySpawning { } override fun MobzySpawning.install() = actions { - if (!Plugins.isEnabled("WorldGuard")) - error("Could not load spawning module, WorldGuard is not installed.") - geary { on(GearyPhase.ENABLE) { "Spawns" { 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 74382a19..050f63e6 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 @@ -3,15 +3,13 @@ package com.mineinabyss.mobzy.spawning -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan +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.accessors.building.map import com.mineinabyss.idofront.serialization.IntRangeSerializer import com.mineinabyss.idofront.util.randomOrMin -import com.mineinabyss.geary.papermc.tracking.entities.helpers.spawnFromPrefab import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo import com.mineinabyss.mobzy.spawning.vertical.checkDown import com.mineinabyss.mobzy.spawning.vertical.checkUp @@ -88,16 +86,15 @@ data class DoSpawn( @AutoScan class SpawnRequestListener : GearyListener() { - private val TargetScope.type by get() - private val TargetScope.amount by getOrNull().map { it?.amount } - private val TargetScope.spawnPos by getOrDefault(SpawnPosition.GROUND) - private val TargetScope.radius by getOrNull().map { it?.radius ?: 0.0 } + 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 EventScope.spawnEvent by get() + private val Pointers.spawnEvent by get().on(event) - @Handler - fun TargetScope.handleSpawn(event: EventScope) { - val location = event.spawnEvent.location + override fun Pointers.handle() { + val location = spawnEvent.location val spawns = amount?.randomOrMin() ?: 1 for (i in 0 until spawns) { val chosenLoc = @@ -107,7 +104,7 @@ class SpawnRequestListener : GearyListener() { chosenLoc.spawnFromPrefab(type.prefab) } - event.spawnEvent.spawnedAmount = spawns + spawnEvent.spawnedAmount = spawns } /** 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 933db38c..1e8db784 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,10 +1,11 @@ package com.mineinabyss.mobzy.spawning -import com.mineinabyss.geary.annotations.Handler +import com.mineinabyss.geary.annotations.optin.UnsafeAccessors import com.mineinabyss.geary.datatypes.GearyEntity import com.mineinabyss.geary.prefabs.prefabs import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.systems.accessors.Pointer +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.geary.systems.query.GearyQuery import com.sk89q.worldguard.WorldGuard import com.sk89q.worldguard.protection.regions.ProtectedRegion @@ -26,8 +27,8 @@ class SpawnRegistry { fun reloadSpawns() { unregisterSpawns() - spawnConfigsQuery.toList().forEach { - prefabLoader.reread(it.entity) + spawnConfigsQuery.matchedEntities.forEach { + prefabLoader.reread(it) } } @@ -36,18 +37,18 @@ class SpawnRegistry { flatMap { regionSpawns[it.id] ?: setOf() } inner class SpawnTracker : GearyListener() { - private val TargetScope.parentRegions by onSet() - private val TargetScope.spawn by onSet() + private val Pointers.parentRegions by get().whenSetOnTarget() + private val Pointers.spawn by get().whenSetOnTarget() - @Handler - fun TargetScope.trackSpawns() { + @OptIn(UnsafeAccessors::class) + override fun Pointers.handle() { parentRegions.keys.forEach { - regionSpawns.getOrPut(it) { mutableSetOf() } += entity + regionSpawns.getOrPut(it) { mutableSetOf() } += target.entity } } } class SpawnConfigs : GearyQuery() { - val TargetScope.config by get() + val Pointer.config by get() } } 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 771d58d4..46036922 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,10 +1,8 @@ package com.mineinabyss.mobzy.spawning.conditions.components -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.EventScope -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.events.CheckingListener +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.serialization.DoubleRangeSerializer import com.mineinabyss.idofront.util.DoubleRange import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo @@ -24,14 +22,12 @@ class BlockComposition( ) @AutoScan -class BlockCompositionCondition : GearyListener() { - private val TargetScope.blockComposition by get() +class BlockCompositionCondition : CheckingListener() { + private val Pointers.blockComposition by get().on(target) + val Pointers.spawnInfo by get().on(event) - val EventScope.spawnInfo by get() - - @Handler - fun TargetScope.check(event: EventScope): Boolean = + override fun Pointers.check(): Boolean = blockComposition.materials.all { (material, range) -> - event.spawnInfo.blockComposition.percent(material) in 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 2e7320f6..5cbf0dbd 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,11 +1,8 @@ package com.mineinabyss.mobzy.spawning.conditions.components -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.EventScope -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.events.CheckingListener +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.mobzy.spawning.SpawnType import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo import kotlinx.serialization.SerialName @@ -25,13 +22,12 @@ class LocalGroupConditions( ) @AutoScan -class CapFull : GearyListener() { - val TargetScope.conf by get() - val TargetScope.spawnType by get() +class CapFull : CheckingListener() { + val Pointers.conf by get().on(target) + val Pointers.spawnType by get().on(target) - val EventScope.spawnInfo by get() + val Pointers.spawnInfo by get().on(event) - @Handler - fun TargetScope.check(event: EventScope): Boolean = - (event.spawnInfo.localTypes[spawnType.prefab] ?: 0) < conf.max + override fun Pointers.check(): Boolean = + (spawnInfo.localTypes[spawnType.prefab] ?: 0) < conf.max } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnCategoryCapCondition.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnCategoryCapCondition.kt index c8920599..42e50550 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnCategoryCapCondition.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/conditions/components/SpawnCategoryCapCondition.kt @@ -1,11 +1,8 @@ package com.mineinabyss.mobzy.spawning.conditions.components -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan import com.mineinabyss.geary.datatypes.family.family import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.EventScope -import com.mineinabyss.geary.systems.accessors.TargetScope import com.mineinabyss.mobzy.spawning.SpawnType import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo import kotlinx.serialization.SerialName 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 debd3ced..9e9b0bfa 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,9 +1,8 @@ package com.mineinabyss.mobzy.spawning.conditions.components -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.events.CheckingListener +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.serialization.DurationSerializer import com.mineinabyss.mobzy.spawning.GlobalSpawnInfo import com.mineinabyss.mobzy.spawning.mobzySpawning @@ -19,12 +18,11 @@ class SpawnDelay( ) @AutoScan -class SpawnDelayCondition : GearyListener() { +class SpawnDelayCondition : CheckingListener() { - private val TargetScope.delay by get() + private val Pointers.delay by get().on(target) - @Handler - fun TargetScope.check(): Boolean { + override fun Pointers.check(): Boolean { val iterationMod = (delay.attemptEvery / mobzySpawning.config.spawnTaskDelay) .toInt().coerceAtLeast(1) return 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 c52793e6..ad5875db 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,10 +1,8 @@ package com.mineinabyss.mobzy.spawning.conditions.components -import com.mineinabyss.geary.annotations.Handler import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.systems.GearyListener -import com.mineinabyss.geary.systems.accessors.EventScope -import com.mineinabyss.geary.systems.accessors.TargetScope +import com.mineinabyss.geary.events.CheckingListener +import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.serialization.IntRangeSerializer import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo import kotlinx.serialization.SerialName @@ -23,12 +21,11 @@ class SpawnGap( ) @AutoScan -class SpawnGapCondition : GearyListener() { - private val TargetScope.spawnGap by get() +class SpawnGapCondition : CheckingListener() { + private val Pointers.spawnGap by get().on(target) - private val EventScope.spawnInfo by get() + private val Pointers.spawnInfo by get().on(event) - @Handler - fun TargetScope.check(event: EventScope): Boolean = - event.spawnInfo.gap in spawnGap.range + override fun Pointers.check(): Boolean = + spawnInfo.gap in spawnGap.range } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt index ffd87efc..3e7f158a 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt @@ -3,8 +3,6 @@ package com.mineinabyss.mobzy.spawning.vertical import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.prefabs.PrefabKey import com.mineinabyss.geary.prefabs.helpers.prefabs -import com.mineinabyss.geary.systems.accessors.TargetScope -import com.mineinabyss.geary.systems.query.GearyQuery import com.mineinabyss.idofront.location.down import com.mineinabyss.idofront.location.up import com.mineinabyss.idofront.typealiases.BukkitEntity @@ -34,10 +32,6 @@ class SpawnInfo( val blockComposition by lazy { SubChunkBlockComposition(this.chunkSnapshot, bottom.blockY) } - object NearbyQuery : GearyQuery() { - val TargetScope.bukkit by get() - } - private val searchRadiusSquared = searchRadius * searchRadius val localMobs: Collection by lazy { diff --git a/settings.gradle.kts b/settings.gradle.kts index 3388277d..da1913cf 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,7 +24,9 @@ dependencyResolutionManagement { } versionCatalogs { - create("libs").from("com.mineinabyss:catalog:$idofrontVersion") + create("libs") { + from("com.mineinabyss:catalog:$idofrontVersion") + } create("myLibs").from(files("gradle/myLibs.versions.toml")) } } diff --git a/src/main/kotlin/com/mineinabyss/mobzy/MobzyCommands.kt b/src/main/kotlin/com/mineinabyss/mobzy/MobzyCommands.kt index 1202f6f4..da138e5d 100644 --- a/src/main/kotlin/com/mineinabyss/mobzy/MobzyCommands.kt +++ b/src/main/kotlin/com/mineinabyss/mobzy/MobzyCommands.kt @@ -1,36 +1,11 @@ package com.mineinabyss.mobzy -import com.mineinabyss.geary.components.relations.InstanceOf -import com.mineinabyss.geary.datatypes.GearyEntity -import com.mineinabyss.geary.helpers.toGeary -import com.mineinabyss.geary.papermc.tracking.entities.components.SetEntityType -import com.mineinabyss.geary.papermc.tracking.entities.gearyMobs -import com.mineinabyss.geary.papermc.tracking.entities.toGeary -import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.idofront.commands.arguments.intArg -import com.mineinabyss.idofront.commands.arguments.optionArg -import com.mineinabyss.idofront.commands.arguments.stringArg import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor -import com.mineinabyss.idofront.commands.execution.stopCommand -import com.mineinabyss.idofront.commands.extensions.actions.PlayerAction -import com.mineinabyss.idofront.commands.extensions.actions.playerAction -import com.mineinabyss.idofront.messaging.info import com.mineinabyss.idofront.messaging.success -import com.mineinabyss.idofront.nms.aliases.toNMS -import com.mineinabyss.mobzy.features.spawning.Important -import com.mineinabyss.mobzy.features.taming.Tamed import com.mineinabyss.mobzy.spawning.mobzySpawning -import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo -import net.minecraft.world.entity.FlyingMob -import net.minecraft.world.entity.animal.AbstractFish -import net.minecraft.world.entity.animal.Animal -import org.bukkit.Bukkit import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter -import org.bukkit.entity.Entity -import org.bukkit.entity.Monster -import org.bukkit.entity.NPC class MobzyCommands : IdofrontCommandExecutor(), TabCompleter { override val commands = commands(mobzy.plugin) { @@ -44,116 +19,9 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter { //TODO proper config reload support } - commandGroup { - val query by stringArg() - val radius by intArg { default = 0 } - - fun PlayerAction.removeOrInfo(isInfo: Boolean) { - val worlds = mobzy.plugin.server.worlds - var entityCount = 0 - val entities = mutableSetOf() - val types = query.split("+") - - for (world in worlds) for (entity in world.entities) { - val nmsEntity = entity.toNMS() - val geary = entity.toGeary() - if (!geary.has()) continue - - - if (types.any { type -> - fun excludeDefault() = - !geary.has() && entity.customName() == null && !geary.has() - when (type) { - "custom" -> excludeDefault() - "passive" -> nmsEntity is Animal && excludeDefault() - "hostile" -> nmsEntity is Monster && excludeDefault() - "renamed" -> entity.customName() != null && nmsEntity !is NPC - "tamed" -> geary.has() - "important" -> geary.has() && entity.customName() == null - "flying" -> nmsEntity is FlyingMob && excludeDefault() - "fish" -> nmsEntity is AbstractFish && excludeDefault() - else -> { - val prefab = runCatching { PrefabKey.of(type).toEntityOrNull() }.getOrNull() - ?: this@commandGroup.stopCommand("No such prefab or selector $type") - geary.deepInstanceOf(prefab) - } - } - }) { - val playerLoc = player.location - if (radius <= 0 || entity.world == playerLoc.world && entity.location.distance(playerLoc) < radius) { - entityCount++ - if (isInfo) entities += entity - else entity.remove() - } - } - } - - sender.success( - """ - ${if (isInfo) "There are" else "Removed"} - $entityCount entities matching your query - ${if (radius <= 0) "in all loaded chunks." else "in a radius of $radius blocks."} - """.trimIndent().replace("\n", " ") - ) - if (isInfo) { - val categories = SpawnInfo.categorizeByType(entities).entries.sortedByDescending { it.value } - if (categories.isNotEmpty()) sender.info( - categories.joinToString("\n") { (type, amount) -> "${type}: $amount" } - ) - } - } - - ("remove" / "rm")(desc = "Removes mobs")?.playerAction { - removeOrInfo(false) - } - - ("info" / "i")(desc = "Lists how many mobs are around you")?.playerAction { - removeOrInfo(true) - } - } - "debug" { createDebugCommands() } - - "locate" { - val mobKey by optionArg(options = gearyMobs.prefabs.run { map { it.key.toString() } }) { - parseErrorMessage = { "No such entity: $passed" } - } - val radius by intArg { - name = "radius to check" - default = 0 - } - playerAction { - val key = PrefabKey.of(mobKey) - if (radius <= 0) { - Bukkit.getWorlds().forEach { world -> - world.entities.filter { it.toGeary().deepInstanceOf(key.toEntity()) }.forEach { entity -> - val loc = entity.location - player.info("Found ${key.key} at ${entity.location}>${entity.location} in ${entity.world.name}") - } - } - } else { - player.location.getNearbyEntities(radius.toDouble(), radius.toDouble(), radius.toDouble()) - .filter { it.toGeary().deepInstanceOf(key.toEntity()) }.forEach { entity -> - val loc = entity.location - player.info("Found ${key.key} at ${entity.location}") - - } - } - } - } - - ("list" / "l")(desc = "Lists all custom mob types")?.action { - sender.success("All registered types:\n${gearyMobs.prefabs.getKeys()}") - } - } - } - - private val mobs: List by lazy { - buildList { - addAll(listOf("custom", "important", "mob", "renamed", "passive", "hostile", "flying")) - addAll(gearyMobs.prefabs.getKeys().map { it.toString() }) } } @@ -167,39 +35,11 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter { return when { command.name != "mobzy" -> emptyList() args.size <= 1 -> listOf( - "info", - "remove", "reload", - "fullreload", - "i", - "rm", - "s", - "stats" + "debug" ).filter { it.startsWith(args[0]) } - else -> { - val subCommand = args[0] - - when (subCommand) { - "remove", "rm", "info", "i" -> if (args.size == 2) { - val query = args[1].lowercase() - val parts = query.split("+") - val withoutLast = query.substringBeforeLast("+", missingDelimiterValue = "").let { - if (parts.size > 1) "$it+" else it - } - return mobs.asSequence().filter { - it !in parts && (it.startsWith(parts.last()) || - it.substringAfter(":").startsWith(parts.last())) - }.take(20).map { "$withoutLast$it" }.toList() - } - } - return emptyList() - } + else -> emptyList() } } } - -fun GearyEntity.deepInstanceOf(entity: GearyEntity): Boolean = - instanceOf(entity) || getRelations().any { - it.target.toGeary().deepInstanceOf(entity) - } diff --git a/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt b/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt index 571e66ea..3f3321ab 100644 --- a/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt @@ -27,7 +27,7 @@ import org.bukkit.plugin.java.JavaPlugin class MobzyPlugin : JavaPlugin() { override fun onLoad() { Platforms.load(this, "mineinabyss") - if(Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { val flags = WorldGuardSpawnFlags() DI.add(flags) flags.registerFlags() @@ -49,7 +49,11 @@ class MobzyPlugin : JavaPlugin() { MobzyCommands() geary { - if (mobzy.config.doMobSpawns) install(MobzySpawning) + if (mobzy.config.doMobSpawns) { + if (!Plugins.isEnabled("WorldGuard")) + logger.warning("Could not load spawning module, WorldGuard is not installed.") + else install(MobzySpawning) + } autoscan(classLoader, "com.mineinabyss.mobzy") { all()