@@ -203,16 +203,54 @@ LL_TYPE_INSTANCE_HOOK(
203203 origin (region, pos, projectile);
204204}
205205
206+ LL_TYPE_INSTANCE_HOOK (
207+ MobHurtHook,
208+ HookPriority::Normal,
209+ Mob,
210+ &Mob::$_hurt,
211+ bool ,
212+ ::ActorDamageSource const & source,
213+ float damage,
214+ bool knock,
215+ bool ignite
216+ ) {
217+ IF_LISTENED (EVENT_TYPES::onMobHurt) {
218+ // LeviLamina's ActorHurtEvent can't handle fire hurt, so we just hook Mob::$_hurt.
219+ Actor* damageSource = nullptr ;
220+ if (source.isEntitySource ()) {
221+ if (source.isChildEntitySource ()) {
222+ damageSource = ll::service::getLevel ()->fetchEntity (source.getEntityUniqueID (), false );
223+ } else {
224+ damageSource = ll::service::getLevel ()->fetchEntity (source.getDamagingEntityUniqueID (), false );
225+ }
226+ }
227+
228+ if (!CallEvent (
229+ EVENT_TYPES::onMobHurt,
230+ EntityClass::newEntity (this ),
231+ damageSource ? EntityClass::newEntity (damageSource) : Local<Value>(),
232+ Number::newNumber (damage < 0 .0f ? -damage : damage),
233+ Number::newNumber ((int )source.getCause ())
234+ )) {
235+ return false ;
236+ }
237+ }
238+ IF_LISTENED_END (EVENT_TYPES::onMobHurt)
239+ return origin (source, damage, knock, ignite);
240+ }
241+
206242LL_TYPE_INSTANCE_HOOK (
207243 MobHurtEffectHook,
208244 HookPriority::Normal,
209245 Mob,
210246 &Mob::getDamageAfterResistanceEffect,
211247 float ,
212- ActorDamageSource const & source,
213- float damage
248+ :: ActorDamageSource const & source,
249+ float damage
214250) {
215251 IF_LISTENED (EVENT_TYPES::onMobHurt) {
252+ // Mob is still hurt after hook Mob::$hurtEffects, and all hurt events are handled by this function, but we just
253+ // need magic damage.
216254 if (source.getCause () == ActorDamageCause::Magic || source.getCause () == ActorDamageCause::Wither) {
217255 Actor* damageSource = nullptr ;
218256 if (source.isEntitySource ()) {
@@ -381,7 +419,10 @@ void ActorRideEvent() { ActorRideHook::hook(); }
381419void WitherDestroyEvent () { WitherDestroyHook::hook (); }
382420void ProjectileHitEntityEvent () { ProjectileHitEntityHook::hook (); }
383421void ProjectileHitBlockEvent () { ProjectileHitBlockHook::hook (); }
384- void MobHurtEvent () { MobHurtEffectHook::hook (); }
422+ void MobHurtEvent () {
423+ MobHurtHook::hook ();
424+ MobHurtEffectHook::hook ();
425+ }
385426void NpcCommandEvent () { NpcCommandHook::hook (); }
386427void EffectApplyEvent () { EffectApplyHook::hook (); }
387428void EffectExpiredEvent () { EffectExpiredHook::hook (); }
0 commit comments