2024-06-24 2:13

- 添加jsdoc注释和d.ts补全文件
- 修改getBlockRuntimeId接口,使其支持填写特殊值
- 添加getBlockLightEmission,getGameRules,applyEnchant,removeEnchants,hasEnchant,getEnchantLevel,getEnchantNameAndLevel接口
- 导出事件onEntityChangeDimAfter,DragonRespawn,ProjectileTryCreate,ProjectileCreate
This commit is contained in:
子沐呀
2024-06-24 02:13:25 +08:00
Unverified
parent f5947784bf
commit ea9934f315
8 changed files with 3024 additions and 293 deletions
+68 -3
View File
@@ -599,8 +599,8 @@ void Export_Compatibility_API() {
return result;
}
);
RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName) -> uint {
if (auto block = Block::tryGetFromRegistry(blockName)) {
RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName, short legacyData) -> uint {
if (auto block = Block::tryGetFromRegistry(blockName, legacyData)) {
return block->getRuntimeId();
}
return 0;
@@ -648,7 +648,10 @@ void Export_Compatibility_API() {
return item->canDestroy(block);
});
RemoteCall::exportAs("GMLIB_API", "itemCanDestroyInCreative", [](ItemStack const* item) -> bool {
return item->getItem()->canDestroyInCreative();
if (auto itemDef = item->getItem()) {
return itemDef->canDestroyInCreative();
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "itemCanDestroySpecial", [](ItemStack const* item, Block const* block) -> bool {
return item->canDestroySpecial(*block);
@@ -678,4 +681,66 @@ void Export_Compatibility_API() {
}
return "tile.unknown.name";
});
RemoteCall::exportAs(
"GMLIB_API",
"getBlockLightEmission",
[](std::string const& blockName, short legacyData) -> char {
if (auto block = Block::tryGetFromRegistry(blockName, legacyData)) {
return (char)block->getLightEmission().value;
}
return -1;
}
);
RemoteCall::exportAs(
"GMLIB_API",
"getGameRules",
[]() -> std::vector<std::unordered_map<std::string, std::string>> {
auto gameRules = ll::service::getLevel()->getGameRules().getRules();
std::vector<std::unordered_map<std::string, std::string>> result;
for (auto& gameRule : gameRules) {
std::unordered_map<std::string, std::string> data;
data["Name"] = gameRule.getName();
switch (gameRule.getType()) {
case GameRule::Type::Bool:
data["Type"] = "Bool";
data["Value"] = std::to_string(gameRule.getBool());
break;
case GameRule::Type::Float:
data["Type"] = "Float";
data["Value"] = std::to_string(gameRule.getFloat());
break;
case GameRule::Type::Int:
data["Type"] = "Int";
data["Value"] = std::to_string(gameRule.getInt());
break;
case GameRule::Type::Invalid:
break;
}
result.push_back(data);
}
return result;
}
);
RemoteCall::exportAs("GMLIB_API", "getLegalEnchants", [](ItemStack const* item) -> std::vector<int> {
return EnchantUtils::getLegalEnchants(item->getItem());
});
RemoteCall::exportAs(
"GMLIB_API",
"applyEnchant",
[](ItemStack const* item, int id, int level, bool allowNonVanilla) -> bool {
return EnchantUtils::applyEnchant((ItemStackBase&)*item, (Enchant::Type)id, level, allowNonVanilla);
}
);
RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack const* item) -> void {
EnchantUtils::removeEnchants((ItemStack&)*item);
});
RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack const* item, int id) -> bool {
return EnchantUtils::hasEnchant((Enchant::Type)id, (ItemStackBase&)*item);
});
RemoteCall::exportAs("GMLIB_API", "getEnchantLevel", [](ItemStack const* item, int id) -> int {
return EnchantUtils::getEnchantLevel((Enchant::Type)id, (ItemStackBase&)*item);
});
RemoteCall::exportAs("GMLIB_API", "getEnchantNameAndLevel", [](int id, int level) -> std::string {
return EnchantUtils::getEnchantNameAndLevel((Enchant::Type)id, level);
});
}