diff --git a/lib/EventAPI-JS.d.ts b/lib/EventAPI-JS.d.ts index 6be8885..0bfdb50 100644 --- a/lib/EventAPI-JS.d.ts +++ b/lib/EventAPI-JS.d.ts @@ -160,7 +160,7 @@ declare class Event { /** 末影龙重生事件 */ static listen( /** 事件名 */ - event: "DragonRespawn", + event: "onDragonRespawn", /** 回调函数 */ listener: ( /** 末影龙重生后的UniqueID */ @@ -171,7 +171,7 @@ declare class Event { /** 弹射物实体尝试创建 */ static listen( /** 事件名 */ - event: "ProjectileTryCreate", + event: "onProjectileTryCreate", /** 回调函数 */ listener: ( /** 弹射物实体对象 */ @@ -184,7 +184,7 @@ declare class Event { /** 弹射物实体成功后(不可拦截) */ static listen( /** 事件名 */ - event: "ProjectileCreate", + event: "onProjectileCreate", /** 回调函数 */ listener: ( /** 弹射物实体对象 */ @@ -197,7 +197,7 @@ declare class Event { /** 生成流浪商人 */ static listen( /** 事件名 */ - event: "SpawnWanderingTrader", + event: "onSpawnWanderingTrader", /** 回调函数 */ listener: ( /** 生成的坐标 */ @@ -208,7 +208,7 @@ declare class Event { /** 处理物品请求 */ static listen( /** 事件名 */ - event: "HandleRequestAction", + event: "onHandleRequestAction", /** 回调函数 */ listener: ( /** 请求玩家 */ @@ -231,7 +231,7 @@ declare class Event { /** 发送容器关闭数据包后(不可拦截) */ static listen( /** 事件名 */ - event: "SendContainerClosePacket", + event: "onSendContainerClosePacket", /** 回调函数 */ listener: ( /** 要被关闭的玩家 */ diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts index bcd7168..443b3af 100644 --- a/lib/GMLIB_API-JS.d.ts +++ b/lib/GMLIB_API-JS.d.ts @@ -1073,6 +1073,12 @@ interface Player { /** 物品 */ item: Item ): void; + + /** (GMLIB)获取玩家破坏方块所需时间 */ + getDestroyProgress( + /** 方块对象 */ + block: Block + ): number; } interface Entity { @@ -1123,8 +1129,14 @@ interface Entity { /** (GMLIB)获取实体的命名 */ getNameTag(): string; - /** 获取实体的主人 */ + /** (GMLIB)获取实体的主人 */ getEntityOwner(): Entity | null; + + /** (GMLIB)实体是否包含在某类里 */ + hasFamily( + /** 实体族 */ + family: string + ): boolean; } interface Block { diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index dff4155..944c9ba 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -339,7 +339,11 @@ const GMLIB_API = { /** 玩家是否拥有NBT @type {function(string):boolean} */ hasPlayerNbt: ll.import("GMLIB_API", "hasPlayerNbt"), /** 获取物品最大堆叠数量 @type {function(Item):number} */ - getItemMaxCount: ll.import("GMLIB_API", "getItemMaxCount") + getItemMaxCount: ll.import("GMLIB_API", "getItemMaxCount"), + /** 实体包含在某族里 @type {function(Entity,string):boolean} */ + entityHasFamily: ll.import("GMLIB_API", "entityHasFamily"), + /** 获取玩家破坏方块所需时间 @type {function(Player,Block):number} */ + getPlayerDestroyBlockProgress: ll.import("GMLIB_API", "getPlayerDestroyBlockProgress") } /** 静态悬浮字类列表 @type {Map} */ @@ -2504,6 +2508,26 @@ LLSE_Item.prototype.getMaxCount = return GMLIB_API.getItemMaxCount(this); } +LLSE_Entity.prototype.hasFamily = + /** + * 实体是否拥包含在某族里 + * @param {string} family 实体族 + * @returns {boolean} + */ + function (family) { + return GMLIB_API.entityHasFamily(this, family); + } + +LLSE_Player.prototype.getDestroyProgress = + /** + * 获取玩家破坏方块所需时间 + * @param {Block} block + * @returns {number} + */ + function (block) { + return GMLIB_API.getPlayerDestroyBlockProgress(this, block); + } + module.exports = { StaticFloatingText, DynamicFloatingText, diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 66d77fe..21b47c2 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,4 +1,6 @@ #include "Global.h" +#include "magic_enum.hpp" +#include "mc/deps/core/string/HashedString.h" #include bool isInteger(const std::string& str) { @@ -884,4 +886,10 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getItemMaxCount", [](ItemStack const* item) -> int { return item->getMaxStackSize(); }); + RemoteCall::exportAs("GMLIB_API", "entityHasFamily", [](Actor* entity, std::string const& family) -> bool { + return entity->hasFamily(HashedString(family)); + }); + RemoteCall::exportAs("GMLIB_API", "getPlayerDestroyBlockProgress", [](Player* player, Block const* block) -> float { + return player->getDestroyProgress(*block); + }); } \ No newline at end of file diff --git a/src/EventAPI.cpp b/src/EventAPI.cpp index e0134cb..f129297 100644 --- a/src/EventAPI.cpp +++ b/src/EventAPI.cpp @@ -206,7 +206,7 @@ void Export_Event_API() { ); return true; } - case doHash("DragonRespawn"): { + case doHash("onDragonRespawn"): { auto Call = RemoteCall::importAs(eventName, eventId); eventBus->emplaceListener( [Call](Event::EntityEvent::DragonRespawnBeforeEvent& ev) { @@ -221,7 +221,7 @@ void Export_Event_API() { ); return true; } - case doHash("ProjectileTryCreate"): { + case doHash("onProjectileTryCreate"): { auto Call = RemoteCall::importAs(eventName, eventId); eventBus->emplaceListener( [Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) { @@ -237,7 +237,7 @@ void Export_Event_API() { ); return true; } - case doHash("ProjectileCreate"): { + case doHash("onProjectileCreate"): { auto Call = RemoteCall::importAs(eventName, eventId); eventBus->emplaceListener( [Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) { @@ -249,7 +249,7 @@ void Export_Event_API() { ); return true; } - case doHash("SpawnWanderingTrader"): { + case doHash("onSpawnWanderingTrader"): { auto Call = RemoteCall::importAs pos)>(eventName, eventId); eventBus->emplaceListener( [Call](Event::EntityEvent::SpawnWanderingTraderBeforeEvent& ev) { @@ -264,7 +264,7 @@ void Export_Event_API() { ); return true; } - case doHash("HandleRequestAction"): { + case doHash("onHandleRequestAction"): { auto Call = RemoteCall::importAs(eventName, eventId); eventBus->emplaceListener( [Call](Event::PacketEvent::ContainerClosePacketSendAfterEvent& ev) {