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
+2 -1
View File
@@ -14,4 +14,5 @@ CMakeSettings.json
build/
/.xmake
/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}",
"entry": "${pluginFile}",
"name": "${modName}",
"entry": "${modFile}",
"type": "native",
"version": "0.13.0",
"version": "0.13.1",
"author": "GroupMountain",
"description": "Better Death Messages",
"dependencies": [
+7 -7
View File
@@ -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
}
+51 -43
View File
@@ -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>(
[](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) {
eventBus.emplaceListener<gmlib::event::entity::DeathMessageAfterEvent>(
[](gmlib::event::entity::DeathMessageAfterEvent& ev) {
auto msg = ev.getDeathMessage();
auto info = tr(msg.first, msg.second);
deathLogger.info(info);
+6 -7
View File
@@ -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<LangI18n> Entry::getI18n() { return mI18n; }
std::optional<gmlib::i18n::LangI18n> Entry::getI18n() { return mI18n; }
void Entry::loadI18n() {
mI18n.emplace(getSelf().getLangDir(), getConfig().ServerSideTranslation.Language);
@@ -58,21 +58,20 @@ void Entry::loadI18n() {
}
void Entry::loadResourcePack() {
GMLIB::Mod::VanillaFix::setFixI18nEnabled();
gmlib::tools::VanillaFix::setFixI18nEnabled();
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("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<std::string> 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);
}
+10 -12
View File
@@ -4,41 +4,39 @@
namespace DeathMessages {
using namespace GMLIB::Files::I18n;
class Entry {
public:
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();
/// @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<LangI18n> getI18n();
std::optional<gmlib::i18n::LangI18n> getI18n();
void loadI18n();
void loadResourcePack();
private:
ll::plugin::NativePlugin& mSelf;
std::optional<Config> mConfig;
std::optional<LangI18n> mI18n;
ll::mod::NativeMod& mSelf;
std::optional<Config> mConfig;
std::optional<gmlib::i18n::LangI18n> mI18n;
};
} // namespace DeathMessages
+3 -4
View File
@@ -1,7 +1,7 @@
#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 deathLogger;
@@ -10,5 +10,4 @@ extern ll::Logger infoLogger;
extern std::string tr(std::string const& key, std::vector<std::string> const& data = {});
extern void RegisterDamageDefinition();
extern void ListenEvents();
extern void initPlugin();
extern void ListenEvents();
+2 -2
View File
@@ -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
+3 -3
View File
@@ -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": [
+6 -6
View File
@@ -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"
@@ -68,12 +68,12 @@ target("DeathMessages") -- Change this to your plugin name.
set_languages("cxx23")
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)