Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
chore: Move MythicMobs features to this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Apr 7, 2024
1 parent 1a99e0c commit 6e8aa12
Show file tree
Hide file tree
Showing 25 changed files with 233 additions and 17 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
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)
Expand Down Expand Up @@ -59,7 +58,7 @@ dependencies {
api(project(":mobzy-features"))
api(project(":mobzy-spawning"))
api(project(":mobzy-core"))
api(project(":mobzy-modelengine"))
api(project(":mobzy-plugin-integrations"))

// Testing
testImplementation(idofrontLibs.kotlin.statistics)
Expand Down
2 changes: 1 addition & 1 deletion mobzy-pathfinding/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dependencies {
compileOnly(idofrontLibs.kotlinx.serialization.json)

compileOnly(project(":mobzy-core"))
compileOnly(project(":mobzy-modelengine"))
compileOnly(project(":mobzy-plugin-integrations"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ plugins {
id(idofrontLibs.plugins.mia.papermc.get().pluginId)
id(idofrontLibs.plugins.mia.publication.get().pluginId)
id(idofrontLibs.plugins.kotlinx.serialization.get().pluginId)
id(idofrontLibs.plugins.mia.nms.get().pluginId)
}

dependencies {
compileOnly(idofrontLibs.kotlinx.serialization.json)
// Plugins
compileOnly(idofrontLibs.minecraft.plugin.mythic.dist)
compileOnly(idofrontLibs.minecraft.plugin.modelengine)

// Other deps
compileOnly(idofrontLibs.kotlinx.serialization.json)
compileOnly(idofrontLibs.minecraft.mccoroutine)

compileOnly(project(":mobzy-core"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mineinabyss.mobzy.modelengine.animation

import com.mineinabyss.idofront.plugin.Services
import com.mineinabyss.idofront.typealiases.BukkitEntity
import com.mineinabyss.mobzy.modelengine.mobzyModelEngine

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.entity.CreatureSpawnEvent
import org.bukkit.event.entity.EntitySpawnEvent
import org.bukkit.event.world.EntitiesLoadEvent

class ModelEngineWorldListener : Listener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mineinabyss.mobzy.mythicmobs

import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.plugin.listeners
import com.mineinabyss.mobzy.mobzy
import com.mineinabyss.mobzy.mythicmobs.actions.runMMSkillAction
import com.mineinabyss.mobzy.mythicmobs.items.MythicMobDropListener
import com.mineinabyss.mobzy.mythicmobs.spawning.mythicMobSpawner
import com.mineinabyss.mobzy.mythicmobs.spawning.setBoundingBoxFromMythicMob

val mobzyMythicMobs: MythicMobsSupport? by DI.observe()

interface MythicMobsSupport {

companion object : GearyAddonWithDefault<MythicMobsSupport> {
override fun default() = object : MythicMobsSupport {
}

override fun MythicMobsSupport.install(): Unit = geary.run {
mobzy.plugin.listeners(
// ConvertToMythicMobListener(), TODO fix and bring back
MythicMobDropListener(),
)
setBoundingBoxFromMythicMob()
runMMSkillAction()
mythicMobSpawner()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.mineinabyss.mobzy.mythicmobs.actions

import com.google.common.collect.Lists
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.serialization.serializers.InnerSerializer
import com.mineinabyss.geary.systems.builders.listener
import com.mineinabyss.geary.systems.query.ListenerQuery
import com.mineinabyss.idofront.typealiases.BukkitEntity
import io.lumine.mythic.api.adapters.AbstractEntity
import io.lumine.mythic.bukkit.BukkitAdapter
import io.lumine.mythic.bukkit.MythicBukkit
import io.lumine.mythic.core.skills.SkillMetadataImpl
import io.lumine.mythic.core.skills.SkillTriggers
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import kotlin.jvm.optionals.getOrNull

@Serializable(with = RunMythicMobsSkills.Serializer::class)
class RunMythicMobsSkills(
val keys: List<String>,
) {
class Serializer : InnerSerializer<List<String>, RunMythicMobsSkills>(
serialName = "geary:run_mythic_skills",
inner = ListSerializer(String.serializer()),
inverseTransform = { it.keys },
transform = ::RunMythicMobsSkills
)
}

fun GearyModule.runMMSkillAction() = listener(
object : ListenerQuery() {
val bukkit by get<BukkitEntity>()
val skill by source.get<RunMythicMobsSkills>()
}
).exec {
skill.keys.forEach {
val line = "[ - $it ]"
val entity = BukkitAdapter.adapt(bukkit)
val caster = MythicBukkit.inst().skillManager.getCaster(entity)
val skill = MythicBukkit.inst().skillManager.getSkill(line).getOrNull()
val meta = SkillMetadataImpl(
SkillTriggers.API,
caster,
entity,
entity.location,
Lists.newArrayList(*arrayOf<AbstractEntity>(entity)),
null,
1.0f
)
skill?.execute(meta)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mineinabyss.mobzy.mythicmobs.items

import com.mineinabyss.geary.papermc.tracking.items.gearyItems
import com.mineinabyss.geary.papermc.tracking.items.helpers.GearyItemPrefabQuery.Companion.getKeys
import com.mineinabyss.geary.prefabs.PrefabKey
import io.lumine.mythic.bukkit.adapters.BukkitItemStack
import io.lumine.mythic.bukkit.events.MythicDropLoadEvent
import io.lumine.mythic.core.drops.droppables.VanillaItemDrop
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener


class MythicMobDropListener : Listener {
@EventHandler
fun MythicDropLoadEvent.onMythicDropLoad() {
if (dropName.lowercase() != "geary") return
val prefabKey = PrefabKey.of(container.line.split(" ")[1])
if (prefabKey !in gearyItems.prefabs.getKeys()) return

register(VanillaItemDrop(container.line, config, BukkitItemStack(gearyItems.createItem(prefabKey))))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mineinabyss.mobzy.mythicmobs.spawning

import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.papermc.tracking.entities.components.AttemptSpawn
import com.mineinabyss.geary.systems.builders.listener
import com.mineinabyss.geary.systems.query.ListenerQuery
import com.mineinabyss.idofront.typealiases.BukkitEntity
import io.lumine.mythic.api.mobs.entities.SpawnReason
import io.lumine.mythic.bukkit.BukkitAdapter
import io.lumine.mythic.bukkit.MythicBukkit
import kotlin.jvm.optionals.getOrNull

fun GearyModule.mythicMobSpawner() = listener(
object : ListenerQuery() {
val mobType by get<SetMythicMob>()
val attemptSpawn by event.get<AttemptSpawn>()
override fun ensure() = this { not { has<BukkitEntity>() } }
}
).exec {
val mythicMob = MythicBukkit.inst().mobManager.getMythicMob(mobType.id).getOrNull() ?: return@exec
mythicMob.spawn(BukkitAdapter.adapt(attemptSpawn.location), 1.0, SpawnReason.NATURAL) { mob ->
entity.set(mob)
entity.set(mythicMob)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mineinabyss.mobzy.mythicmobs.spawning

import com.mineinabyss.geary.papermc.MobTypeConversion
import com.mineinabyss.geary.papermc.gearyPaper
import com.mineinabyss.geary.papermc.tracking.entities.events.GearyEntityAddToWorldEvent
import com.mineinabyss.geary.papermc.tracking.entities.systems.updatemobtype.UpdateMob
import io.lumine.mythic.api.mobs.MythicMob
import io.lumine.mythic.bukkit.MythicBukkit
import io.lumine.mythic.core.constants.MobKeys
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener

class ConvertToMythicMobListener : Listener {
@EventHandler
fun GearyEntityAddToWorldEvent.onAdd() {
if (gearyPaper.config.mobTypeConversion == MobTypeConversion.IGNORE) return
val mm = MythicBukkit.inst()
if (mm.mobManager == null) return

// If MM already encoded or loaded, we let it handle things itself
if (entity.persistentDataContainer.has(MobKeys.TYPE)) return
if (mm.mobManager.isActiveMob(entity.uniqueId)) return

if (!gearyEntity.has<SetMythicMob>()) return
if (gearyEntity.has<MythicMob>()) return

when (gearyPaper.config.mobTypeConversion) {
MobTypeConversion.MIGRATE -> {
UpdateMob.scheduleRecreation(entity, gearyEntity)
}

MobTypeConversion.REMOVE -> {
UpdateMob.scheduleRemove(entity)
}

MobTypeConversion.IGNORE -> Unit
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mineinabyss.mobzy.mythicmobs.spawning

import com.mineinabyss.geary.components.relations.NoInherit
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.NMSEntityType
import io.lumine.mythic.bukkit.MythicBukkit
import org.bukkit.NamespacedKey
import org.bukkit.util.BoundingBox
import kotlin.jvm.optionals.getOrNull

fun GearyModule.setBoundingBoxFromMythicMob() = listener(
object : ListenerQuery() {
val mobType by get<com.mineinabyss.mobzy.mythicmobs.spawning.SetMythicMob>()
override fun ensure() = event.anySet(::mobType)
}
).exec {
val mythicMob = MythicBukkit.inst().mobManager.getMythicMob(mobType.id).getOrNull() ?: return@exec

// val megModel = mythicMob.model.config.getString("Id")
val vanillaType = NamespacedKey.minecraft(mythicMob.entityType.name.lowercase())

val nmsType = NMSEntityType.byString(vanillaType.toString())
.orElseGet { error("An entity type with key $vanillaType was not found.") }

entity.addRelation<NoInherit, BoundingBox>()
// entity.set(BoundingBoxHelpers.getForEntityType(nmsType))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mineinabyss.mobzy.mythicmobs.spawning

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@JvmInline
@Serializable
@SerialName("mobzy:set.mythic_mob")
value class SetMythicMob(val id: String)
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencyResolutionManagement {
include(
"mobzy-core",
"mobzy-features",
"mobzy-modelengine",
"mobzy-plugin-integrations",
"mobzy-pathfinding",
"mobzy-spawning",
)
21 changes: 12 additions & 9 deletions src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.mineinabyss.mobzy.features.prevent.riding.PreventRidingSystem
import com.mineinabyss.mobzy.features.sounds.OverrideMobSoundsBukkitListener
import com.mineinabyss.mobzy.features.taming.TamingBukkitListener
import com.mineinabyss.mobzy.modelengine.ModelEngineSupport
import com.mineinabyss.mobzy.mythicmobs.MythicMobsSupport
import com.mineinabyss.mobzy.pathfinding.components.PathfinderComponent
import com.mineinabyss.mobzy.spawning.MobzySpawnFeature
import com.mineinabyss.mobzy.spawning.WorldGuardSpawnFlags
Expand All @@ -46,14 +47,10 @@ class MobzyPlugin : JavaPlugin() {
all()
subClassesOf<PathfinderComponent>()
}

if (Plugins.isEnabled("ModelEngine")) {
install(ModelEngineSupport)
}
}
}

override fun onEnable() = actions {
override fun onEnable() = actions(mobzy.logger) {
MobzyFeatureManager(this@MobzyPlugin).enable()
MobzyCommands()

Expand All @@ -68,14 +65,20 @@ class MobzyPlugin : JavaPlugin() {
OverrideMobSoundsBukkitListener(),
)

geary.apply {
removeWhenFarAway()
}

geary {
if (Plugins.isEnabled("ModelEngine")) {
mobzy.logger.s("ModelEngine detected, enabling support.")
install(ModelEngineSupport)
}

if (Plugins.isEnabled("MythicMobs")) {
mobzy.logger.s("MythicMobs detected, enabling support.")
install(MythicMobsSupport)
}

module.apply {
removeWhenFarAway()
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ dependencies:
required: true
load: BEFORE
join-classpath: true
MythicMobs:
required: false
load: BEFORE
join-classpath: true
ModelEngine:
required: false
load: BEFORE
Expand Down

0 comments on commit 6e8aa12

Please sign in to comment.