新增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: (
|
listener: (
|
||||||
/** 弹射物实体对象 */
|
/** 弹射物实体对象 */
|
||||||
entity: Entity
|
entity: Entity,
|
||||||
|
/** 创建弹射的实体的uniqueID */
|
||||||
|
uniqueId: number
|
||||||
) => boolean | void
|
) => boolean | void
|
||||||
): boolean;
|
): boolean;
|
||||||
|
|
||||||
@@ -188,7 +190,37 @@ declare class Event {
|
|||||||
/** 回调函数 */
|
/** 回调函数 */
|
||||||
listener: (
|
listener: (
|
||||||
/** 弹射物实体对象 */
|
/** 弹射物实体对象 */
|
||||||
entity: Entity
|
entity: Entity,
|
||||||
|
/** 创建弹射的实体的uniqueID */
|
||||||
|
uniqueId: number
|
||||||
) => void
|
) => void
|
||||||
): boolean;
|
): 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获取玩家对象 */
|
/** 根据UniqueId获取玩家对象 */
|
||||||
static getPlayerFromUniqueId(
|
static getPlayerFromUniqueId(
|
||||||
uniqueId: string
|
uniqueId: string | number
|
||||||
): Player;
|
): Player;
|
||||||
|
|
||||||
/** 根据UniqueId获取实体对象 */
|
/** 根据UniqueId获取实体对象 */
|
||||||
static getEntityFromUniqueId(
|
static getEntityFromUniqueId(
|
||||||
uniqueId: string
|
uniqueId: string | number
|
||||||
): Entity;
|
): Entity;
|
||||||
|
|
||||||
/** 获取方块runtimeId */
|
/** 获取方块runtimeId */
|
||||||
|
|||||||
+4
-4
@@ -805,20 +805,20 @@ class Minecraft {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据UniqueId获取玩家对象
|
* 根据UniqueId获取玩家对象
|
||||||
* @param {string} uniqueId 玩家的UniqueId
|
* @param {string|number} uniqueId 玩家的UniqueId
|
||||||
* @returns {Player} 玩家对象
|
* @returns {Player} 玩家对象
|
||||||
*/
|
*/
|
||||||
static getPlayerFromUniqueId(uniqueId) {
|
static getPlayerFromUniqueId(uniqueId) {
|
||||||
return GMLIB_API.getPlayerFromUniqueId(uniqueId);
|
return GMLIB_API.getPlayerFromUniqueId(uniqueId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据UniqueId获取实体对象
|
* 根据UniqueId获取实体对象
|
||||||
* @param {string} uniqueId 实体的UniqueId
|
* @param {string|number} uniqueId 实体的UniqueId
|
||||||
* @returns {Entity} 实体对象
|
* @returns {Entity} 实体对象
|
||||||
*/
|
*/
|
||||||
static getEntityFromUniqueId(uniqueId) {
|
static getEntityFromUniqueId(uniqueId) {
|
||||||
return GMLIB_API.getEntityFromUniqueId(uniqueId);
|
return GMLIB_API.getEntityFromUniqueId(uniqueId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+48
-5
@@ -1,4 +1,5 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "mc/world/ActorUniqueID.h"
|
||||||
using namespace ll::hash_utils;
|
using namespace ll::hash_utils;
|
||||||
|
|
||||||
void Export_Event_API() {
|
void Export_Event_API() {
|
||||||
@@ -222,31 +223,73 @@ void Export_Event_API() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case doHash("ProjectileTryCreate"): {
|
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>(
|
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateBeforeEvent>(
|
||||||
[Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) {
|
[Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
try {
|
try {
|
||||||
result = Call(&ev.self());
|
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||||
|
result = Call(&ev.self(), uid);
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
ev.cancel();
|
ev.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case doHash("ProjectileCreate"): {
|
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>(
|
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateAfterEvent>(
|
||||||
[Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) {
|
[Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) {
|
||||||
try {
|
try {
|
||||||
Call(&ev.self());
|
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||||
|
Call(&ev.self(), uid);
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return true;
|
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:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user