Skip to content

Commit

Permalink
fix: fix onMobHurt exception #157
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Aug 3, 2024
1 parent 79b4dce commit 03cd4b2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 46 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions src/legacy/api/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -528,6 +529,31 @@ void EnableEventListener(int eventId) {
break;

case EVENT_TYPES::onMobHurt:
bus.emplaceListener<ActorHurtEvent>([](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<Value>(),
Number::newNumber(ev.damage()),
Number::newNumber((int)ev.source().getCause())
);
}
}
IF_LISTENED_END(EVENT_TYPES::onMobHurt)
});
lse::events::MobHurtEvent();
break;

Expand Down
39 changes: 1 addition & 38 deletions src/legacy/events/EventHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value>(),
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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tooth.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion tooth.lua.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tooth.nodejs.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tooth.python.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tooth.quickjs.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 03cd4b2

Please sign in to comment.