添加12个接口

- getPlayerEffectVisible
- getPlayerEffectDuration
- getPlayerEffectDurationEasy
- getPlayerEffectDurationHard
- getPlayerEffectDurationNormal
- getPlayerEffectAmplifier
- getPlayerEffectAmbient
- playerHasEffect
- getGameDifficulty
- setGameDifficulty
- getDefaultGameMode
- setDefaultGameMode
This commit is contained in:
子沐呀
2024-08-01 20:22:21 +08:00
Unverified
parent b72c4564bc
commit ae34d79b56
3 changed files with 233 additions and 1 deletions
+67
View File
@@ -372,6 +372,24 @@ declare class Minecraft {
/** 玩家的uuid */ /** 玩家的uuid */
uuid: string uuid: string
): boolean; ): boolean;
/** 获取游戏难度 */
static getGameDifficulty(): -1 | 0 | 1 | 2 | 3;
/** 设置游戏难度 */
static setGameDifficulty(
/** 游戏难度 */
difficulty: 0 | 1 | 2 | 3
): void;
/** 获取默认游戏模式 */
static getDefaultGameMode(): -1 | 0 | 1 | 2 | 5 | 6;
/** 设置默认游戏模式 */
static setDefaultGameMode(
/** 游戏模式 */
gameMode: 0 | 1 | 2 | 5 | 6
): void;
} }
/** 合成表类 */ /** 合成表类 */
@@ -1079,6 +1097,55 @@ interface Player {
/** 方块对象 */ /** 方块对象 */
block: Block block: Block
): number; ): number;
/** (GMLIB)玩家是否拥有buff效果 */
hasEffect(
/** 效果ID */
effectId: number
): boolean;
/** (GMLIB)获取buff信息 */
getEffectInfo(
/** 效果ID */
effectId: number
): {
/** 效果ID */
Id: number,
/** 效果等级 */
Amplifier: number,
/** 持续时间 */
Duration: number,
/** 简单难度下的持续时间 */
DurationEasy: number,
/** 普通难度下的持续时间 */
DurationNormal: number,
/** 困难难度下的持续时间 */
DurationHard: number,
/** 是否为信标给予 */
Ambient: boolean,
/** 是否显示粒子效果 */
ShowParticles: boolean
} | null;
/** (GMLIB)获取所有buff信息 */
getAllEffectsInfo(): {
/** 效果ID */
Id: number,
/** 效果等级 */
Amplifier: number,
/** 持续时间 */
Duration: number,
/** 简单难度下的持续时间 */
DurationEasy: number,
/** 普通难度下的持续时间 */
DurationNormal: number,
/** 困难难度下的持续时间 */
DurationHard: number,
/** 是否为信标给予 */
Ambient: boolean,
/** 是否显示粒子效果 */
ShowParticles: boolean
}[];
} }
interface Entity { interface Entity {
+97 -1
View File
@@ -1,3 +1,5 @@
/// <reference path='d:/dts/dts/helperlib/src/index.d.ts'/>
/** LRCA导出接口 */ /** LRCA导出接口 */
const GMLIB_API = { const GMLIB_API = {
/** 创建悬浮字 @type {function(FloatPos,string,boolean):number} */ /** 创建悬浮字 @type {function(FloatPos,string,boolean):number} */
@@ -343,7 +345,31 @@ const GMLIB_API = {
/** 实体包含在某族里 @type {function(Entity,string):boolean} */ /** 实体包含在某族里 @type {function(Entity,string):boolean} */
entityHasFamily: ll.import("GMLIB_API", "entityHasFamily"), entityHasFamily: ll.import("GMLIB_API", "entityHasFamily"),
/** 获取玩家破坏方块所需时间 @type {function(Player,Block):number} */ /** 获取玩家破坏方块所需时间 @type {function(Player,Block):number} */
getPlayerDestroyBlockProgress: ll.import("GMLIB_API", "getPlayerDestroyBlockProgress") getPlayerDestroyBlockProgress: ll.import("GMLIB_API", "getPlayerDestroyBlockProgress"),
/** 获取玩家的buff是否显示 @type {function(Player,number):boolean} */
getPlayerEffectVisible: ll.import("GMLIB_API", "getPlayerEffectVisible"),
/** 获取玩家的buff持续时间 @type {function(Player,number):number} */
getPlayerEffectDuration: ll.import("GMLIB_API", "getPlayerEffectDuration"),
/** 获取玩家的buff简单模式下的持续时间 @type {function(Player,number):number} */
getPlayerEffectDurationEasy: ll.import("GMLIB_API", "getPlayerEffectDuration"),
/** 获取玩家的buff困难模式下的持续时间 @type {function(Player,number):number} */
getPlayerEffectDurationHard: ll.import("GMLIB_API", "getPlayerEffectDurationHard"),
/** 获取玩家的buff普通模式下的持续时间 @type {function(Player,number):number} */
getPlayerEffectDurationNormal: ll.import("GMLIB_API", "getPlayerEffectDurationNormal"),
/** 获取玩家的buff效果等级 @type {function(Player,number):number} */
getPlayerEffectAmplifier: ll.import("GMLIB_API", "getPlayerEffectAmplifier"),
/** 获取玩家的buff是否为信标给予 @type {function(Player,number):boolean} */
getPlayerEffectAmbient: ll.import("GMLIB_API", "getPlayerEffectAmbient"),
/** 玩家是否拥有buff效果 @type {function(Player,number):boolean} */
playerHasEffect: ll.import("GMLIB_API", "playerHasEffect"),
/** 获取游戏难度 @type {function():number} */
getGameDifficulty: ll.import("GMLIB_API", "getGameDifficulty"),
/** 设置游戏难度 @type {function(difficulty):void} */
setGameDifficulty: ll.import("GMLIB_API", "setGameDifficulty"),
/** 获取默认游戏模式 @type {function():number} */
getDefaultGameMode: ll.import("GMLIB_API", "getDefaultGameMode"),
/** 设置默认游戏模式 @type {function(mode):void} */
setDefaultGameMode: ll.import("GMLIB_API", "setDefaultGameMode"),
} }
/** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */ /** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */
@@ -1033,6 +1059,37 @@ class Minecraft {
static hasPlayerNbt(uuid) { static hasPlayerNbt(uuid) {
return GMLIB_API.hasPlayerNbt(uuid); return GMLIB_API.hasPlayerNbt(uuid);
} }
/**
* 获取游戏难度
* @returns {-1|0|1|2|3} 游戏难度
*/
static getGameDifficulty() {
return GMLIB_API.getGameDifficulty();
}
/**
* 设置游戏难度
* @param {0|1|2|3} difficulty 游戏难度
*/
static setGameDifficulty(difficulty) {
GMLIB_API.setGameDifficulty(difficulty);
}
/**
* 获取默认游戏模式
* @returns {-1|0|1|2|5|6} 游戏模式
*/
static getDefaultGameMode() {
return GMLIB_API.getDefaultGameMode();
}
/**
* 设置默认游戏模式
* @param {0|1|2|3} gameMode 游戏模式
*/
static setDefaultGameMode(gameMode) {
GMLIB_API.setDefaultGameMode(gameMode);
}
} }
/** 合成表类 */ /** 合成表类 */
@@ -2528,6 +2585,45 @@ LLSE_Player.prototype.getDestroyProgress =
return GMLIB_API.getPlayerDestroyBlockProgress(this, block); return GMLIB_API.getPlayerDestroyBlockProgress(this, block);
} }
LLSE_Player.prototype.hasEffect =
/**
* 玩家是否拥有buff效果
* @param {number} effectId buff效果ID
* @returns {boolean}
*/
function (effectId) {
return GMLIB_API.playerHasEffect(this, effectId);
}
LLSE_Player.prototype.getEffectInfo =
/**
* 获取buff信息
* @param {number} effectId buff效果ID
* @returns {{Id: number, Amplifier: number, Duration: number, DurationEasy: number, DurationNormal: number, DurationHard: number, Ambient: boolean, ShowParticles: boolean} | null}
*/
function (effectId) {
if (!this.hasEffect(effectId)) return null;
return {
Id: id,
Amplifier: GMLIB_API.getPlayerEffectAmbient(this, effectId),
Duration: GMLIB_API.getPlayerEffectDuration(this, effectId),
DurationEasy: GMLIB_API.getPlayerEffectDurationEasy(this, effectId),
DurationNormal: GMLIB_API.getPlayerEffectDurationNormal(this, effectId),
DurationHard: GMLIB_API.getPlayerEffectDurationHard(this, effectId),
Ambient: GMLIB_API.getPlayerEffectAmbient(this, effectId),
ShowParticles: GMLIB_API.getPlayerEffectAmbient(this, effectId),
}
}
LLSE_Player.prototype.getAllEffectsInfo =
/**
* 获取所有buff信息
* @returns {{Id: number, Amplifier: number, Duration: number, DurationEasy: number, DurationNormal: number, DurationHard: number, Ambient: boolean, ShowParticles: boolean}[]}
*/
function () {
this.getAllEffects().map(this.getEffectInfo);
}
module.exports = { module.exports = {
StaticFloatingText, StaticFloatingText,
DynamicFloatingText, DynamicFloatingText,
+69
View File
@@ -1,6 +1,8 @@
#include "Global.h" #include "Global.h"
#include "ll/api/service/Bedrock.h"
#include "magic_enum.hpp" #include "magic_enum.hpp"
#include "mc/deps/core/string/HashedString.h" #include "mc/deps/core/string/HashedString.h"
#include "mc/world/effect/MobEffect.h"
#include <regex> #include <regex>
bool isInteger(const std::string& str) { bool isInteger(const std::string& str) {
@@ -892,4 +894,71 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "getPlayerDestroyBlockProgress", [](Player* player, Block const* block) -> float { RemoteCall::exportAs("GMLIB_API", "getPlayerDestroyBlockProgress", [](Player* player, Block const* block) -> float {
return player->getDestroyProgress(*block); return player->getDestroyProgress(*block);
}); });
RemoteCall::exportAs("GMLIB_API", "getPlayerEffectVisible", [](Player* player, int effectId) -> bool {
if (auto effect = player->getEffect(effectId)) {
return effect->mEffectVisible;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerEffectDuration", [](Player* player, int effectId) -> int {
if (auto effect = player->getEffect(effectId)) {
return effect->mDuration;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerEffectDurationEasy", [](Player* player, int effectId) -> int {
if (auto effect = player->getEffect(effectId)) {
return effect->mDurationEasy;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerEffectDurationHard", [](Player* player, int effectId) -> int {
if (auto effect = player->getEffect(effectId)) {
return effect->mDurationHard;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerEffectDurationNormal", [](Player* player, int effectId) -> int {
if (auto effect = player->getEffect(effectId)) {
return effect->mDurationNormal;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerEffectAmplifier", [](Player* player, int effectId) -> int {
if (auto effect = player->getEffect(effectId)) {
return effect->mAmplifier;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerEffectAmbient", [](Player* player, int effectId) -> bool {
if (auto effect = player->getEffect(effectId)) {
return effect->mAmbient;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "playerHasEffect", [](Player* player, int effectId) -> int {
return player->hasEffect(*MobEffect::getById(effectId));
});
RemoteCall::exportAs("GMLIB_API", "getGameDifficulty", []() -> int {
if (auto level = ll::service::getLevel()) {
return (int)level->getDifficulty();
}
return -1;
});
RemoteCall::exportAs("GMLIB_API", "setGameDifficulty", [](int difficulty) -> void {
if (auto level = ll::service::getLevel()) {
level->setDifficulty((Difficulty)difficulty);
}
});
RemoteCall::exportAs("GMLIB_API", "getDefaultGameMode", []() -> int {
if (auto level = ll::service::getLevel()) {
return (int)level->getDefaultGameType();
}
return -1;
});
RemoteCall::exportAs("GMLIB_API", "setDefaultGameMode", [](int gameMode) -> void {
if (auto level = ll::service::getLevel()) {
level->setDefaultGameType((GameType)gameMode);
}
});
} }