From 03cd4b28cf6d4c6d30a7cf902e0247c64bdcdc9b Mon Sep 17 00:00:00 2001 From: ShrBox Date: Sat, 3 Aug 2024 23:39:03 +0800 Subject: [PATCH] fix: fix onMobHurt exception #157 --- CHANGELOG.md | 8 +++++++ manifest.json | 2 +- src/legacy/api/EventAPI.cpp | 26 +++++++++++++++++++++ src/legacy/events/EventHooks.cpp | 39 +------------------------------- tooth.json | 6 ++--- tooth.lua.json | 2 +- tooth.nodejs.json | 2 +- tooth.python.json | 2 +- tooth.quickjs.json | 2 +- 9 files changed, 43 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a653fe6..58040b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.6] - 2024-08-03 + +### Fixed + +- Fix onMobHurt exception [#157] + ## [0.8.5] - 2024-07-29 ### Changed @@ -475,7 +481,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#152]: https://github.com/LiteLDev/LegacyScriptEngine/issues/152 [#153]: https://github.com/LiteLDev/LegacyScriptEngine/issues/153 [#154]: https://github.com/LiteLDev/LegacyScriptEngine/issues/154 +[#157]: https://github.com/LiteLDev/LegacyScriptEngine/issues/157 +[0.8.6]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.5...v0.8.6 [0.8.5]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.4...v0.8.5 [0.8.4]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.3...v0.8.4 [0.8.3]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.2...v0.8.3 diff --git a/manifest.json b/manifest.json index 81be614..bd4bad3 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "type": "native", "description": "A plugin engine for running LLSE plugins on LeviLamina", "author": "LiteLDev", - "version": "0.8.5", + "version": "0.8.6", "dependencies": [ { "name": "LegacyMoney" diff --git a/src/legacy/api/EventAPI.cpp b/src/legacy/api/EventAPI.cpp index d692052..04f38b6 100644 --- a/src/legacy/api/EventAPI.cpp +++ b/src/legacy/api/EventAPI.cpp @@ -47,6 +47,7 @@ #include "ll/api/service/Bedrock.h" #include "ll/api/utils/StringUtils.h" #include "main/Global.h" +#include "mc/entity/utilities/ActorType.h" #include "mc/server/commands/CommandOriginType.h" #include "mc/world/actor/player/Player.h" #include "mc/world/item/Item.h" @@ -528,6 +529,31 @@ void EnableEventListener(int eventId) { break; case EVENT_TYPES::onMobHurt: + bus.emplaceListener([](ActorHurtEvent& ev) { + IF_LISTENED(EVENT_TYPES::onMobHurt) { + if (ev.self().isType(ActorType::Mob)) { + Actor* damageSource; + if (ev.source().isEntitySource()) { + if (ev.source().isChildEntitySource()) { + damageSource = ll::service::getLevel()->fetchEntity(ev.source().getEntityUniqueID()); + } else { + damageSource = + ll::service::getLevel()->fetchEntity(ev.source().getDamagingEntityUniqueID()); + } + } + + CallEventRtnValue( + EVENT_TYPES::onMobHurt, + false, + EntityClass::newEntity(&ev.self()), + damageSource ? EntityClass::newEntity(damageSource) : Local(), + Number::newNumber(ev.damage()), + Number::newNumber((int)ev.source().getCause()) + ); + } + } + IF_LISTENED_END(EVENT_TYPES::onMobHurt) + }); lse::events::MobHurtEvent(); break; diff --git a/src/legacy/events/EventHooks.cpp b/src/legacy/events/EventHooks.cpp index 8c5bc5d..a3faace 100644 --- a/src/legacy/events/EventHooks.cpp +++ b/src/legacy/events/EventHooks.cpp @@ -1148,40 +1148,6 @@ LL_TYPE_INSTANCE_HOOK( } } // namespace HopperEvents -LL_TYPE_INSTANCE_HOOK( - MobHurtHook, - HookPriority::Normal, - Mob, - "?_hurt@Mob@@MEAA_NAEBVActorDamageSource@@M_N1@Z", - bool, - ActorDamageSource const& source, - float dmg, - bool knock, - bool ignite -) { - 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()); - } - } - - CallEventRtnValue( - EVENT_TYPES::onMobHurt, - false, - EntityClass::newEntity(this), - damageSource ? EntityClass::newEntity(damageSource) : Local(), - Number::newNumber(dmg), - Number::newNumber((int)source.getCause()) - ); - } - IF_LISTENED_END(EVENT_TYPES::onMobHurt) - return origin(source, dmg, knock, ignite); -} - LL_TYPE_INSTANCE_HOOK( MobHurtEffectHook, HookPriority::Normal, @@ -1281,10 +1247,7 @@ void HopperEvent(bool pullIn) { HopperEvents::HopperPushOutHook::hook(); } } -void MobHurtEvent() { - MobHurtHook::hook(); - MobHurtEffectHook::hook(); -} +void MobHurtEvent() { MobHurtEffectHook::hook(); } // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) diff --git a/tooth.json b/tooth.json index 3f98ff4..9fe9d25 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/LiteLDev/LegacyScriptEngine", - "version": "0.8.5", + "version": "0.8.6", "info": { "name": "LegacyScriptEngine", "description": "A plugin engine for running LLSE plugins on LeviLamina", @@ -12,7 +12,7 @@ ] }, "dependencies": { - "gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.5", - "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.5" + "gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.6", + "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.6" } } diff --git a/tooth.lua.json b/tooth.lua.json index 9a08e02..f0cbcc6 100644 --- a/tooth.lua.json +++ b/tooth.lua.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-lua", - "version": "0.8.5", + "version": "0.8.6", "info": { "name": "LegacyScriptEngine with Lua backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", diff --git a/tooth.nodejs.json b/tooth.nodejs.json index 51d92ce..86497b1 100644 --- a/tooth.nodejs.json +++ b/tooth.nodejs.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-nodejs", - "version": "0.8.5", + "version": "0.8.6", "info": { "name": "LegacyScriptEngine with NodeJs backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", diff --git a/tooth.python.json b/tooth.python.json index 20a9ddf..246f4d8 100644 --- a/tooth.python.json +++ b/tooth.python.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-python", - "version": "0.8.5", + "version": "0.8.6", "info": { "name": "LegacyScriptEngine with Python backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", diff --git a/tooth.quickjs.json b/tooth.quickjs.json index 01fd02f..1e599b2 100644 --- a/tooth.quickjs.json +++ b/tooth.quickjs.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs", - "version": "0.8.5", + "version": "0.8.6", "info": { "name": "LegacyScriptEngine with QuickJs backend", "description": "A plugin engine for running LLSE plugins on LeviLamina",