diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts
index 443b3af..1109e5f 100644
--- a/lib/GMLIB_API-JS.d.ts
+++ b/lib/GMLIB_API-JS.d.ts
@@ -372,6 +372,24 @@ declare class Minecraft {
/** 玩家的uuid */
uuid: string
): 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
): 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 {
diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js
index 944c9ba..8e6cb3a 100644
--- a/lib/GMLIB_API-JS.js
+++ b/lib/GMLIB_API-JS.js
@@ -1,3 +1,5 @@
+///
+
/** LRCA导出接口 */
const GMLIB_API = {
/** 创建悬浮字 @type {function(FloatPos,string,boolean):number} */
@@ -343,7 +345,31 @@ const GMLIB_API = {
/** 实体包含在某族里 @type {function(Entity,string):boolean} */
entityHasFamily: ll.import("GMLIB_API", "entityHasFamily"),
/** 获取玩家破坏方块所需时间 @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} */
@@ -1033,6 +1059,37 @@ class Minecraft {
static 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);
}
+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 = {
StaticFloatingText,
DynamicFloatingText,
diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp
index 21b47c2..9575c83 100644
--- a/src/CompatibilityApi.cpp
+++ b/src/CompatibilityApi.cpp
@@ -1,6 +1,8 @@
#include "Global.h"
+#include "ll/api/service/Bedrock.h"
#include "magic_enum.hpp"
#include "mc/deps/core/string/HashedString.h"
+#include "mc/world/effect/MobEffect.h"
#include
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 {
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);
+ }
+ });
}
\ No newline at end of file