Skip to content

Commit 03cd4b2

Browse files
committed
fix: fix onMobHurt exception #157
1 parent 79b4dce commit 03cd4b2

File tree

9 files changed

+43
-46
lines changed

9 files changed

+43
-46
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.8.6] - 2024-08-03
9+
10+
### Fixed
11+
12+
- Fix onMobHurt exception [#157]
13+
814
## [0.8.5] - 2024-07-29
915

1016
### Changed
@@ -475,7 +481,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
475481
[#152]: https://github.com/LiteLDev/LegacyScriptEngine/issues/152
476482
[#153]: https://github.com/LiteLDev/LegacyScriptEngine/issues/153
477483
[#154]: https://github.com/LiteLDev/LegacyScriptEngine/issues/154
484+
[#157]: https://github.com/LiteLDev/LegacyScriptEngine/issues/157
478485

486+
[0.8.6]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.5...v0.8.6
479487
[0.8.5]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.4...v0.8.5
480488
[0.8.4]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.3...v0.8.4
481489
[0.8.3]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.2...v0.8.3

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "native",
55
"description": "A plugin engine for running LLSE plugins on LeviLamina",
66
"author": "LiteLDev",
7-
"version": "0.8.5",
7+
"version": "0.8.6",
88
"dependencies": [
99
{
1010
"name": "LegacyMoney"

src/legacy/api/EventAPI.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "ll/api/service/Bedrock.h"
4848
#include "ll/api/utils/StringUtils.h"
4949
#include "main/Global.h"
50+
#include "mc/entity/utilities/ActorType.h"
5051
#include "mc/server/commands/CommandOriginType.h"
5152
#include "mc/world/actor/player/Player.h"
5253
#include "mc/world/item/Item.h"
@@ -528,6 +529,31 @@ void EnableEventListener(int eventId) {
528529
break;
529530

530531
case EVENT_TYPES::onMobHurt:
532+
bus.emplaceListener<ActorHurtEvent>([](ActorHurtEvent& ev) {
533+
IF_LISTENED(EVENT_TYPES::onMobHurt) {
534+
if (ev.self().isType(ActorType::Mob)) {
535+
Actor* damageSource;
536+
if (ev.source().isEntitySource()) {
537+
if (ev.source().isChildEntitySource()) {
538+
damageSource = ll::service::getLevel()->fetchEntity(ev.source().getEntityUniqueID());
539+
} else {
540+
damageSource =
541+
ll::service::getLevel()->fetchEntity(ev.source().getDamagingEntityUniqueID());
542+
}
543+
}
544+
545+
CallEventRtnValue(
546+
EVENT_TYPES::onMobHurt,
547+
false,
548+
EntityClass::newEntity(&ev.self()),
549+
damageSource ? EntityClass::newEntity(damageSource) : Local<Value>(),
550+
Number::newNumber(ev.damage()),
551+
Number::newNumber((int)ev.source().getCause())
552+
);
553+
}
554+
}
555+
IF_LISTENED_END(EVENT_TYPES::onMobHurt)
556+
});
531557
lse::events::MobHurtEvent();
532558
break;
533559

src/legacy/events/EventHooks.cpp

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,40 +1148,6 @@ LL_TYPE_INSTANCE_HOOK(
11481148
}
11491149
} // namespace HopperEvents
11501150

1151-
LL_TYPE_INSTANCE_HOOK(
1152-
MobHurtHook,
1153-
HookPriority::Normal,
1154-
Mob,
1155-
"?_hurt@Mob@@MEAA_NAEBVActorDamageSource@@M_N1@Z",
1156-
bool,
1157-
ActorDamageSource const& source,
1158-
float dmg,
1159-
bool knock,
1160-
bool ignite
1161-
) {
1162-
IF_LISTENED(EVENT_TYPES::onMobHurt) {
1163-
Actor* damageSource;
1164-
if (source.isEntitySource()) {
1165-
if (source.isChildEntitySource()) {
1166-
damageSource = ll::service::getLevel()->fetchEntity(source.getEntityUniqueID());
1167-
} else {
1168-
damageSource = ll::service::getLevel()->fetchEntity(source.getDamagingEntityUniqueID());
1169-
}
1170-
}
1171-
1172-
CallEventRtnValue(
1173-
EVENT_TYPES::onMobHurt,
1174-
false,
1175-
EntityClass::newEntity(this),
1176-
damageSource ? EntityClass::newEntity(damageSource) : Local<Value>(),
1177-
Number::newNumber(dmg),
1178-
Number::newNumber((int)source.getCause())
1179-
);
1180-
}
1181-
IF_LISTENED_END(EVENT_TYPES::onMobHurt)
1182-
return origin(source, dmg, knock, ignite);
1183-
}
1184-
11851151
LL_TYPE_INSTANCE_HOOK(
11861152
MobHurtEffectHook,
11871153
HookPriority::Normal,
@@ -1281,10 +1247,7 @@ void HopperEvent(bool pullIn) {
12811247
HopperEvents::HopperPushOutHook::hook();
12821248
}
12831249
}
1284-
void MobHurtEvent() {
1285-
MobHurtHook::hook();
1286-
MobHurtEffectHook::hook();
1287-
}
1250+
void MobHurtEvent() { MobHurtEffectHook::hook(); }
12881251

12891252
// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast)
12901253
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)

tooth.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "github.com/LiteLDev/LegacyScriptEngine",
4-
"version": "0.8.5",
4+
"version": "0.8.6",
55
"info": {
66
"name": "LegacyScriptEngine",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",
@@ -12,7 +12,7 @@
1212
]
1313
},
1414
"dependencies": {
15-
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.5",
16-
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.5"
15+
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.6",
16+
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.6"
1717
}
1818
}

tooth.lua.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-lua",
4-
"version": "0.8.5",
4+
"version": "0.8.6",
55
"info": {
66
"name": "LegacyScriptEngine with Lua backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.nodejs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-nodejs",
4-
"version": "0.8.5",
4+
"version": "0.8.6",
55
"info": {
66
"name": "LegacyScriptEngine with NodeJs backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.python.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-python",
4-
"version": "0.8.5",
4+
"version": "0.8.6",
55
"info": {
66
"name": "LegacyScriptEngine with Python backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.quickjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs",
4-
"version": "0.8.5",
4+
"version": "0.8.6",
55
"info": {
66
"name": "LegacyScriptEngine with QuickJs backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

0 commit comments

Comments
 (0)