feat: adapt gmlib 1.0.0

This commit is contained in:
zimuya4153
2025-04-16 17:47:08 +08:00
Unverified
parent 1693ac7290
commit ce7da22e96
10 changed files with 203 additions and 146 deletions
+41 -46
View File
@@ -1,17 +1,17 @@
#include "Global.h"
#include <regex>
#include <unordered_map>
ActorUniqueID parseScriptUniqueID(std::string const& uniqueId) {
return StringUtils::isInteger(uniqueId) ? ActorUniqueID(std::stoll(uniqueId)) : ActorUniqueID::INVALID_ID();
return string_utils::isInteger(uniqueId) ? ActorUniqueID(std::stoll(uniqueId)) : ActorUniqueID::INVALID_ID();
}
void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "unregisterRecipe", [](std::string const& id) -> bool {
// return GMLevel::getInstance().has_value() ? GMLIB::Mod::CustomRecipe::unregisterRecipe(id) : false;
throw std::runtime_error("GMLIB_API::unregisterRecipe is not implemented");
return CustomRecipeRegistry::getInstance().unregisterRecipe(id, true);
});
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void {
AddonsLoaderUtils::addCustomPackPath(path);
AddonsLoader::addCustomPackPath(path);
});
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> double {
return GMLevel::getInstance().transform(
@@ -66,20 +66,21 @@ void Export_Compatibility_API() {
return OfflinePlayer::deletePlayerNbt(mce::UUID::fromString(uuid));
});
RemoteCall::exportAs("GMLIB_API", "getAllExperiments", []() -> std::vector<int> {
// std::vector<int> result;
// for (auto& key : GMLevel::getAllExperiments()) {
// result.push_back((int)key);
// }
// return result;
throw std::runtime_error("GMLIB_API::getAllExperiments is not implemented");
return {36, 45, 38, 48, 47, 53, 56, 45, 40};
});
RemoteCall::exportAs("GMLIB_API", "getExperimentTranslateKey", [](int id) -> std::string {
// std::string result;
// try {
// result = Experiments::getExperimentTextID(AllExperiments(id));
// } catch (...) {}
// return result;
throw std::runtime_error("GMLIB_API::getExperimentTranslateKey is not implemented");
static std::unordered_map<int, std::string> mMap = {
{36, "createWorldScreen.experimentalbiomes" },
{45, "createWorldScreen.experimentalCreatorFeatures" },
{38, "createWorldScreen.experimentalGameTest" },
{48, "createWorldScreen.experimentalThirdPersonCameras" },
{47, "createWorldScreen.experimentalFocusTargetCamera" },
{53, "createWorldScreen.experimentalVillagerTradesRebalance" },
{56, "createWorldScreen.experimentalDataDrivenJigsawStructures"},
{45, "createWorldScreen.experimentalCameraAimAssist" },
{40, "createWorldScreen.experimentalY2025Drop1" }
};
return mMap.contains(id) ? mMap[id] : "";
});
RemoteCall::exportAs(
"GMLIB_API",
@@ -213,8 +214,10 @@ void Export_Compatibility_API() {
"GMLIB_API",
"setPlayerPosition",
[](std::string const& uuid, std::pair<BlockPos, int> pos) -> bool {
// return GMPlayer::setPlayerPosition(mce::UUID::fromString(uuid), pos.first, pos.second);
throw std::runtime_error("GMLIB_API::setPlayerPosition is not implemented");
if (auto player = OfflinePlayer::getOfflinePlayer(mce::UUID::fromString(uuid))) {
return player->setPosition(pos.first, pos.second);
}
return false;
}
);
RemoteCall::exportAs("GMLIB_API", "playerHasScore", [](std::string const& uuid, std::string const& obj) -> bool {
@@ -452,17 +455,14 @@ void Export_Compatibility_API() {
return true;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerSpawnPoint", [](Player* pl) -> std::pair<BlockPos, int> {
// auto res = ((GMPlayer*)pl)->getSpawnPoint();
// return {res.first, res.second};
throw std::runtime_error("GMLIB_API::getPlayerSpawnPoint is not implemented");
return {pl->mPlayerRespawnPoint->mSpawnBlockPos, pl->mPlayerRespawnPoint->mDimension.get()};
});
RemoteCall::exportAs("GMLIB_API", "setPlayerSpawnPoint", [](Player* pl, std::pair<BlockPos, int> pos) -> void {
// ((GMPlayer*)pl)->setSpawnPoint(pos.first, pos.second);
throw std::runtime_error("GMLIB_API::setPlayerSpawnPoint is not implemented");
pl->setRespawnPosition(pos.first, pos.second);
});
RemoteCall::exportAs("GMLIB_API", "clearPlayerSpawnPoint", [](Player* pl) -> void {
// ((GMPlayer*)pl)->clearSpawnPoint();
throw std::runtime_error("GMLIB_API::clearPlayerSpawnPoint is not implemented");
pl->mPlayerRespawnPoint->mSpawnBlockPos = BlockPos::MIN();
pl->mPlayerRespawnPoint->mDimension = VanillaDimensions::Undefined();
});
RemoteCall::exportAs(
"GMLIB_API",
@@ -546,8 +546,7 @@ void Export_Compatibility_API() {
return block->mDirectData->mUnkc08fbd.as<float>();
});
RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](ItemStack const* item, Block const* block) -> float {
// return item->getDestroySpeed(*block);
throw std::runtime_error("GMLIB_API::getDestroyBlockSpeed is not implemented");
return item->getItem()->getDestroySpeed(*item, *block);
});
RemoteCall::exportAs(
"GMLIB_API",
@@ -568,8 +567,7 @@ void Export_Compatibility_API() {
return false;
});
RemoteCall::exportAs("GMLIB_API", "itemCanDestroySpecial", [](ItemStack const* item, Block const* block) -> bool {
// return item->canDestroySpecial(*block);
throw std::runtime_error("GMLIB_API::itemCanDestroySpecial is not implemented");
return item->getItem()->canDestroySpecial(*block);
});
RemoteCall::exportAs("GMLIB_API", "blockCanDropWithAnyTool", [](Block const* block) -> bool {
return !block->getLegacyBlock().mRequiresCorrectToolForDrops;
@@ -584,9 +582,10 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool {
return player->attack(*entity, SharedTypes::Legacy::ActorDamageCause::EntityAttack);
});
RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](Player* player, Actor* entity) -> bool {
// return player->pullInEntity(*entity);
throw std::runtime_error("GMLIB_API::playerPullInEntity is not implemented");
RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](Player* player, Actor* entity) -> void {
if (auto component = player->getEntityContext().tryGetComponent<RideableComponent>()){
component->pullInEntity(*player, *entity);
}
});
RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKeyFromName", [](std::string const& blockName) -> std::string {
return Block::tryGetFromRegistry(blockName)
@@ -896,20 +895,16 @@ void Export_Compatibility_API() {
"GMLIB_API",
"registerCustomShapelessRecipe",
[](std::string const& recipe_id, std::vector<std::string> ingredients, ItemStack* result) -> void {
// if (!GMLevel::getInstance().has_value()) return;
// std::vector<Recipes::Type> types;
// char rt = 'A';
// for (auto& ing : ingredients) {
// auto ingredient = RecipeIngredient{ing, 0,1};
// types.push_back(Recipes::Type{
// (Item*)ingredient.getItem(),
// ingredient.getBlock(),
// ingredient,
// rt++
// });
// }
// GMLIB::Mod::CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, *result);
throw std::runtime_error("GMLIB_API::registerCustomShapelessRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
std::vector<ICustomRecipe::Ingredient> types;
for (auto& ing : ingredients) {
types.push_back(ICustomRecipe::Ingredient{ing});
}
CustomRecipeRegistry::getInstance().registerShapelessRecipe(
recipe_id,
types,
ItemInstance(*result->getItem(), result->mCount, result->mAuxValue, result->mUserData.get())
);
}
);
RemoteCall::exportAs(
+4 -1
View File
@@ -9,6 +9,7 @@ LegacyRemoteCallApi& LegacyRemoteCallApi::getInstance() {
}
bool LegacyRemoteCallApi::load() {
(void)CustomRecipeRegistry::getInstance();
Export_Legacy_GMLib_ModAPI();
Export_Legacy_GMLib_ServerAPI();
Export_Compatibility_API();
@@ -39,4 +40,6 @@ LL_REGISTER_MOD(gmlib::LegacyRemoteCallApi, gmlib::LegacyRemoteCallApi::getInsta
ll::thread::ThreadPoolExecutor const& getThreadPoolExecutor() {
return gmlib::LegacyRemoteCallApi::getInstance().getThreadPoolExecutor();
}
}
ll::io::Logger& getLogger() { return gmlib::LegacyRemoteCallApi::getInstance().getSelf().getLogger(); }
+1 -1
View File
@@ -141,7 +141,7 @@ void Export_Event_API() {
REGISTER_EVENT_LISTEN(
ila::mc::SpawnItemActorAfterEvent,
(Actor * item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
(event.itemActor(),
(&event.itemActor(),
{event.pos(), event.blockSource().getDimensionId().id},
event.spawner() ? event.spawner()->getOrCreateUniqueID().rawID : -1),
,
+3 -1
View File
@@ -1,10 +1,11 @@
#pragma once
// clang-format off
#define GMLIB_Gloabl_Using
#define GMLIB_GLOBAL_USING
#include <gmlib/GlobalUsing.h>
#include <gmlib/include_all.h>
#include <ila/include_all.h>
#include <RemoteCallAPI.h>
using namespace gmlib::mod;
// clang-format on
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
@@ -27,4 +28,5 @@ extern void ExportPAPI();
extern void Export_Event_API();
extern void Export_BinaryStream_API();
extern ll::thread::ThreadPoolExecutor const& getThreadPoolExecutor();
extern ll::io::Logger& getLogger();
// extern void Export_Form_API();
+63 -73
View File
@@ -1,12 +1,13 @@
#include "Global.h"
#include "gmlib/mod/recipe/CustomRecipeRegistry.h"
#include <gmlib/mc/world/Level.h>
#include <mc/world/item/crafting/RecipeIngredient.h>
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string const& key) {
if (HardCodedKeys.count(key)) return key;
return std::vector<RecipeIngredient>({RecipeIngredient(key, 0, 1)});
ICustomRecipe::UnlockingRequirement makeRecipeUnlockingKey(std::string const& key) {
if (HardCodedKeys.count(key)) return {{ICustomRecipe::Ingredient{key}}};
return ICustomRecipe::UnlockingRequirement({ICustomRecipe::Ingredient(key, 1, 0)});
}
void Export_Legacy_GMLib_ModAPI() {
@@ -19,18 +20,13 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& result,
int count,
std::string const& unlock) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// std::vector<RecipeIngredient> types;
// for (auto ing : ingredients) {
// types.emplace_back(ing, 0, 1);
// }
// GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(
// recipe_id,
// types,
// RecipeIngredient(result, 0, count),
// makeRecipeUnlockingKey(unlock)
// );
throw std::runtime_error("GMLib_ModAPI::registerShapelessRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
std::vector<ICustomRecipe::Ingredient> types;
for (auto& ing : ingredients) {
types.emplace_back(ICustomRecipe::Ingredient{ing, 1});
}
CustomRecipeRegistry::getInstance()
.registerShapelessRecipe(recipe_id, types, ItemInstance(result, count), makeRecipeUnlockingKey(unlock));
}
);
RemoteCall::exportAs(
@@ -42,19 +38,20 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& result,
int count,
std::string const& unlock) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// std::vector<RecipeIngredient> types;
// for (auto ing : ingredients) {
// types.push_back(RecipeIngredient(ing, 0, 1));
// }
// GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(
// recipe_id,
// shape,
// types,
// RecipeIngredient(result, 0, count),
// makeRecipeUnlockingKey(unlock)
// );
throw std::runtime_error("GMLib_ModAPI::registerShapedRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
ICustomShapedRecipe::ShapedIngredients types;
char index = 'a';
for (auto& ing : ingredients) {
types.add(std::string{index++}, ICustomRecipe::Ingredient{ing, 1});
}
CustomRecipeRegistry::getInstance().registerShapedRecipe(
recipe_id,
shape,
types,
ItemInstance(result, count),
makeRecipeUnlockingKey(unlock)
);
}
);
RemoteCall::exportAs(
@@ -64,14 +61,9 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& input,
std::string const& output,
std::vector<std::string> tags) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(
// recipe_id,
// RecipeIngredient(input, 0, 1),
// RecipeIngredient(output, 0, 1),
// tags
// );
throw std::runtime_error("GMLib_ModAPI::registerFurnaceRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
CustomRecipeRegistry::getInstance()
.registerFurnaceRecipe(ICustomRecipe::Ingredient{input}, ItemInstance{output}, tags);
}
);
RemoteCall::exportAs(
@@ -79,10 +71,12 @@ void Export_Legacy_GMLib_ModAPI() {
"registerBrewingMixRecipe",
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, RecipeIngredient(reagent, 0,
// 1));
throw std::runtime_error("GMLib_ModAPI::registerBrewingMixRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
CustomRecipeRegistry::getInstance().registerBrewingRecipe(
ICustomRecipe::Ingredient{input},
ICustomRecipe::Ingredient{reagent},
ICustomRecipe::Ingredient{output}
);
}
);
RemoteCall::exportAs(
@@ -90,14 +84,12 @@ void Export_Legacy_GMLib_ModAPI() {
"registerBrewingContainerRecipe",
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(
// recipe_id,
// RecipeIngredient(input, 0, 1),
// RecipeIngredient(output, 0, 1),
// RecipeIngredient(reagent, 0, 1)
// );
throw std::runtime_error("GMLib_ModAPI::registerBrewingContainerRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
CustomRecipeRegistry::getInstance().registerBrewingRecipe(
ICustomRecipe::Ingredient{input},
ICustomRecipe::Ingredient{reagent},
ICustomRecipe::Ingredient{output}
);
}
);
RemoteCall::exportAs(
@@ -108,15 +100,14 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& base,
std::string const& addition,
std::string const& result) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
// recipe_id,
// smithing_template,
// base,
// addition,
// result
// );
throw std::runtime_error("GMLib_ModAPI::registerSmithingTransformRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
CustomRecipeRegistry::getInstance().registerSmithingTransformRecipe(
recipe_id,
ICustomRecipe::Ingredient{smithing_template},
ICustomRecipe::Ingredient{base},
ICustomRecipe::Ingredient{addition},
ItemInstance{result}
);
}
);
RemoteCall::exportAs(
@@ -126,9 +117,13 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& smithing_template,
std::string const& base,
std::string const& addition) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
throw std::runtime_error("GMLib_ModAPI::registerSmithingTrimRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
CustomRecipeRegistry::getInstance().registerSmithingTrimRecipe(
recipe_id,
ICustomRecipe::Ingredient{smithing_template},
ICustomRecipe::Ingredient{base},
ICustomRecipe::Ingredient{addition}
);
}
);
RemoteCall::exportAs(
@@ -140,19 +135,17 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& output,
int output_data,
int output_count) -> void {
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(
// recipe_id,
// RecipeIngredient(input, 0, 1),
// RecipeIngredient(output, 0, 1)
// );
throw std::runtime_error("GMLib_ModAPI::registerStoneCutterRecipe is not implemented");
if (!GMLevel::getInstance().has_value()) return;
CustomRecipeRegistry::getInstance().registerStoneCutterRecipe(
recipe_id,
ICustomRecipe::Ingredient{input, 1, input_data},
{output, output_count, output_data}
);
}
);
// 错误方块清理
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
// GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled();
throw std::runtime_error("GMLib_ModAPI::setUnknownBlockCleaner is not implemented");
getLogger().error("setUnknownBlockCleaner is not implemented");
});
// 实验性
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
@@ -172,8 +165,5 @@ void Export_Legacy_GMLib_ModAPI() {
.transform([&](GMLevel& level) { return level.getExperimentEnabled((AllExperiments)experiment_id); })
.value_or(false);
});
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
// GMLIB::Mod::VanillaFix::setFixI18nEnabled();
throw std::runtime_error("GMLib_ModAPI::setFixI18nEnabled is not implemented");
});
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {});
}
+6 -12
View File
@@ -2,24 +2,19 @@
void Export_Legacy_GMLib_ServerAPI() {
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
// GMLIB_Level::tryEnableEducationEdition();
throw std::runtime_error("GMLib_ServerAPI::setEducationFeatureEnabled is not implemented");
getLogger().error("GMLib_ServerAPI::setEducationFeatureEnabled is not implemented");
});
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
// GMLIB_Level::tryRegisterAbilityCommand();
throw std::runtime_error("GMLib_ServerAPI::registerAbilityCommand is not implemented");
getLogger().error("GMLib_ServerAPI::registerAbilityCommand is not implemented");
});
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
// GMLIB_Level::setForceAchievementsEnabled();
throw std::runtime_error("GMLib_ServerAPI::setEnableAchievement is not implemented");
getLogger().error("GMLib_ServerAPI::setEnableAchievement is not implemented");
});
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void {
// GMLIB_Level::trustAllSkins();
throw std::runtime_error("GMLib_ServerAPI::setForceTrustSkins is not implemented");
getLogger().error("GMLib_ServerAPI::setForceTrustSkins is not implemented");
});
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
// GMLIB_Level::requireServerResourcePackAndAllowClientResourcePack();
throw std::runtime_error("GMLib_ServerAPI::enableCoResourcePack is not implemented");
getLogger().error("GMLib_ServerAPI::enableCoResourcePack is not implemented");
});
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
return GMLevel::getInstance().transform(
@@ -37,8 +32,7 @@ void Export_Legacy_GMLib_ServerAPI() {
.value_or("");
});
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
// return GMLIB_Level::setFakeSeed(seed);
throw std::runtime_error("GMLib_ServerAPI::setFakeSeed is not implemented");
getLogger().error("GMLib_ServerAPI::setFakeSeed is not implemented");
});
RemoteCall::exportAs(
"GMLib_ServerAPI",