diff --git a/gradle.properties b/gradle.properties index ce86905fb..d678eb7c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ group=com.mineinabyss version=0.18 useNMS=true -idofrontVersion=0.12.104 +idofrontVersion=0.12.106 kotlinVersion=1.6.10 serverVersion=1.19.2-R0.1-SNAPSHOT # Workaround for dokka builds failing on CI, see https://github.com/Kotlin/dokka/issues/1405 diff --git a/mobzy-systems/src/main/kotlin/com/mineinabyss/mobzy/systems/listeners/RidableListener.kt b/mobzy-systems/src/main/kotlin/com/mineinabyss/mobzy/systems/listeners/RidableListener.kt index 77a01809c..ab39d57f6 100644 --- a/mobzy-systems/src/main/kotlin/com/mineinabyss/mobzy/systems/listeners/RidableListener.kt +++ b/mobzy-systems/src/main/kotlin/com/mineinabyss/mobzy/systems/listeners/RidableListener.kt @@ -6,9 +6,11 @@ import com.mineinabyss.mobzy.ecs.components.interaction.Rideable import com.mineinabyss.mobzy.systems.systems.ModelEngineSystem.toModelEntity import io.papermc.paper.event.entity.EntityMoveEvent import org.bukkit.Material +import org.bukkit.entity.LivingEntity import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent import org.bukkit.event.player.PlayerInteractEntityEvent object RidableListener : Listener { @@ -53,4 +55,27 @@ object RidableListener : Listener { isCancelled = true } } + + /** Apply remaining damage to driver and passengers of a [Rideable] entity when it dies */ + @EventHandler + fun EntityDamageEvent.onMountFallDamage() { + val mount = entity.toModelEntity()?.mountHandler ?: return + val health = (entity as LivingEntity).health + + if (entity.toGearyOrNull() == null) return + if (cause != EntityDamageEvent.DamageCause.FALL) return + if (health - finalDamage > 0) return + + if (mount.hasDriver() && mount.driver is Player) { + val driver = mount.driver as Player + driver.damage(damage - health) + driver.lastDamageCause = this + driver.noDamageTicks = 0 + } + mount.passengers["mount"]?.passengers?.filterIsInstance()?.forEach { + it.damage(damage - health) + it.lastDamageCause = this + it.noDamageTicks = 0 + } + } }