Compare commits

...

3 Commits

8 changed files with 176 additions and 130 deletions
+48 -45
View File
@@ -1,51 +1,54 @@
/**
* @returns {string}
*/
const getPluginName = () => {
// quickjs
try {
throw new Error("getPluginName");
} catch (error) {
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes("<anonymous>")) {
return line.slice(
line.indexOf("(") + 1,
line.indexOf("\\")
);
}
if (line.includes("<eval>")) {
return line.slice(
line.indexOf("/", line.indexOf("/") + 1) + 1,
line.indexOf("\\")
);
}
}
if (getPluginName.PluginNameCache) return getPluginName.PluginNameCache;
// nodejs
try {
const path = require('path');
const selfFileName = path.basename(__filename);
const pluginDirectory = Object.entries(
require('module')._pathCache
).find(
([key, _]) =>
key.includes(selfFileName)
)[0].split("\u0000")[1];
const directories = pluginDirectory.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
} catch { }
try {
throw new Error("getPluginName");
} catch (error) {
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
const directories = line.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
return getPluginName.PluginNameCache = (() => {
if (ll.getCurrentPluginInfo) return ll.getCurrentPluginInfo().name;
const error = new Error("getPluginName");
switch (ll.scriptEngineVersion) {
case "QuickJS": {
if (!error.stack) break;
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes("<anonymous>")) {
return line.slice(
line.indexOf("(") + 1,
line.indexOf("\\")
);
}
if (line.includes("<eval>")) {
return line.slice(
line.indexOf("/", line.indexOf("/") + 1) + 1,
line.indexOf("\\")
);
}
break;
}
case "V8 12.4.254.21-node.21": {
try {
const selfFileName = require('path').basename(__filename);
const pluginDirectory = Object.entries(
require('module')._pathCache
).find(
([key, _]) => key.includes(selfFileName)
)[0].split("\u0000")[1];
const directories = pluginDirectory.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
} catch { }
if (!error.stack) break;
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
const directories = line.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
}
break;
}
default: break;
}
}
return "Unknown";
return "Unknown";
})();
};
module.exports = {
+48 -42
View File
@@ -1,50 +1,56 @@
/// <reference path='d:/dts/dts/helperlib/src/index.d.ts'/>
const getPluginName = () => {
// quickjs
try {
throw new Error("getPluginName");
} catch (error) {
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes("<anonymous>")) {
return line.slice(
line.indexOf("(") + 1,
line.indexOf("\\")
);
}
if (line.includes("<eval>")) {
return line.slice(
line.indexOf("/", line.indexOf("/") + 1) + 1,
line.indexOf("\\")
);
}
}
if (getPluginName.PluginNameCache) return getPluginName.PluginNameCache;
// nodejs
try {
const path = require('path');
const selfFileName = path.basename(__filename);
const pluginDirectory = Object.entries(
require('module')._pathCache
).find(
([key, _]) =>
key.includes(selfFileName)
)[0].split("\u0000")[1];
const directories = pluginDirectory.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
} catch { }
try {
throw new Error("getPluginName");
} catch (error) {
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
const directories = line.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
return getPluginName.PluginNameCache = (() => {
if (ll.getCurrentPluginInfo) return ll.getCurrentPluginInfo().name;
const error = new Error("getPluginName");
switch (ll.scriptEngineVersion) {
case "QuickJS": {
if (!error.stack) break;
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes("<anonymous>")) {
return line.slice(
line.indexOf("(") + 1,
line.indexOf("\\")
);
}
if (line.includes("<eval>")) {
return line.slice(
line.indexOf("/", line.indexOf("/") + 1) + 1,
line.indexOf("\\")
);
}
break;
}
case "V8 12.4.254.21-node.21": {
try {
const selfFileName = require('path').basename(__filename);
const pluginDirectory = Object.entries(
require('module')._pathCache
).find(
([key, _]) => key.includes(selfFileName)
)[0].split("\u0000")[1];
const directories = pluginDirectory.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
} catch { }
if (!error.stack) break;
const /** @type {string} */ line = error.stack.trim().split("\n").pop().trim();
if (line.includes(".js") && /:\d+:\d+$/.test(line)) {
const directories = line.split("\\");
const pluginName = directories[directories.findIndex(value => value === "plugins") + 1].trim();
if (pluginName) return pluginName;
}
break;
}
default: break;
}
}
return "Unknown";
return "Unknown";
})();
};
module.exports = {
+3
View File
@@ -14,6 +14,9 @@
},
{
"name": "iListenAttentively"
},
{
"name": "ModAPI"
}
]
}
+49 -27
View File
@@ -11,7 +11,7 @@ void Export_Compatibility_API() {
return CustomRecipeRegistry::getInstance().unregisterRecipe(id, true);
});
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void {
AddonsLoader::addCustomPackPath(path);
AddonsLoader::getInstance().addCustomPackPath(path);
});
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> double {
return GMLevel::getInstance().transform(
@@ -19,14 +19,10 @@ void Export_Compatibility_API() {
).value_or(0.0);
});
RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float {
return GMLevel::getInstance().transform(
[](GMLevel& level) -> float { return level.getServerCurrentTps(); }
).value_or(0.0);
return TpsStatus::getInstance().getLevelCurrentTps();
});
RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> double {
return GMLevel::getInstance().transform(
[](GMLevel& level) -> double { return level.getServerAverageTps(); }
).value_or(0.0);
return TpsStatus::getInstance().getLevelAverageTps();
});
RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
std::vector<std::string> result;
@@ -445,7 +441,30 @@ void Export_Compatibility_API() {
return ll::service::getLevel()->fetchEntity(parseScriptUniqueID(uniqueId), false);
});
RemoteCall::exportAs("GMLIB_API", "getWorldSpawn", []() -> std::pair<BlockPos, int> {
return {GMLevel::getInstance()->getLevelData().getSpawnPos(), 0};
constexpr static HashedString SPAWN_POS{"spawnPos"};
using mUnkfc867e = std::variant<
int,
bool,
float,
std::string,
GeneratorType,
GameType,
BlockPos,
LevelSeed64,
LevelDataValue::Tag,
DaylightCycle>;
auto& levelData = GMLevel::getInstance()->getLevelData();
if (auto it = levelData.mValues->find(SPAWN_POS); it != levelData.mValues->end()) {
if (auto value = std::get_if<BlockPos>(&it->second.mUnkfc867e.as<mUnkfc867e>()); value) {
return {*value, 0};
}
}
if (auto it = levelData.mOverrides->find(SPAWN_POS); it != levelData.mOverrides->end()) {
if (auto value = std::get_if<BlockPos>(&it->second.mUnkfc867e.as<mUnkfc867e>()); value) {
return {*value, 0};
}
}
return {BlockPos::ZERO(), 1};
});
RemoteCall::exportAs("GMLIB_API", "setWorldSpawn", [](std::pair<BlockPos, int> pos) -> bool {
if (pos.second != 0) return false;
@@ -534,7 +553,7 @@ void Export_Compatibility_API() {
.value_or(0);
});
RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKey", [](Block const* block) -> std::string {
return block->getLegacyBlock().mDescriptionId.get() + ".name";
return block->mBlockType->mDescriptionId.get() + ".name";
});
RemoteCall::exportAs("GMLIB_API", "getItemTranslateKey", [](ItemStack* item) -> std::string {
return item->getDescriptionId();
@@ -573,7 +592,7 @@ void Export_Compatibility_API() {
}
);
RemoteCall::exportAs("GMLIB_API", "itemCanDestroyBlock", [](ItemStack const* item, Block const* block) -> bool {
return std::ranges::any_of(item->mCanDestroy, [block](BlockLegacy const* blockLegacy) {
return std::ranges::any_of(item->mCanDestroy, [block](BlockType const* blockLegacy) {
return blockLegacy && block->getTypeName() == blockLegacy->getTypeName();
});
});
@@ -590,13 +609,13 @@ void Export_Compatibility_API() {
return false;
});
RemoteCall::exportAs("GMLIB_API", "blockCanDropWithAnyTool", [](Block const* block) -> bool {
return !block->getLegacyBlock().mRequiresCorrectToolForDrops;
return !block->mBlockType->mRequiresCorrectToolForDrops;
});
RemoteCall::exportAs(
"GMLIB_API",
"blockPlayerWillDestroy",
[](Block const* block, Player* player, std::pair<BlockPos, int> pos) -> bool {
return block->getLegacyBlock().playerWillDestroy(*player, pos.first, *block);
return block->mBlockType->playerWillDestroy(*player, pos.first, *block);
}
);
RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool {
@@ -630,23 +649,23 @@ void Export_Compatibility_API() {
switch (gameRule.mType) {
case GameRule::Type::Bool:
result.push_back({
{"Name", gameRule.mName },
{"Type", "Bool" },
{"Value", std::to_string(gameRule.mValue->boolVal)}
{"Name", gameRule.mName },
{"Type", "Bool" },
{"Value", std::to_string(std::get<bool>(*gameRule.mValue))}
});
break;
case GameRule::Type::Float:
result.push_back({
{"Name", gameRule.mName },
{"Type", "Float" },
{"Value", std::to_string(gameRule.mValue->floatVal)}
{"Name", gameRule.mName },
{"Type", "Float" },
{"Value", std::to_string(std::get<float>(*gameRule.mValue))}
});
break;
case GameRule::Type::Int:
result.push_back({
{"Name", gameRule.mName },
{"Type", "Int" },
{"Value", std::to_string(gameRule.mValue->intVal)}
{"Name", gameRule.mName },
{"Type", "Int" },
{"Value", std::to_string(std::get<int>(*gameRule.mValue))}
});
break;
case GameRule::Type::Invalid:
@@ -674,7 +693,7 @@ void Export_Compatibility_API() {
);
}
);
RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack* item) -> void { item->removeEnchants(); });
RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack* item) -> void { (void)item->removeEnchants(); });
RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack* item, std::string const& typeName) -> bool {
return EnchantUtils::hasEnchant(Enchant::mEnchantNameToType()[HashedString(typeName)], *item);
});
@@ -745,9 +764,9 @@ void Export_Compatibility_API() {
"GMLIB_API",
"setItemCanDestroy",
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
std::vector<const BlockLegacy*> data;
std::vector<const BlockType*> data;
for (auto& name : blocks) {
if (auto block = BlockLegacy::tryGetFromRegistry(name)) {
if (auto block = BlockType::tryGetFromRegistry(name)) {
data.push_back(block.as_ptr());
}
}
@@ -765,9 +784,9 @@ void Export_Compatibility_API() {
"GMLIB_API",
"setItemCanPlaceOn",
[](ItemStack const* item, std::vector<std::string> blocks) -> void {
std::vector<const BlockLegacy*> data;
std::vector<const BlockType*> data;
for (auto& name : blocks) {
if (auto block = BlockLegacy::tryGetFromRegistry(name)) {
if (auto block = BlockType::tryGetFromRegistry(name)) {
data.push_back(block.as_ptr());
}
}
@@ -972,7 +991,10 @@ void Export_Compatibility_API() {
return entity->isType((ActorType)type);
});
RemoteCall::exportAs("GMLIB_API", "entityHasType", [](Actor* entity, int type) -> bool {
return entity->hasType((ActorType)type);
if (auto component = entity->mEntityContext->tryGetComponent<ActorTypeComponent>(); component) {
return (type & std::to_underlying(component->mType)) == type;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "getEntityTypeId", [](Actor* entity) -> int {
return (int)entity->getEntityTypeId();
+3 -2
View File
@@ -216,10 +216,11 @@ void Export_Event_API() {
);
}
case doHash("gmlib::EndermanTakeBlockBeforeEvent"): {
REGISTER_EVENT_LISTEN(ila::mc::EndermanTakeBlockBeforeEvent,
REGISTER_EVENT_LISTEN(ila::mc::MobTakeBlockBeforeEvent,
(Actor * mob, bool isCancelled),
(&event.self(), event.isCancelled()),
event.setCancelled(result););
event.setCancelled(result);
, if (!event.self().isType(ActorType::EnderMan)) return;);
}
case doHash("gmlib::DragonRespawnBeforeEvent"): {
REGISTER_EVENT_LISTEN(ila::mc::DragonRespawnBeforeEvent,
+13 -5
View File
@@ -2,19 +2,27 @@
// clang-format off
#pragma warning(push)
#pragma warning(disable : 4996)
#define GMLIB_GLOBAL_USING
#include <gmlib/GlobalUsing.h>
#include <gmlib/include_all.h>
#pragma include_alias("mc/world/item/HumanoidArmorItem.h", "modapi/item/types/mc/HumanoidArmorItem.h")
#include <gmlib/include_ll.h>
#include <gmlib/include_lib.h>
#include <gmlib/include_mc.h>
#include <ila/include_all.h>
#include <modapi/addons/AddonsLoader.h>
#include <modapi/recipe/CustomRecipeRegistry.h>
#include <modapi/item/CustomItemRegistry.h>
#include <RemoteCallAPI.h>
using namespace gmlib::mod;
using namespace gmlib;
using namespace gmlib::ui;
using namespace gmlib::i18n;
using namespace gmlib::memory;
using namespace modapi;
#pragma warning(pop)
// clang-format on
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
#define LIB_VERSION_MAJOR 1
#define LIB_VERSION_MINOR 0
#define LIB_VERSION_MINOR 6
#define LIB_VERSION_PATCH 0
#define LIB_VERSION_PRERELEASE std::nullopt
+5 -4
View File
@@ -2,7 +2,7 @@
"format_version": 3,
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "1.4.1",
"version": "1.6.0",
"info": {
"name": "GMLIB-LegacyRemoteCallApi",
"description": "Legacy RemoteCall API for GMLIB",
@@ -19,9 +19,10 @@
{
"platform": "win-x64",
"dependencies": {
"github.com/LiteLDev/LeviLamina": ">=1.3.0",
"github.com/GroupMountain/GMLIB-Release": ">=1.3.0-rc.1",
"github.com/MiracleForest/iListenAttentively-Release": ">=0.6.0"
"github.com/LiteLDev/LeviLamina": ">=1.6.0",
"github.com/GroupMountain/GMLIB-Release": ">=1.6.0",
"github.com/GroupMountain/ModAPI-Release": ">=0.2.0",
"github.com/MiracleForest/iListenAttentively-Release": ">=0.9.0"
},
"assets": [
{
+7 -5
View File
@@ -8,11 +8,12 @@ if not has_config("vs_runtime") then
set_runtimes("MD")
end
add_requires("levilamina 1.4.1", {configs = {target_type = "server"}})
add_requires("levilamina 1.6.0", {configs = {target_type = "server"}})
add_requires("legacyremotecall")
add_requires("levibuildscript")
add_requires("ilistenattentively 0.7.0")
add_requires("gmlib 1.4.3")
add_requires("levibuildscript 0.5.2")
add_requires("ilistenattentively 0.9.0")
add_requires("gmlib 1.6.0")
add_requires("modapi 0.2.0")
target("GMLIB-LegacyRemoteCallApi")
add_cxflags(
@@ -35,7 +36,8 @@ target("GMLIB-LegacyRemoteCallApi")
"levilamina",
"legacyremotecall",
"ilistenattentively",
"gmlib"
"gmlib",
"modapi"
)
add_rules("@levibuildscript/linkrule")
add_rules("@levibuildscript/modpacker")