dapt: adapt to GMLIB v0.13.8

This commit is contained in:
子沐呀
2024-11-04 16:33:20 +08:00
Unverified
parent ea77ebe7a2
commit c16046e405
11 changed files with 93 additions and 91 deletions
+1
View File
@@ -15,3 +15,4 @@ build/
/.xmake /.xmake
/CMakeLists.txt /CMakeLists.txt
/bin /bin
/.cache
-3
View File
@@ -1,3 +0,0 @@
[submodule "SDK-GMLIB"]
path = SDK-GMLIB
url = https://github.com/GroupMountain/SDK-GMLIB.git
+3 -3
View File
@@ -1,8 +1,8 @@
{ {
"name": "${pluginName}", "name": "${modName}",
"entry": "${pluginFile}", "entry": "${modFile}",
"type": "native", "type": "native",
"version": "0.13.0", "version": "0.13.1",
"author": "GroupMountain", "author": "GroupMountain",
"description": "Better Death Messages", "description": "Better Death Messages",
"dependencies": [ "dependencies": [
+7 -7
View File
@@ -82,16 +82,16 @@ function string_formatter(str, variables)
end) end)
end end
function pack_plugin(target,plugin_define) function pack_mod(target,mod_define)
import("lib.detect.find_file") import("lib.detect.find_file")
local manifest_path = find_file("manifest.json", os.projectdir()) local manifest_path = find_file("manifest.json", os.projectdir())
if manifest_path then if manifest_path then
local manifest = io.readfile(manifest_path) local manifest = io.readfile(manifest_path)
local bindir = path.join(os.projectdir(), "bin") local bindir = path.join(os.projectdir(), "bin")
local outputdir = path.join(bindir, plugin_define.pluginName) local outputdir = path.join(bindir, mod_define.modName)
local targetfile = path.join(outputdir, plugin_define.pluginFile) local targetfile = path.join(outputdir, mod_define.modFile)
local pdbfile = path.join(outputdir, path.basename(plugin_define.pluginFile) .. ".pdb") local pdbfile = path.join(outputdir, path.basename(mod_define.modFile) .. ".pdb")
local manifestfile = path.join(outputdir, "manifest.json") local manifestfile = path.join(outputdir, "manifest.json")
local oritargetfile = target:targetfile() local oritargetfile = target:targetfile()
local oripdbfile = path.join(path.directory(oritargetfile), path.basename(oritargetfile) .. ".pdb") 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) os.cp(oripdbfile, pdbfile)
end end
formattedmanifest = string_formatter(manifest, plugin_define) formattedmanifest = string_formatter(manifest, mod_define)
io.writefile(manifestfile,formattedmanifest) 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 else
cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!") cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!")
end end
@@ -112,7 +112,7 @@ end
return { return {
pack_plugin = pack_plugin, pack_mod = pack_mod,
beautify_json = beautify_json, beautify_json = beautify_json,
string_formatter = string_formatter string_formatter = string_formatter
} }
+51 -43
View File
@@ -2,99 +2,107 @@
#include "Global.h" #include "Global.h"
void RegisterDamageDefinition() { void RegisterDamageDefinition() {
GMLIB::Mod::DamageCause::setCustomDamageCauseEnabled(); gmlib::mod::damage::DamageCauseRegistry::setCustomDamageCauseEnabled();
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Anvil, "anvil"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Anvil, "anvil");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::EntityAttack, "mob"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::EntityAttack, "mob");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::RamAttack, "mob"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::RamAttack, "mob");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Drowning, "drown"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Drowning, "drown");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::FallingBlock, "fallingBlock"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::FallingBlock, "fallingBlock");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Fire, "inFire"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Fire, "inFire");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::FireTick, "onFire"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::FireTick, "onFire");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Fireworks, "fireworks"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Fireworks, "fireworks");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::FlyIntoWall, "flyIntoWall"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::FlyIntoWall, "flyIntoWall");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Freezing, "freeze"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Freezing, "freeze");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Lava, "lava"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Lava, "lava");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Lightning, "lightningBolt"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Lightning, "lightningBolt");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Wither, "wither"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Wither, "wither");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Magic, "indirectMagic"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Magic, "indirectMagic");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Magma, "hotFloor"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Magma, "hotFloor");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Stalactite, "stalactite"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Stalactite, "stalactite");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Stalagmite, "stalagmite"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Stalagmite, "stalagmite");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Starve, "starve"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Starve, "starve");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Suffocation, "inWall"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Suffocation, "inWall");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::SonicBoom, "sonicBoom"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::SonicBoom, "sonicBoom");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Void, "outOfWorld"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Void, "outOfWorld");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::SelfDestruct, "genericKill"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::SelfDestruct, "genericKill");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Projectile, "thrown"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Projectile, "thrown");
GMLIB::Mod::DamageCause::setVanillaCauseMessage(ActorDamageCause::Thorns, "thorns"); gmlib::mod::damage::DamageCauseRegistry::setVanillaCauseMessage(ActorDamageCause::Thorns, "thorns");
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::Projectile, ActorDamageCause::Projectile,
"death.attack.fireball.item", "death.attack.fireball.item",
"minecraft:small_fireball" "minecraft:small_fireball"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::Projectile, ActorDamageCause::Projectile,
"death.attack.trident.item", "death.attack.trident.item",
"minecraft:thrown_trident" "minecraft:thrown_trident"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::Projectile, ActorDamageCause::Projectile,
"death.attack.spit", "death.attack.spit",
"minecraft:llama_spit" "minecraft:llama_spit"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::Projectile, ActorDamageCause::Projectile,
"death.attack.bullet", "death.attack.bullet",
"minecraft:shulker_bullet" "minecraft:shulker_bullet"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::Projectile, ActorDamageCause::Projectile,
"death.attack.arrow.item", "death.attack.arrow.item",
"minecraft:arrow" "minecraft:arrow"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::Projectile, ActorDamageCause::Projectile,
"death.attack.explosion.player", "death.attack.explosion.player",
"minecraft:fireball" "minecraft:fireball"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::Projectile, ActorDamageCause::Projectile,
"death.attack.mob", "death.attack.mob",
"minecraft:breeze_wind_charge_projectile" "minecraft:breeze_wind_charge_projectile"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage(ActorDamageCause::Magic, "death.attack.magic", "empty"); gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
GMLIB::Mod::DamageCause::registerCustomDeathMessage( ActorDamageCause::Magic,
"death.attack.magic",
"empty"
);
gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::SonicBoom, ActorDamageCause::SonicBoom,
"death.attack.sonicBoom", "death.attack.sonicBoom",
"minecraft:warden" "minecraft:warden"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage(ActorDamageCause::Thorns, "death.attack.generic", "empty"); gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
GMLIB::Mod::DamageCause::registerCustomDeathMessage( ActorDamageCause::Thorns,
"death.attack.generic",
"empty"
);
gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::EntityExplosion, ActorDamageCause::EntityExplosion,
"death.attack.explosion.player", "death.attack.explosion.player",
"all" "all"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::EntityExplosion, ActorDamageCause::EntityExplosion,
"minecraft:wither_skull", "minecraft:wither_skull",
"death.attack.witherSkull.item" "death.attack.witherSkull.item"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::EntityExplosion, ActorDamageCause::EntityExplosion,
"minecraft:wither_skull_dangerous", "minecraft:wither_skull_dangerous",
"death.attack.witherSkull.item" "death.attack.witherSkull.item"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::EntityAttack, ActorDamageCause::EntityAttack,
"minecraft:player", "minecraft:player",
"death.attack.player.item" "death.attack.player.item"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::EntityAttack, ActorDamageCause::EntityAttack,
"minecraft:bee", "minecraft:bee",
"death.attack.sting.item" "death.attack.sting.item"
); );
GMLIB::Mod::DamageCause::registerCustomDeathMessage( gmlib::mod::damage::DamageCauseRegistry::registerCustomDeathMessage(
ActorDamageCause::RamAttack, ActorDamageCause::RamAttack,
"minecraft:player", "minecraft:player",
"death.attack.player.item" "death.attack.player.item"
@@ -116,8 +124,8 @@ void ListenEvents() {
}); });
} }
if (config.ConsoleLog.DeathMessage) { if (config.ConsoleLog.DeathMessage) {
eventBus.emplaceListener<GMLIB::Event::EntityEvent::DeathMessageAfterEvent>( eventBus.emplaceListener<gmlib::event::entity::DeathMessageAfterEvent>(
[](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) { [](gmlib::event::entity::DeathMessageAfterEvent& ev) {
auto msg = ev.getDeathMessage(); auto msg = ev.getDeathMessage();
auto info = tr(msg.first, msg.second); auto info = tr(msg.first, msg.second);
deathLogger.info(info); deathLogger.info(info);
+6 -7
View File
@@ -2,7 +2,7 @@
#include "Global.h" #include "Global.h"
#include "Language.h" #include "Language.h"
ll::Logger logger(PLUGIN_NAME); ll::Logger logger(MOD_NAME);
ll::Logger deathLogger("Death"); ll::Logger deathLogger("Death");
ll::Logger infoLogger("Server"); ll::Logger infoLogger("Server");
@@ -47,7 +47,7 @@ bool Entry::unload() {
Config& Entry::getConfig() { return mConfig.value(); } Config& Entry::getConfig() { return mConfig.value(); }
std::optional<LangI18n> Entry::getI18n() { return mI18n; } std::optional<gmlib::i18n::LangI18n> Entry::getI18n() { return mI18n; }
void Entry::loadI18n() { void Entry::loadI18n() {
mI18n.emplace(getSelf().getLangDir(), getConfig().ServerSideTranslation.Language); mI18n.emplace(getSelf().getLangDir(), getConfig().ServerSideTranslation.Language);
@@ -58,21 +58,20 @@ void Entry::loadI18n() {
} }
void Entry::loadResourcePack() { void Entry::loadResourcePack() {
GMLIB::Mod::VanillaFix::setFixI18nEnabled(); gmlib::tools::VanillaFix::setFixI18nEnabled();
std::string resourcePath = "./plugins/DeathMessages/resource/"; std::string resourcePath = "./plugins/DeathMessages/resource/";
auto resource = GMLIB::Files::ResourceLanguage::ResourceLanguage(resourcePath, PLUGIN_NAME, 0, 8, 0); auto resource = gmlib::i18n::ResourceI18n(resourcePath, MOD_NAME, 0, 8, 0);
resource.addLanguage("en_US", en_US); resource.addLanguage("en_US", en_US);
resource.addLanguage("zh_CN", zh_CN); resource.addLanguage("zh_CN", zh_CN);
resource.initLanguage();
} }
} // namespace DeathMessages } // 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<std::string> const& params) { std::string tr(std::string const& key, std::vector<std::string> const& params) {
if (auto i18n = DeathMessages::Entry::getInstance()->getI18n()) { if (auto i18n = DeathMessages::Entry::getInstance()->getI18n()) {
return i18n->get(key, params); return i18n->get(key, params);
} }
return I18nAPI::get(key, params); return gmlib::world::I18nAPI::get(key, params);
} }
+9 -11
View File
@@ -4,41 +4,39 @@
namespace DeathMessages { namespace DeathMessages {
using namespace GMLIB::Files::I18n;
class Entry { class Entry {
public: public:
static std::unique_ptr<Entry>& getInstance(); static std::unique_ptr<Entry>& 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(); bool load();
/// @return True if the plugin is enabled successfully. /// @return True if the mod is enabled successfully.
bool enable(); bool enable();
/// @return True if the plugin is disabled successfully. /// @return True if the mod is disabled successfully.
bool disable(); bool disable();
/// @return True if the plugin is unloaded successfully. /// @return True if the mod is unloaded successfully.
bool unload(); bool unload();
Config& getConfig(); Config& getConfig();
std::optional<LangI18n> getI18n(); std::optional<gmlib::i18n::LangI18n> getI18n();
void loadI18n(); void loadI18n();
void loadResourcePack(); void loadResourcePack();
private: private:
ll::plugin::NativePlugin& mSelf; ll::mod::NativeMod& mSelf;
std::optional<Config> mConfig; std::optional<Config> mConfig;
std::optional<LangI18n> mI18n; std::optional<gmlib::i18n::LangI18n> mI18n;
}; };
} // namespace DeathMessages } // namespace DeathMessages
+2 -3
View File
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <include_all.h> #include <headers/include_all.h>
#define PLUGIN_NAME "DeathMessages" #define MOD_NAME "DeathMessages"
extern ll::Logger logger; extern ll::Logger logger;
extern ll::Logger deathLogger; extern ll::Logger deathLogger;
@@ -11,4 +11,3 @@ extern std::string tr(std::string const& key, std::vector<std::string> const& da
extern void RegisterDamageDefinition(); extern void RegisterDamageDefinition();
extern void ListenEvents(); extern void ListenEvents();
extern void initPlugin();
+2 -2
View File
@@ -1,5 +1,5 @@
// This file will make your plugin use LeviLamina's memory operators by default. // This file will make your mod use LeviLamina's memory operators by default.
// This improves the memory management of your plugin and is recommended to use. // This improves the memory management of your mod and is recommended to use.
#define LL_MEMORY_OPERATORS #define LL_MEMORY_OPERATORS
+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"format_version": 2, "format_version": 2,
"tooth": "github.com/GroupMountain/DeathMessages", "tooth": "github.com/GroupMountain/DeathMessages",
"version": "0.13.0", "version": "0.13.1",
"info": { "info": {
"name": "DeathMessages", "name": "DeathMessages",
"description": "Better Death Messages on MCBE", "description": "Better Death Messages on MCBE",
@@ -11,9 +11,9 @@
"DeathMessages" "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": { "dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.13.0" "github.com/GroupMountain/GMLIB": ">=0.13.8"
}, },
"files": { "files": {
"place": [ "place": [
+6 -6
View File
@@ -42,7 +42,7 @@ add_requires("gmlib")
-- import("package.tools.xmake").install(package) -- import("package.tools.xmake").install(package)
-- end) -- end)
target("DeathMessages") -- Change this to your plugin name. target("DeathMessages") -- Change this to your mod name.
add_cxflags( add_cxflags(
"/EHa", "/EHa",
"/utf-8" "/utf-8"
@@ -68,12 +68,12 @@ target("DeathMessages") -- Change this to your plugin name.
set_languages("cxx23") set_languages("cxx23")
after_build(function (target) after_build(function (target)
local plugin_packer = import("scripts.after_build") local mod_packer = import("scripts.after_build")
local plugin_define = { local mod_define = {
pluginName = target:name(), modName = target:name(),
pluginFile = path.filename(target:targetfile()), modFile = path.filename(target:targetfile()),
} }
plugin_packer.pack_plugin(target,plugin_define) mod_packer.pack_mod(target,mod_define)
end) end)