修复问题

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