From edaf094359f76263c5e23d904e5b77955d05ae01 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sat, 14 Dec 2024 00:03:23 -0500 Subject: [PATCH] fix: Apply looting calculation to drops --- .../mythicmobs/MythicEmbeddedGearyEntity.kt | 1 + .../mythicmobs/items/MythicMobDropListener.kt | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/MythicEmbeddedGearyEntity.kt b/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/MythicEmbeddedGearyEntity.kt index e216935..17c116f 100644 --- a/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/MythicEmbeddedGearyEntity.kt +++ b/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/MythicEmbeddedGearyEntity.kt @@ -51,6 +51,7 @@ object MythicEmbeddedGearyEntity { set(it, it::class) } observeComponent?.let { set(it, it::class) } + set(prefabKey) } prefabs.manager.registerPrefab(prefabKey, prefabEntity) prefabEntity diff --git a/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/items/MythicMobDropListener.kt b/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/items/MythicMobDropListener.kt index c42b4eb..3905ae0 100644 --- a/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/items/MythicMobDropListener.kt +++ b/geary-papermc-mythicmobs/src/main/kotlin/com/mineinabyss/geary/papermc/mythicmobs/items/MythicMobDropListener.kt @@ -9,10 +9,13 @@ import com.mineinabyss.geary.prefabs.entityOfOrNull import io.lumine.mythic.api.adapters.AbstractItemStack import io.lumine.mythic.api.config.MythicLineConfig import io.lumine.mythic.api.drops.DropMetadata +import io.lumine.mythic.bukkit.BukkitAdapter import io.lumine.mythic.bukkit.adapters.item.ItemComponentBukkitItemStack import io.lumine.mythic.bukkit.events.MythicDropLoadEvent import io.lumine.mythic.bukkit.utils.numbers.RandomDouble import io.lumine.mythic.core.drops.droppables.VanillaItemDrop +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener import kotlin.jvm.optionals.getOrNull @@ -22,9 +25,10 @@ class MythicMobDropListener : Listener { @EventHandler fun MythicDropLoadEvent.onMythicDropLoad() { if (dropName.lowercase() != "geary") return - val lines = container.line.split(" ") + val lines = container.line.lowercase().split(" ") val prefabKey = PrefabKey.of(lines[1]) val amount = lines.getOrNull(2)?.takeIf { "-" in it } ?: "1-1" + val noLooting = "nolooting" in lines val world = gearyPaper.worldManager.global val itemStack = world.getAddon(ItemTracking).createItem(prefabKey) ?: return @@ -32,6 +36,7 @@ class MythicMobDropListener : Listener { GearyDrop( world, prefabKey, + noLooting, container.line, config, ItemComponentBukkitItemStack(itemStack), @@ -44,13 +49,18 @@ class MythicMobDropListener : Listener { class GearyDrop( world: Geary, val prefab: PrefabKey, - line: String, config: MythicLineConfig, item: AbstractItemStack, amount: RandomDouble, -) : VanillaItemDrop(line, config, item, amount) { - // val item = gearyItems.createItem(prefab) + val noLooting: Boolean, + line: String, config: MythicLineConfig, item: AbstractItemStack, + val randomAmount: RandomDouble, +) : VanillaItemDrop(line, config, item, randomAmount) { val cookedItem = world.entityOfOrNull(prefab)?.get()?.replaceWith?.toItemStack() - val cookedDrop = cookedItem?.let { VanillaItemDrop(line, config, ItemComponentBukkitItemStack(it), amount) } + val cookedDrop = cookedItem?.let { VanillaItemDrop(line, config, ItemComponentBukkitItemStack(it), randomAmount) } + override fun getDrop(metadata: DropMetadata?, amount: Double): AbstractItemStack { val isOnFire = (metadata?.dropper?.getOrNull()?.entity?.bukkitEntity?.fireTicks ?: 0) > 0 + val itemInKillerHand = (BukkitAdapter.adapt(metadata?.cause?.getOrNull()) as? Player)?.inventory?.itemInMainHand + val lootingLvl = if (noLooting) 0 else itemInKillerHand?.enchantments?.get(Enchantment.LOOTING) ?: 0 + val amount = (0..(randomAmount.max.toInt() + lootingLvl)).random().toDouble() return if (isOnFire && cookedDrop != null) cookedDrop.getDrop(metadata, amount) else super.getDrop(metadata, amount) }