From 0fe3c691e5148d146d6adc6266fe04c4ac954831 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 Date: Mon, 4 Mar 2024 22:02:52 +0800 Subject: [PATCH] feat: death message event --- src/CompatibilityApi.cpp | 8 ++++++++ src/EventAPI.cpp | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 9a544ee..729172f 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -133,4 +133,12 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string { return GMLIB::Version::getLibVersionString(); }); + RemoteCall::exportAs( + "GMLIB_API", + "resourcePackTranslate", + [](std::string key, std::vector params) -> std::string { return I18n::get(key, params); } + ); + RemoteCall::exportAs("GMLIB_API", "chooseResourcePackI18nLanguage", [](std::string code) -> void { + I18n::chooseLanguage(code); + }); } \ No newline at end of file diff --git a/src/EventAPI.cpp b/src/EventAPI.cpp index 8a6a98f..73189ff 100644 --- a/src/EventAPI.cpp +++ b/src/EventAPI.cpp @@ -132,6 +132,26 @@ void Export_Event_API() { ); return true; } + case do_hash("onDeathMessage"): { + auto Call = RemoteCall::importAs< + bool(std::string message, std::vector, Actor * dead, Actor * killer, int cause)>( + eventName, + eventId + ); + eventBus->emplaceListener( + [Call](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) { + auto msg = ev.getDeathMessage(); + auto source = ev.getDamageSource(); + Actor* entity = nullptr; + entity = GMLIB_Level::getLevel()->fetchEntity(source.getDamagingEntityUniqueID()); + if (entity->getOwner()) { + entity = entity->getOwner(); + } + Call(msg.first, msg.second, &ev.self(), entity, (int)source.getCause()); + } + ); + return true; + } default: return false; }