Skip to content

Commit

Permalink
fix: Apply looting calculation to drops
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Dec 14, 2024
1 parent 1ea2ea7 commit edaf094
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ object MythicEmbeddedGearyEntity {
set(it, it::class)
}
observeComponent?.let { set(it, it::class) }
set(prefabKey)
}
prefabs.manager.registerPrefab(prefabKey, prefabEntity)
prefabEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,16 +25,18 @@ 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

register(
GearyDrop(
world,
prefabKey,
noLooting,
container.line,
config,
ItemComponentBukkitItemStack(itemStack),
Expand All @@ -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<ReplaceBurnedDrop>()?.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)
}
Expand Down

0 comments on commit edaf094

Please sign in to comment.