Skip to content

Commit

Permalink
fix: fix onMobHurt crash again
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Aug 5, 2024
1 parent 0833b7e commit 7bd706e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/legacy/api/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void EnableEventListener(int eventId) {
case EVENT_TYPES::onMobHurt:
bus.emplaceListener<ActorHurtEvent>([](ActorHurtEvent& ev) {
IF_LISTENED(EVENT_TYPES::onMobHurt) {
if (ev.self().isType(ActorType::Mob)) {
if (ev.self().hasType(ActorType::Mob)) {
Actor* damageSource;
if (ev.source().isEntitySource()) {
if (ev.source().isChildEntitySource()) {
Expand Down
43 changes: 22 additions & 21 deletions src/lse/events/EventHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "legacy/api/ItemAPI.h"
#include "legacy/api/PlayerAPI.h"
#include "ll/api/service/Bedrock.h"
#include "mc/entity/utilities/ActorDamageCause.h"
#include "mc/server/ServerPlayer.h"
#include "mc/server/commands/CommandOrigin.h"
#include "mc/server/commands/CommandOriginType.h"
Expand Down Expand Up @@ -1152,34 +1153,34 @@ LL_TYPE_INSTANCE_HOOK(
MobHurtEffectHook,
HookPriority::Normal,
Mob,
"?hurtEffects@Mob@@UEAAXAEBVActorDamageSource@@M_N1@Z",
bool,
&Mob::getDamageAfterResistanceEffect,
float,
ActorDamageSource const& source,
float damage,
bool knock,
bool ignite
float damage
) {
IF_LISTENED(EVENT_TYPES::onMobHurt) {
Actor* damageSource;
if (source.isEntitySource()) {
if (source.isChildEntitySource()) {
damageSource = ll::service::getLevel()->fetchEntity(source.getEntityUniqueID());
} else {
damageSource = ll::service::getLevel()->fetchEntity(source.getDamagingEntityUniqueID());
if (source.getCause() == ActorDamageCause::Magic || source.getCause() == ActorDamageCause::Wither) {
Actor* damageSource;
if (source.isEntitySource()) {
if (source.isChildEntitySource()) {
damageSource = ll::service::getLevel()->fetchEntity(source.getEntityUniqueID());
} else {
damageSource = ll::service::getLevel()->fetchEntity(source.getDamagingEntityUniqueID());
}
}
}

CallEventRtnValue(
EVENT_TYPES::onMobHurt,
false,
EntityClass::newEntity(this),
damageSource ? EntityClass::newEntity(damageSource) : Local<Value>(),
Number::newNumber(damage),
Number::newNumber((int)source.getCause())
);
CallEventRtnValue(
EVENT_TYPES::onMobHurt,
0.0f,
EntityClass::newEntity(this),
damageSource ? EntityClass::newEntity(damageSource) : Local<Value>(),
Number::newNumber(damage < 0.0f ? -damage : damage),
Number::newNumber((int)source.getCause())
);
}
}
IF_LISTENED_END(EVENT_TYPES::onMobHurt)
return origin(source, damage, knock, ignite);
return origin(source, damage);
}

void PlayerStartDestroyBlock() { PlayerStartDestroyHook::hook(); }
Expand Down

0 comments on commit 7bd706e

Please sign in to comment.