@@ -203,16 +203,54 @@ LL_TYPE_INSTANCE_HOOK(
203
203
origin (region, pos, projectile);
204
204
}
205
205
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
+
206
242
LL_TYPE_INSTANCE_HOOK (
207
243
MobHurtEffectHook,
208
244
HookPriority::Normal,
209
245
Mob,
210
246
&Mob::getDamageAfterResistanceEffect,
211
247
float ,
212
- ActorDamageSource const & source,
213
- float damage
248
+ :: ActorDamageSource const & source,
249
+ float damage
214
250
) {
215
251
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.
216
254
if (source.getCause () == ActorDamageCause::Magic || source.getCause () == ActorDamageCause::Wither) {
217
255
Actor* damageSource = nullptr ;
218
256
if (source.isEntitySource ()) {
@@ -381,7 +419,10 @@ void ActorRideEvent() { ActorRideHook::hook(); }
381
419
void WitherDestroyEvent () { WitherDestroyHook::hook (); }
382
420
void ProjectileHitEntityEvent () { ProjectileHitEntityHook::hook (); }
383
421
void ProjectileHitBlockEvent () { ProjectileHitBlockHook::hook (); }
384
- void MobHurtEvent () { MobHurtEffectHook::hook (); }
422
+ void MobHurtEvent () {
423
+ MobHurtHook::hook ();
424
+ MobHurtEffectHook::hook ();
425
+ }
385
426
void NpcCommandEvent () { NpcCommandHook::hook (); }
386
427
void EffectApplyEvent () { EffectApplyHook::hook (); }
387
428
void EffectExpiredEvent () { EffectExpiredHook::hook (); }
0 commit comments