diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c05491..ae10ca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.8.18] - 2024-08-12 + +### Fixed + +- Fix onMobHurt [#157] + ## [0.8.17] - 2024-08-10 ### Fixed @@ -573,7 +579,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#157]: https://github.com/LiteLDev/LegacyScriptEngine/issues/157 [#160]: https://github.com/LiteLDev/LegacyScriptEngine/issues/160 -[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.17...HEAD +[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.18...HEAD +[0.8.18]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.17...v0.8.18 [0.8.17]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.16...v0.8.17 [0.8.16]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.15...v0.8.16 [0.8.15]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.14...v0.8.15 diff --git a/manifest.json b/manifest.json index 75fd853..09bb270 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.17", + "version": "0.8.18", "dependencies": [ { "name": "LegacyMoney" diff --git a/src/legacy/api/BlockEntityAPI.h b/src/legacy/api/BlockEntityAPI.h index 116050d..97d3997 100644 --- a/src/legacy/api/BlockEntityAPI.h +++ b/src/legacy/api/BlockEntityAPI.h @@ -7,7 +7,7 @@ class BlockActor; class BlockEntityClass : public ScriptClass { private: - BlockActor* blockEntity; + BlockActor* blockEntity = nullptr; int dim; public: diff --git a/src/legacy/api/EntityAPI.cpp b/src/legacy/api/EntityAPI.cpp index a8c0243..b6aceb4 100644 --- a/src/legacy/api/EntityAPI.cpp +++ b/src/legacy/api/EntityAPI.cpp @@ -198,10 +198,10 @@ Actor* EntityClass::extract(Local v) { else return nullptr; } -std::optional EntityClass::tryExtractActor(Local v) { +Actor* EntityClass::tryExtractActor(Local v) { if (IsInstanceOf(v)) return EntityClass::extract(v); if (IsInstanceOf(v)) return PlayerClass::extract(v); - return std::nullopt; + return nullptr; } // 成员函数 @@ -759,7 +759,7 @@ Local EntityClass::distanceTo(const Arguments& args) { } else if (IsInstanceOf(args[0]) || IsInstanceOf(args[0])) { // Player or Entity - Actor* targetActor = EntityClass::tryExtractActor(args[0]).value(); + Actor* targetActor = EntityClass::tryExtractActor(args[0]); if (!targetActor) return Local(); Vec3 targetActorPos = targetActor->getPosition(); @@ -825,7 +825,7 @@ Local EntityClass::distanceToSqr(const Arguments& args) { } else if (IsInstanceOf(args[0]) || IsInstanceOf(args[0])) { // Player or Entity - Actor* targetActor = EntityClass::tryExtractActor(args[0]).value(); + Actor* targetActor = EntityClass::tryExtractActor(args[0]); if (!targetActor) return Local(); Vec3 targetActorPos = targetActor->getPosition(); diff --git a/src/legacy/api/EntityAPI.h b/src/legacy/api/EntityAPI.h index df76ea5..95d8d75 100644 --- a/src/legacy/api/EntityAPI.h +++ b/src/legacy/api/EntityAPI.h @@ -16,10 +16,10 @@ class EntityClass : public ScriptClass { void set(Actor* actor); Actor* get(); - static Local newEntity(Actor* actor); - static Actor* extract(Local v); - static std::optional tryExtractActor(Local v); - Local asPointer(const Arguments& args); + static Local newEntity(Actor* actor); + static Actor* extract(Local v); + static Actor* tryExtractActor(Local v); + Local asPointer(const Arguments& args); Local getName(); Local getType(); diff --git a/src/legacy/api/EventAPI.cpp b/src/legacy/api/EventAPI.cpp index e292b56..e137e5d 100644 --- a/src/legacy/api/EventAPI.cpp +++ b/src/legacy/api/EventAPI.cpp @@ -522,7 +522,7 @@ void EnableEventListener(int eventId) { bus.emplaceListener([](ActorHurtEvent& ev) { IF_LISTENED(EVENT_TYPES::onMobHurt) { if (ev.self().hasType(ActorType::Mob)) { - std::optional damageSource; + Actor* damageSource = nullptr; if (ev.source().isEntitySource()) { if (ev.source().isChildEntitySource()) { damageSource = ll::service::getLevel()->fetchEntity(ev.source().getEntityUniqueID()); @@ -535,7 +535,7 @@ void EnableEventListener(int eventId) { CallEvent( EVENT_TYPES::onMobHurt, EntityClass::newEntity(&ev.self()), - damageSource.has_value() ? EntityClass::newEntity(damageSource.value()) : Local(), + damageSource ? EntityClass::newEntity(damageSource) : Local(), Number::newNumber(ev.damage()), Number::newNumber((int)ev.source().getCause()) ); diff --git a/src/legacy/api/PlayerAPI.cpp b/src/legacy/api/PlayerAPI.cpp index 9d2ad1f..592f5fc 100644 --- a/src/legacy/api/PlayerAPI.cpp +++ b/src/legacy/api/PlayerAPI.cpp @@ -643,7 +643,7 @@ Local McClass::getPlayer(const Arguments& args) { try { std::string target = args[0].toStr(); if (target.empty()) return Local(); - Player* found; + Player* found = nullptr; if (mce::UUID::canParse(target)) { // If target is UUID, then get player by using UUID found = ll::service::getLevel()->getPlayer(mce::UUID(target)); if (found) { @@ -2590,11 +2590,11 @@ Local PlayerClass::hurt(const Arguments& args) { type = args[1].asNumber().toInt32(); } if (args.size() == 3) { - std::optional source = EntityClass::tryExtractActor(args[2]); + Actor* source = EntityClass::tryExtractActor(args[2]); if (!source) { return Boolean::newBoolean(false); } - ActorDamageByActorSource damageBySource = ActorDamageByActorSource(*source.value(), (ActorDamageCause)type); + ActorDamageByActorSource damageBySource = ActorDamageByActorSource(*source, (ActorDamageCause)type); return Boolean::newBoolean(player->_hurt(damageBySource, damage, true, false)); } ActorDamageSource damageSource = ActorDamageSource((ActorDamageCause)type); @@ -3400,7 +3400,7 @@ Local PlayerClass::distanceTo(const Arguments& args) { } else if (IsInstanceOf(args[0]) || IsInstanceOf(args[0])) { // Player or Entity - Actor* targetActor = EntityClass::tryExtractActor(args[0]).value(); + Actor* targetActor = EntityClass::tryExtractActor(args[0]); if (!targetActor) return Local(); Vec3 targetActorPos = targetActor->getPosition(); @@ -3466,7 +3466,7 @@ Local PlayerClass::distanceToSqr(const Arguments& args) { } else if (IsInstanceOf(args[0]) || IsInstanceOf(args[0])) { // Player or Entity - Actor* targetActor = EntityClass::tryExtractActor(args[0]).value(); + Actor* targetActor = EntityClass::tryExtractActor(args[0]); if (!targetActor) return Local(); Vec3 targetActorPos = targetActor->getPosition(); diff --git a/src/lse/events/EventHooks.cpp b/src/lse/events/EventHooks.cpp index 0e57c85..94e6f8c 100644 --- a/src/lse/events/EventHooks.cpp +++ b/src/lse/events/EventHooks.cpp @@ -1159,7 +1159,7 @@ LL_TYPE_INSTANCE_HOOK( ) { IF_LISTENED(EVENT_TYPES::onMobHurt) { if (source.getCause() == ActorDamageCause::Magic || source.getCause() == ActorDamageCause::Wither) { - Actor* damageSource; + Actor* damageSource = nullptr; if (source.isEntitySource()) { if (source.isChildEntitySource()) { damageSource = ll::service::getLevel()->fetchEntity(source.getEntityUniqueID()); diff --git a/tooth.json b/tooth.json index 0a3283b..9854868 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/LiteLDev/LegacyScriptEngine", - "version": "0.8.17", + "version": "0.8.18", "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.17", - "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.17" + "gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.18", + "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.18" } } diff --git a/tooth.lua.json b/tooth.lua.json index afc3347..7c1541e 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.17", + "version": "0.8.18", "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 9e1774b..aac4381 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.17", + "version": "0.8.18", "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 cdc9c2b..25bee9d 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.17", + "version": "0.8.18", "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 a1c0363..01049f8 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.17", + "version": "0.8.18", "info": { "name": "LegacyScriptEngine with QuickJs backend", "description": "A plugin engine for running LLSE plugins on LeviLamina",