新增2事件,修改2事件,2接口
新增事件: - SpawnWanderingTrader - HandleRequestAction 修改事件: - ProjectileTryCreate - ProjectileCreate 修改接口: - getPlayerFromUniqueId - getEntityFromUniqueId
This commit is contained in:
Vendored
+34
-2
@@ -177,7 +177,9 @@ declare class Event {
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 弹射物实体对象 */
|
||||
entity: Entity
|
||||
entity: Entity,
|
||||
/** 创建弹射的实体的uniqueID */
|
||||
uniqueId: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
@@ -188,7 +190,37 @@ declare class Event {
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 弹射物实体对象 */
|
||||
entity: Entity
|
||||
entity: Entity,
|
||||
/** 创建弹射的实体的uniqueID */
|
||||
uniqueId: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 生成流浪商人 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "SpawnWanderingTrader",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 生成的坐标 */
|
||||
pos: IntPos
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
/** 处理物品请求 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "HandleRequestAction",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 请求玩家 */
|
||||
player: Player,
|
||||
/** 请求类型 */
|
||||
actionType: string,
|
||||
/** 容器ID */
|
||||
ContainerNetId: string,
|
||||
/** 请求的槽位 */
|
||||
slot: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -276,12 +276,12 @@ declare class Minecraft {
|
||||
|
||||
/** 根据UniqueId获取玩家对象 */
|
||||
static getPlayerFromUniqueId(
|
||||
uniqueId: string
|
||||
uniqueId: string | number
|
||||
): Player;
|
||||
|
||||
/** 根据UniqueId获取实体对象 */
|
||||
static getEntityFromUniqueId(
|
||||
uniqueId: string
|
||||
uniqueId: string | number
|
||||
): Entity;
|
||||
|
||||
/** 获取方块runtimeId */
|
||||
|
||||
+4
-4
@@ -805,20 +805,20 @@ class Minecraft {
|
||||
|
||||
/**
|
||||
* 根据UniqueId获取玩家对象
|
||||
* @param {string} uniqueId 玩家的UniqueId
|
||||
* @param {string|number} uniqueId 玩家的UniqueId
|
||||
* @returns {Player} 玩家对象
|
||||
*/
|
||||
static getPlayerFromUniqueId(uniqueId) {
|
||||
return GMLIB_API.getPlayerFromUniqueId(uniqueId);
|
||||
return GMLIB_API.getPlayerFromUniqueId(uniqueId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据UniqueId获取实体对象
|
||||
* @param {string} uniqueId 实体的UniqueId
|
||||
* @param {string|number} uniqueId 实体的UniqueId
|
||||
* @returns {Entity} 实体对象
|
||||
*/
|
||||
static getEntityFromUniqueId(uniqueId) {
|
||||
return GMLIB_API.getEntityFromUniqueId(uniqueId);
|
||||
return GMLIB_API.getEntityFromUniqueId(uniqueId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+47
-4
@@ -1,4 +1,5 @@
|
||||
#include "Global.h"
|
||||
#include "mc/world/ActorUniqueID.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
void Export_Event_API() {
|
||||
@@ -222,12 +223,13 @@ void Export_Event_API() {
|
||||
return true;
|
||||
}
|
||||
case doHash("ProjectileTryCreate"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateBeforeEvent>(
|
||||
[Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||
result = Call(&ev.self(), uid);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
@@ -237,16 +239,57 @@ void Export_Event_API() {
|
||||
return true;
|
||||
}
|
||||
case doHash("ProjectileCreate"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateAfterEvent>(
|
||||
[Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) {
|
||||
try {
|
||||
Call(&ev.self());
|
||||
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||
Call(&ev.self(), uid);
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("SpawnWanderingTrader"): {
|
||||
auto Call = RemoteCall::importAs<bool(std::pair<BlockPos, int> pos)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::SpawnWanderingTraderBeforeEvent>(
|
||||
[Call](Event::EntityEvent::SpawnWanderingTraderBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call({ev.getPos(), 0});
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("HandleRequestAction"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(Player * player, std::string const& actionType, std::string const& ContainerNetId, int slot)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::PlayerEvent::HandleRequestActionBeforeEvent>(
|
||||
[Call](Event::PlayerEvent::HandleRequestActionBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
auto requestAction = (ItemStackRequestActionTransferBase*)&ev.getRequestAction();
|
||||
result = Call(
|
||||
&ev.self(),
|
||||
magic_enum::enum_name(requestAction->mActionType).data(),
|
||||
magic_enum::enum_name(requestAction->getSrc().mOpenContainerNetId).data(),
|
||||
requestAction->getSrc().mSlot
|
||||
);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user