diff --git a/.gitignore b/.gitignore index 9bfef8b..7d43b0d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ CMakeSettings.json build/ /.xmake /CMakeLists.txt -/bin \ No newline at end of file +/bin +/.cache \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 973fe68..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "SDK-GMLIB"] - path = SDK-GMLIB - url = https://github.com/GroupMountain/SDK-GMLIB.git diff --git a/manifest.json b/manifest.json index 8689149..439dae2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { - "name": "${pluginName}", - "entry": "${pluginFile}", + "name": "${modName}", + "entry": "${modFile}", "type": "native", - "version": "0.13.0", + "version": "0.13.1", "author": "GroupMountain", "description": "Better Death Messages", "dependencies": [ diff --git a/scripts/after_build.lua b/scripts/after_build.lua index 9475b5a..2a9731c 100644 --- a/scripts/after_build.lua +++ b/scripts/after_build.lua @@ -82,16 +82,16 @@ function string_formatter(str, variables) end) end -function pack_plugin(target,plugin_define) +function pack_mod(target,mod_define) import("lib.detect.find_file") local manifest_path = find_file("manifest.json", os.projectdir()) if manifest_path then local manifest = io.readfile(manifest_path) local bindir = path.join(os.projectdir(), "bin") - local outputdir = path.join(bindir, plugin_define.pluginName) - local targetfile = path.join(outputdir, plugin_define.pluginFile) - local pdbfile = path.join(outputdir, path.basename(plugin_define.pluginFile) .. ".pdb") + local outputdir = path.join(bindir, mod_define.modName) + local targetfile = path.join(outputdir, mod_define.modFile) + local pdbfile = path.join(outputdir, path.basename(mod_define.modFile) .. ".pdb") local manifestfile = path.join(outputdir, "manifest.json") local oritargetfile = target:targetfile() local oripdbfile = path.join(path.directory(oritargetfile), path.basename(oritargetfile) .. ".pdb") @@ -102,9 +102,9 @@ function pack_plugin(target,plugin_define) os.cp(oripdbfile, pdbfile) end - formattedmanifest = string_formatter(manifest, plugin_define) + formattedmanifest = string_formatter(manifest, mod_define) io.writefile(manifestfile,formattedmanifest) - cprint("${bright green}[Plugin Packer]: ${reset}plugin already generated to " .. outputdir) + cprint("${bright green}[Mod Packer]: ${reset}mod already generated to " .. outputdir) else cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!") end @@ -112,7 +112,7 @@ end return { - pack_plugin = pack_plugin, + pack_mod = pack_mod, beautify_json = beautify_json, string_formatter = string_formatter } diff --git a/src/DeathMessage.cpp b/src/DeathMessage.cpp index e1083f3..4f63604 100644 --- a/src/DeathMessage.cpp +++ b/src/DeathMessage.cpp @@ -2,99 +2,107 @@ #include "Global.h" void RegisterDamageDefinition() { - GMLIB::Mod::DamageCause::setCustomDamageCauseEnabled(); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Anvil, "anvil"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::EntityAttack, "mob"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::RamAttack, "mob"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Drowning, "drown"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::FallingBlock, "fallingBlock"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Fire, "inFire"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::FireTick, "onFire"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Fireworks, "fireworks"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::FlyIntoWall, "flyIntoWall"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Freezing, "freeze"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Lava, "lava"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Lightning, "lightningBolt"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Wither, "wither"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Magic, "indirectMagic"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Magma, "hotFloor"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Stalactite, "stalactite"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Stalagmite, "stalagmite"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Starve, "starve"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Suffocation, "inWall"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::SonicBoom, "sonicBoom"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Void, "outOfWorld"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::SelfDestruct, "genericKill"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Projectile, "thrown"); - GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Thorns, "thorns"); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::setCustomDamageCauseEnabled(); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Anvil, "anvil"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::EntityAttack, "mob"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::RamAttack, "mob"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Drowning, "drown"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::FallingBlock, "fallingBlock"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Fire, "inFire"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::FireTick, "onFire"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Fireworks, "fireworks"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::FlyIntoWall, "flyIntoWall"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Freezing, "freeze"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Lava, "lava"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Lightning, "lightningBolt"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Wither, "wither"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Magic, "indirectMagic"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Magma, "hotFloor"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Stalactite, "stalactite"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Stalagmite, "stalagmite"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Starve, "starve"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Suffocation, "inWall"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::SonicBoom, "sonicBoom"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Void, "outOfWorld"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::SelfDestruct, "genericKill"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Projectile, "thrown"); + gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Thorns, "thorns"); + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::Projectile, "death.attack.fireball.item", "minecraft:small_fireball" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::Projectile, "death.attack.trident.item", "minecraft:thrown_trident" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::Projectile, "death.attack.spit", "minecraft:llama_spit" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::Projectile, "death.attack.bullet", "minecraft:shulker_bullet" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::Projectile, "death.attack.arrow.item", "minecraft:arrow" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::Projectile, "death.attack.explosion.player", "minecraft:fireball" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::Projectile, "death.attack.mob", "minecraft:breeze_wind_charge_projectile" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage(ActorDamageCause::Magic, "death.attack.magic", "empty"); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( + ActorDamageCause::Magic, + "death.attack.magic", + "empty" + ); + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::SonicBoom, "death.attack.sonicBoom", "minecraft:warden" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage(ActorDamageCause::Thorns, "death.attack.generic", "empty"); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( + ActorDamageCause::Thorns, + "death.attack.generic", + "empty" + ); + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::EntityExplosion, "death.attack.explosion.player", "all" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::EntityExplosion, "minecraft:wither_skull", "death.attack.witherSkull.item" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::EntityExplosion, "minecraft:wither_skull_dangerous", "death.attack.witherSkull.item" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::EntityAttack, "minecraft:player", "death.attack.player.item" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::EntityAttack, "minecraft:bee", "death.attack.sting.item" ); - GMLIB::Mod::DamageCause::registerCustomDeathMessage( + gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage( ActorDamageCause::RamAttack, "minecraft:player", "death.attack.player.item" @@ -116,8 +124,8 @@ void ListenEvents() { }); } if (config.ConsoleLog.DeathMessage) { - eventBus.emplaceListener( - [](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) { + eventBus.emplaceListener( + [](gmlib::event::entity::DeathMessageAfterEvent& ev) { auto msg = ev.getDeathMessage(); auto info = tr(msg.first, msg.second); deathLogger.info(info); diff --git a/src/Entry.cpp b/src/Entry.cpp index 62b76e3..bbf8115 100644 --- a/src/Entry.cpp +++ b/src/Entry.cpp @@ -2,7 +2,7 @@ #include "Global.h" #include "Language.h" -ll::Logger logger(PLUGIN_NAME); +ll::Logger logger(MOD_NAME); ll::Logger deathLogger("Death"); ll::Logger infoLogger("Server"); @@ -47,7 +47,7 @@ bool Entry::unload() { Config& Entry::getConfig() { return mConfig.value(); } -std::optional Entry::getI18n() { return mI18n; } +std::optional Entry::getI18n() { return mI18n; } void Entry::loadI18n() { mI18n.emplace(getSelf().getLangDir(), getConfig().ServerSideTranslation.Language); @@ -58,21 +58,19 @@ void Entry::loadI18n() { } void Entry::loadResourcePack() { - GMLIB::Mod::VanillaFix::setFixI18nEnabled(); - std::string resourcePath = "./plugins/DeathMessages/resource/"; - auto resource = GMLIB::Files::ResourceLanguage::ResourceLanguage(resourcePath, PLUGIN_NAME, 0, 8, 0); + gmlib::tools::VanillaFix::setFixI18nEnabled(); + auto resource = gmlib::i18n::ResourceI18n(getSelf().getModDir() / u8"resource", MOD_NAME, 0, 8, 0); resource.addLanguage("en_US", en_US); resource.addLanguage("zh_CN", zh_CN); - resource.initLanguage(); } } // namespace DeathMessages -LL_REGISTER_PLUGIN(DeathMessages::Entry, DeathMessages::Entry::getInstance()); +LL_REGISTER_MOD(DeathMessages::Entry, DeathMessages::Entry::getInstance()); std::string tr(std::string const& key, std::vector const& params) { if (auto i18n = DeathMessages::Entry::getInstance()->getI18n()) { return i18n->get(key, params); } - return I18nAPI::get(key, params); + return gmlib::world::I18nAPI::get(key, params); } \ No newline at end of file diff --git a/src/Entry.h b/src/Entry.h index f0d3587..16731c9 100644 --- a/src/Entry.h +++ b/src/Entry.h @@ -4,41 +4,39 @@ namespace DeathMessages { -using namespace GMLIB::Files::I18n; - class Entry { public: static std::unique_ptr& getInstance(); - Entry(ll::plugin::NativePlugin& self) : mSelf(self) {} + Entry(ll::mod::NativeMod& self) : mSelf(self) {} - [[nodiscard]] ll::plugin::NativePlugin& getSelf() const { return mSelf; } + [[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; } - /// @return True if the plugin is loaded successfully. + /// @return True if the mod is loaded successfully. bool load(); - /// @return True if the plugin is enabled successfully. + /// @return True if the mod is enabled successfully. bool enable(); - /// @return True if the plugin is disabled successfully. + /// @return True if the mod is disabled successfully. bool disable(); - /// @return True if the plugin is unloaded successfully. + /// @return True if the mod is unloaded successfully. bool unload(); Config& getConfig(); - std::optional getI18n(); + std::optional getI18n(); void loadI18n(); void loadResourcePack(); private: - ll::plugin::NativePlugin& mSelf; - std::optional mConfig; - std::optional mI18n; + ll::mod::NativeMod& mSelf; + std::optional mConfig; + std::optional mI18n; }; } // namespace DeathMessages diff --git a/src/Global.h b/src/Global.h index 347a08a..81a336f 100644 --- a/src/Global.h +++ b/src/Global.h @@ -1,7 +1,7 @@ #pragma once -#include +#include -#define PLUGIN_NAME "DeathMessages" +#define MOD_NAME "DeathMessages" extern ll::Logger logger; extern ll::Logger deathLogger; @@ -10,5 +10,4 @@ extern ll::Logger infoLogger; extern std::string tr(std::string const& key, std::vector const& data = {}); extern void RegisterDamageDefinition(); -extern void ListenEvents(); -extern void initPlugin(); \ No newline at end of file +extern void ListenEvents(); \ No newline at end of file diff --git a/src/MemoryOperators.cpp b/src/MemoryOperators.cpp index a81be3a..0172f0d 100644 --- a/src/MemoryOperators.cpp +++ b/src/MemoryOperators.cpp @@ -1,5 +1,5 @@ -// This file will make your plugin use LeviLamina's memory operators by default. -// This improves the memory management of your plugin and is recommended to use. +// This file will make your mod use LeviLamina's memory operators by default. +// This improves the memory management of your mod and is recommended to use. #define LL_MEMORY_OPERATORS diff --git a/tooth.json b/tooth.json index 031fb88..8176e88 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/GroupMountain/DeathMessages", - "version": "0.13.0", + "version": "0.13.1", "info": { "name": "DeathMessages", "description": "Better Death Messages on MCBE", @@ -11,9 +11,9 @@ "DeathMessages" ] }, - "asset_url": "https://github.com/GroupMountain/DeathMessages/releases/download/v0.13.0/DeathMessages-windows-x64.zip", + "asset_url": "https://github.com/GroupMountain/DeathMessages/releases/download/v0.13.1/DeathMessages-windows-x64.zip", "dependencies": { - "github.com/GroupMountain/GMLIB": ">=0.13.0" + "github.com/GroupMountain/GMLIB": ">=0.13.8" }, "files": { "place": [ diff --git a/xmake.lua b/xmake.lua index 28797eb..c950500 100644 --- a/xmake.lua +++ b/xmake.lua @@ -42,7 +42,7 @@ add_requires("gmlib") -- import("package.tools.xmake").install(package) -- end) -target("DeathMessages") -- Change this to your plugin name. +target("DeathMessages") -- Change this to your mod name. add_cxflags( "/EHa", "/utf-8" @@ -66,14 +66,15 @@ target("DeathMessages") -- Change this to your plugin name. set_exceptions("none") -- To avoid conflicts with /EHa set_kind("shared") set_languages("cxx23") + set_symbols("debug") after_build(function (target) - local plugin_packer = import("scripts.after_build") + local mod_packer = import("scripts.after_build") - local plugin_define = { - pluginName = target:name(), - pluginFile = path.filename(target:targetfile()), + local mod_define = { + modName = target:name(), + modFile = path.filename(target:targetfile()), } - plugin_packer.pack_plugin(target,plugin_define) + mod_packer.pack_mod(target,mod_define) end)