修复问题

This commit is contained in:
子沐呀
2024-07-19 00:17:48 +08:00
Unverified
parent 55424a447b
commit c544569bd8
6 changed files with 67 additions and 52 deletions
+7 -2
View File
@@ -4,7 +4,9 @@ declare class PAPI {
/** PAPI调用函数 */ /** PAPI调用函数 */
func: ( func: (
/** 玩家对象 */ /** 玩家对象 */
player: Player player: Player,
/** 变量参数 */
param: null | object.<string, string>
) => string, ) => string,
/** 插件名字 */ /** 插件名字 */
pluginsName: string, pluginsName: string,
@@ -15,7 +17,10 @@ declare class PAPI {
/** 注册一个服务器PAPI变量 */ /** 注册一个服务器PAPI变量 */
static registerServerPlaceholder( static registerServerPlaceholder(
/** PAPI调用函数 */ /** PAPI调用函数 */
func: () => string, func: (
/** 变量参数 */
param: null | object.<string, string>
) => string,
/** 插件名字 */ /** 插件名字 */
pluginsName: string, pluginsName: string,
/** PAPI变量 */ /** PAPI变量 */
+12 -7
View File
@@ -25,19 +25,24 @@ Function.prototype.getName =
* @returns {string} * @returns {string}
*/ */
function () { function () {
return this.name || this.toString().match(/function\s*([^(]*)\(/)?.[1] || this.toString().hashCode().toString(16); return this.name || this.toString().match(/function\s*([^(]*)\(/)?.[1] || getStringHashCode(this.toString()).toString(16);
} }
String.prototype.hashCode = function () { /**
var hash = 0, i, chr; * 获取字符串哈希值
if (this.length === 0) return hash; * @param {string} str 字符串
for (i = 0; i < this.length; i++) { * @returns {number}
chr = this.charCodeAt(i); */
function getStringHashCode(str) {
let hash = 0, chr;
if (str.length === 0) return hash;
for (let i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr; hash = ((hash << 5) - hash) + chr;
hash |= 0; hash |= 0;
} }
return hash; return hash;
}; }
/** PAPI变量类 */ /** PAPI变量类 */
class PAPI { class PAPI {
+1 -1
View File
@@ -63,7 +63,7 @@ declare class Event {
/** 掉落物生成完毕(不可以拦截) */ /** 掉落物生成完毕(不可以拦截) */
static listen( static listen(
/** 事件名 */ /** 事件名 */
event: "onItemTrySpawn", event: "onItemSpawned",
/** 回调函数 */ /** 回调函数 */
listener: ( listener: (
/** 物品对象 */ /** 物品对象 */
+19 -19
View File
@@ -219,7 +219,7 @@ declare class Minecraft {
static spawnEntity( static spawnEntity(
/** 生成坐标 */ /** 生成坐标 */
pos: FloatPos, pos: FloatPos,
/** 实体命名空间 */ /** 实体命名空间ID */
name: string name: string
): Entity; ): Entity;
@@ -227,7 +227,7 @@ declare class Minecraft {
static shootProjectile( static shootProjectile(
/** 实体对象 */ /** 实体对象 */
entity: Entity, entity: Entity,
/** 投射物命名空间 */ /** 投射物命名空间ID */
proj: string, proj: string,
/** 速度 */ /** 速度 */
speed: number, speed: number,
@@ -286,7 +286,7 @@ declare class Minecraft {
/** 获取方块runtimeId */ /** 获取方块runtimeId */
static getBlockRuntimeId( static getBlockRuntimeId(
/** 方块命名空间 */ /** 方块命名空间ID */
block: string, block: string,
/** 方块的特殊值 */ /** 方块的特殊值 */
legacyData: Number | undefined legacyData: Number | undefined
@@ -330,18 +330,18 @@ declare class Minecraft {
isBinary: boolean | undefined isBinary: boolean | undefined
): NbtCompound; ): NbtCompound;
/** 根据命名空间获取翻译键名 */ /** 根据命名空间ID获取翻译键名 */
static getBlockTranslateKeyFromName( static getBlockTranslateKeyFromName(
/** 方块命名空间 */ /** 方块命名空间ID */
name: string name: string
): string; ): string;
/** 获取存档种子 */ /** 获取存档种子 */
static getLevelSeed(): string; static getLevelSeed(): string;
/** 获取方块亮度 */ /** 获取方块亮度 */
static getBlockLightEmission( static getBlockLightEmission(
/** 方块的命名空间 */ /** 方块的命名空间ID */
block: string, block: string,
/** 方块的特殊值 */ /** 方块的特殊值 */
legacyData: number legacyData: number
@@ -352,13 +352,13 @@ declare class Minecraft {
/** 获取附魔名字和等级 */ /** 获取附魔名字和等级 */
static getEnchantNameAndLevel( static getEnchantNameAndLevel(
/** 附魔命名空间 */ /** 附魔命名空间ID */
typeName: string, typeName: string,
/** 附魔的等级 */ /** 附魔的等级 */
level: number level: number
): string; ): string;
/** 通过附魔ID获取附魔命名空间 */ /** 通过附魔ID获取附魔命名空间ID */
static getMaxPlayers( static getMaxPlayers(
/** 附魔ID */ /** 附魔ID */
id: number id: number
@@ -468,7 +468,7 @@ declare class Recipes {
result: string, result: string,
/** 合成结果的数量 */ /** 合成结果的数量 */
count: number | undefined, count: number | undefined,
/** 解锁条件(也可以填物品命名空间) */ /** 解锁条件(也可以填物品命名空间ID) */
unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined
): boolean; ): boolean;
@@ -482,7 +482,7 @@ declare class Recipes {
result: string, result: string,
/** 合成结果的数量 */ /** 合成结果的数量 */
count: number | undefined, count: number | undefined,
/** 解锁条件(也可以填物品命名空间) */ /** 解锁条件(也可以填物品命名空间ID) */
unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined
): boolean; ): boolean;
} }
@@ -760,15 +760,15 @@ declare class JsonConfig {
): void; ): void;
/** 获取所有数据 */ /** 获取所有数据 */
getData(): object; getData(): Record<string,any>;
/** 读取数据 */ /** 读取数据 */
get( get<T>(
/** 键名 */ /** 键名 */
key: string, key: string,
/** 不存在返回值 */ /** 不存在返回值 */
defaultValue: any defaultValue: T
): any; ): T;
/** 设置数据 */ /** 设置数据 */
set( set(
@@ -1039,7 +1039,7 @@ interface Player {
interface Entity { interface Entity {
/** (GMLIB)射弹投射物 */ /** (GMLIB)射弹投射物 */
shootProjectile( shootProjectile(
/** 投射物命名空间 */ /** 投射物命名空间ID */
proj: string, proj: string,
/** 速度 */ /** 速度 */
speed: number | undefined, speed: number | undefined,
@@ -1156,7 +1156,7 @@ interface Item {
/** (GMLIB)添加附魔 */ /** (GMLIB)添加附魔 */
applyEnchant( applyEnchant(
/** 附魔的命名空间 */ /** 附魔的命名空间ID */
typeName: string, typeName: string,
/** 附魔等级 */ /** 附魔等级 */
level: number, level: number,
@@ -1169,13 +1169,13 @@ interface Item {
/** (GMLIB)判断是否拥有附魔 */ /** (GMLIB)判断是否拥有附魔 */
hasEnchant( hasEnchant(
/** 附魔的命名空间 */ /** 附魔的命名空间ID */
typeName: string typeName: string
): boolean; ): boolean;
/** (GMLIB)获取附魔等级 */ /** (GMLIB)获取附魔等级 */
getEnchantLevel( getEnchantLevel(
/** 附魔的命名空间 */ /** 附魔的命名空间ID */
typeName: string typeName: string
): number; ): number;
+18 -18
View File
@@ -258,7 +258,7 @@ const GMLIB_API = {
playerPullInEntity: ll.import("GMLIB_API", "playerPullInEntity"), playerPullInEntity: ll.import("GMLIB_API", "playerPullInEntity"),
/** 根据命令空间获取翻译键名 @type {function(string):string} */ /** 根据命令空间获取翻译键名 @type {function(string):string} */
getBlockTranslateKeyFromName: ll.import("GMLIB_API", "getBlockTranslateKeyFromName"), getBlockTranslateKeyFromName: ll.import("GMLIB_API", "getBlockTranslateKeyFromName"),
/** 获取存档种子 @type {function():string} */ /** 获取存档种子 @type {function():string} */
getLevelSeed: ll.import("GMLib_ServerAPI", "getLevelSeed"), getLevelSeed: ll.import("GMLib_ServerAPI", "getLevelSeed"),
/** 获取方块亮度 @type {function(string,number):number} */ /** 获取方块亮度 @type {function(string,number):number} */
getBlockLightEmission: ll.import("GMLIB_API", "getBlockLightEmission"), getBlockLightEmission: ll.import("GMLIB_API", "getBlockLightEmission"),
@@ -276,7 +276,7 @@ const GMLIB_API = {
getEnchantLevel: ll.import("GMLIB_API", "getEnchantLevel"), getEnchantLevel: ll.import("GMLIB_API", "getEnchantLevel"),
/** 获取附魔名字 @type {function(string,number):number} */ /** 获取附魔名字 @type {function(string,number):number} */
getEnchantNameAndLevel: ll.import("GMLIB_API", "getEnchantNameAndLevel"), getEnchantNameAndLevel: ll.import("GMLIB_API", "getEnchantNameAndLevel"),
/** 通过ID获取附魔命名空间 @type {function(number):string} */ /** 通过ID获取附魔命名空间ID @type {function(number):string} */
getEnchantTypeNameFromId: ll.import("GMLIB_API", "getEnchantTypeNameFromId"), getEnchantTypeNameFromId: ll.import("GMLIB_API", "getEnchantTypeNameFromId"),
/** 获取最大玩家数 @type {function():number} */ /** 获取最大玩家数 @type {function():number} */
getMaxPlayers: ll.import("GMLib_ServerAPI", "getMaxPlayers"), getMaxPlayers: ll.import("GMLib_ServerAPI", "getMaxPlayers"),
@@ -765,7 +765,7 @@ class Minecraft {
/** /**
* 强制生成实体 * 强制生成实体
* @param {FloatPos} pos 要生成的坐标 * @param {FloatPos} pos 要生成的坐标
* @param {string} name 实体命名空间 * @param {string} name 实体命名空间ID
* @returns {boolean} 是否成功生成实体 * @returns {boolean} 是否成功生成实体
*/ */
static spawnEntity(pos, name) { static spawnEntity(pos, name) {
@@ -775,7 +775,7 @@ class Minecraft {
/** /**
* 射弹投射物 * 射弹投射物
* @param {Entity} entity 实体对象 * @param {Entity} entity 实体对象
* @param {string} proj 投射物命名空间 * @param {string} proj 投射物命名空间ID
* @param {number} [speed=2] 速度 * @param {number} [speed=2] 速度
* @param {number} [offset=3] 偏移量 * @param {number} [offset=3] 偏移量
* @returns {boolean} 是否成功投射投射物 * @returns {boolean} 是否成功投射投射物
@@ -861,7 +861,7 @@ class Minecraft {
/** /**
* 获取方块runtimeId * 获取方块runtimeId
* @param {string} block 方块命名空间 * @param {string} block 方块命名空间ID
* @param {number} [legacyData=0] 方块的特殊值 * @param {number} [legacyData=0] 方块的特殊值
* @returns {number} 方块的runtimeId * @returns {number} 方块的runtimeId
*/ */
@@ -925,8 +925,8 @@ class Minecraft {
} }
/** /**
* 根据命名空间获取翻译键名 * 根据命名空间ID获取翻译键名
* @param {string} name 方块的命名空间 * @param {string} name 方块的命名空间ID
* @returns {string} 方块的翻译键名 * @returns {string} 方块的翻译键名
*/ */
static getBlockTranslateKeyFromName(name) { static getBlockTranslateKeyFromName(name) {
@@ -934,7 +934,7 @@ class Minecraft {
} }
/** /**
* 获取存档种子 * 获取存档种子
*/ */
static getLevelSeed() { static getLevelSeed() {
return GMLIB_API.getLevelSeed(); return GMLIB_API.getLevelSeed();
@@ -942,7 +942,7 @@ class Minecraft {
/** /**
* 获取方块亮度 * 获取方块亮度
* @param {string} block 方块的命名空间 * @param {string} block 方块的命名空间ID
* @param {number} [legacyData=0] 方块的特殊值 * @param {number} [legacyData=0] 方块的特殊值
* @returns {number} 方块的亮度(-1为不存在) * @returns {number} 方块的亮度(-1为不存在)
*/ */
@@ -975,7 +975,7 @@ class Minecraft {
/** /**
* 获取附魔名字和等级 * 获取附魔名字和等级
* @param {string} typeName 附魔的命名空间 * @param {string} typeName 附魔的命名空间ID
* @param {number} level 附魔等级 * @param {number} level 附魔等级
* @returns {string} 文本 * @returns {string} 文本
*/ */
@@ -984,9 +984,9 @@ class Minecraft {
} }
/** /**
* 通过附魔ID获取附魔命名空间 * 通过附魔ID获取附魔命名空间ID
* @param {number} id 附魔ID * @param {number} id 附魔ID
* @returns {string?} 附魔的命名空间 * @returns {string?} 附魔的命名空间ID
*/ */
static getEnchantTypeNameFromId(id) { static getEnchantTypeNameFromId(id) {
const result = GMLIB_API.getEnchantTypeNameFromId(id); const result = GMLIB_API.getEnchantTypeNameFromId(id);
@@ -1085,7 +1085,7 @@ class Recipes {
* @param {string} recipeId 合成表唯一标识 * @param {string} recipeId 合成表唯一标识
* @param {string} input 输入材料 * @param {string} input 输入材料
* @param {string} output 合成结果 * @param {string} output 合成结果
* @param {Array.<"furnace"|"blast_furnace"|"smoker"|"campfire"|"soul_campfire">} [tags=["furnace"]] 材料的标签数组 * @param {Array.<string>} [tags=["furnace"]] 材料的标签数组
* @returns {boolean} 是否注册成功 * @returns {boolean} 是否注册成功
*/ */
static registerFurnaceRecipe(recipeId, input, output, tags = ["furnace"]) { static registerFurnaceRecipe(recipeId, input, output, tags = ["furnace"]) {
@@ -1099,7 +1099,7 @@ class Recipes {
* @param {Array.<string>} ingredients 材料数组 * @param {Array.<string>} ingredients 材料数组
* @param {string} result 合成结果 * @param {string} result 合成结果
* @param {string} [count=1] 合成结果的数量 * @param {string} [count=1] 合成结果的数量
* @param {"AlwaysUnlocked"|"PlayerHasManyItems"|"PlayerInWater"|"None"} [unlock=AlwaysUnlocked] 解锁条件(也可以填物品命名空间) * @param {string} [unlock=AlwaysUnlocked] 解锁条件(也可以填物品命名空间ID)
* @returns {boolean} 是否注册成功 * @returns {boolean} 是否注册成功
*/ */
static registerShapedRecipe(recipeId, shape, ingredients, result, count = 1, unlock = "AlwaysUnlocked") { static registerShapedRecipe(recipeId, shape, ingredients, result, count = 1, unlock = "AlwaysUnlocked") {
@@ -1112,7 +1112,7 @@ class Recipes {
* @param {Array.<string>} ingredients 合成材料 * @param {Array.<string>} ingredients 合成材料
* @param {string} result 合成结果 * @param {string} result 合成结果
* @param {number} [count=1] 合成数量 * @param {number} [count=1] 合成数量
* @param {"AlwaysUnlocked"|"PlayerHasManyItems"|"PlayerInWater"|"None"} [unlock=AlwaysUnlocked] 解锁条件(也可以填物品命名空间) * @param {string} [unlock=AlwaysUnlocked] 解锁条件(也可以填物品命名空间ID)
* @returns {boolean} 是否注册成功 * @returns {boolean} 是否注册成功
*/ */
static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") { static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") {
@@ -1975,7 +1975,7 @@ LLSE_Player.prototype.clearSpawnPoint =
LLSE_Entity.prototype.shootProjectile = LLSE_Entity.prototype.shootProjectile =
/** /**
* 射弹投射物 * 射弹投射物
* @param {string} proj 投射物命名空间 * @param {string} proj 投射物命名空间ID
* @param {number} [speed=2] 速度 * @param {number} [speed=2] 速度
* @param {number} [offset=3] 偏移量 * @param {number} [offset=3] 偏移量
* @returns {boolean} 是射弹投射物 * @returns {boolean} 是射弹投射物
@@ -2170,7 +2170,7 @@ LLSE_Item.prototype.getLegalEnchants =
LLSE_Item.prototype.applyEnchant = LLSE_Item.prototype.applyEnchant =
/** /**
* 添加附魔 * 添加附魔
* @param {string} typeName 附魔的命名空间 * @param {string} typeName 附魔的命名空间ID
* @param {number} level 等级 * @param {number} level 等级
* @param {boolean} allowNonVanilla 允许非原版附魔 * @param {boolean} allowNonVanilla 允许非原版附魔
* @returns {boolean} 是否附魔成功 * @returns {boolean} 是否附魔成功
@@ -2190,7 +2190,7 @@ LLSE_Item.prototype.removeEnchants =
LLSE_Item.prototype.hasEnchant = LLSE_Item.prototype.hasEnchant =
/** /**
* 判断是否拥有附魔 * 判断是否拥有附魔
* @param {number} typeName 附魔的命名空间 * @param {number} typeName 附魔的命名空间ID
* @returns {boolean} 是否拥有附魔 * @returns {boolean} 是否拥有附魔
*/ */
function (typeName) { function (typeName) {
+10 -5
View File
@@ -740,7 +740,7 @@ void Export_Compatibility_API() {
"applyEnchant", "applyEnchant",
[](ItemStack const* item, std::string const& typeName, int level, bool allowNonVanilla) -> bool { [](ItemStack const* item, std::string const& typeName, int level, bool allowNonVanilla) -> bool {
return EnchantUtils::applyEnchant( return EnchantUtils::applyEnchant(
(ItemStackBase&)*item, *(const_cast<ItemStack*>(item)),
Enchant::getEnchantTypeFromName(HashedString(typeName)), Enchant::getEnchantTypeFromName(HashedString(typeName)),
level, level,
allowNonVanilla allowNonVanilla
@@ -751,12 +751,15 @@ void Export_Compatibility_API() {
EnchantUtils::removeEnchants((ItemStack&)*item); EnchantUtils::removeEnchants((ItemStack&)*item);
}); });
RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack const* item, std::string const& typeName) -> bool { RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack const* item, std::string const& typeName) -> bool {
return EnchantUtils::hasEnchant(Enchant::getEnchantTypeFromName(HashedString(typeName)), (ItemStackBase&)*item); return EnchantUtils::hasEnchant(
Enchant::getEnchantTypeFromName(HashedString(typeName)),
*(const_cast<ItemStack*>(item))
);
}); });
RemoteCall::exportAs("GMLIB_API", "getEnchantLevel", [](ItemStack const* item, std::string const& typeName) -> int { RemoteCall::exportAs("GMLIB_API", "getEnchantLevel", [](ItemStack const* item, std::string const& typeName) -> int {
return EnchantUtils::getEnchantLevel( return EnchantUtils::getEnchantLevel(
Enchant::getEnchantTypeFromName(HashedString(typeName)), Enchant::getEnchantTypeFromName(HashedString(typeName)),
(ItemStackBase&)*item *(const_cast<ItemStack*>(item))
); );
}); });
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -802,7 +805,7 @@ void Export_Compatibility_API() {
return item->getBaseRepairCost(); return item->getBaseRepairCost();
}); });
RemoteCall::exportAs("GMLIB_API", "setItemRepairCost", [](ItemStack const* item, int cost) -> void { RemoteCall::exportAs("GMLIB_API", "setItemRepairCost", [](ItemStack const* item, int cost) -> void {
((ItemStackBase*)item)->setRepairCost(cost); (*(const_cast<ItemStack*>(item))).setRepairCost(cost);
}); });
RemoteCall::exportAs("GMLIB_API", "getItemCanDestroy", [](ItemStack const* item) -> std::vector<std::string> { RemoteCall::exportAs("GMLIB_API", "getItemCanDestroy", [](ItemStack const* item) -> std::vector<std::string> {
std::vector<std::string> result = {}; std::vector<std::string> result = {};
@@ -841,5 +844,7 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](Player* player) -> int { RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](Player* player) -> int {
return player->getArmorValue(); return player->getArmorValue();
}); });
RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](Actor* entity) -> int64 { return entity->getOwnerId().id; }); RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](Actor* entity) -> int64 {
return entity->getOwnerId().id;
});
} }