Compare commits
14 Commits
Vendored
+6
-6
@@ -55,8 +55,8 @@ declare class Event {
|
||||
item: Item,
|
||||
/** 尝试生成的坐标对象 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体对象 */
|
||||
spawnerEntity: Entity
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
@@ -72,15 +72,15 @@ declare class Event {
|
||||
entity: Entity,
|
||||
/** 实体生成的坐标 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体对象 */
|
||||
spawnerEntity: Entity
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 实体切换维度 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityChangeDim",
|
||||
event: "onEntityTryChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
@@ -93,7 +93,7 @@ declare class Event {
|
||||
/** 实体切换维度后(不可拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityChangeDimAfter",
|
||||
event: "onEntityChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
|
||||
+7
-21
@@ -1,23 +1,11 @@
|
||||
/** 事件创建函数 @type {function(string,string):boolean} */
|
||||
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
|
||||
|
||||
/** 事件ID @type {number} */
|
||||
let NextEventId = 0;
|
||||
|
||||
/**
|
||||
* 获取事件ID标识名
|
||||
* @returns {string} 事件ID标识名
|
||||
*/
|
||||
function getNextEventId() {
|
||||
NextEventId++;
|
||||
return "GMLIB_Event_" + NextEventId;
|
||||
}
|
||||
const CallEvent = ll.import("GMLIB_Event_API", "callCustomEvent");
|
||||
/** 获取事件ID函数 @type {function():string} */
|
||||
const getNextEventId = ll.import("GMLIB_Event_API", "getNextScriptEventId");
|
||||
|
||||
/** 事件类 */
|
||||
class Event {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
constructor() { throw new Error("Static class cannot be instantiated"); }
|
||||
|
||||
/**
|
||||
* 监听事件
|
||||
@@ -30,13 +18,11 @@ class Event {
|
||||
ll.export(callback, event, eventId);
|
||||
let result = CallEvent(event, eventId);
|
||||
if (!result) {
|
||||
logger.error(`Cannot listen event "${event}"!`);
|
||||
logger.error(`Event "${event}" No Found!`);
|
||||
logger.error(`Cannot listen event "${event}" !`);
|
||||
logger.error(`GMLIB Script Event "${event}" does not exist !`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Event
|
||||
};
|
||||
module.exports = { Event };
|
||||
Vendored
+22
@@ -509,6 +509,28 @@ declare class Recipes {
|
||||
/** 解锁条件(也可以填物品命名空间ID) */
|
||||
unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined
|
||||
): boolean;
|
||||
|
||||
/** 注册自定义有序合成表 */
|
||||
static registerCustomShapedRecipe(
|
||||
/** 合成表唯一标识符 */
|
||||
recipeId: string,
|
||||
/** 合成表摆放方式,数组元素为字符串 */
|
||||
shape: [string, string, string],
|
||||
/** 材料数组 */
|
||||
ingredients: string[],
|
||||
/** 合成结果 */
|
||||
result: Item
|
||||
): boolean;
|
||||
|
||||
/** 注册自定义无序合成表 */
|
||||
static registerCustomShapelessRecipe(
|
||||
/** 合成表唯一标识符 */
|
||||
recipeId: string,
|
||||
/** 合成材料 */
|
||||
ingredients: string[],
|
||||
/** 合成结果 */
|
||||
result: Item
|
||||
): boolean;
|
||||
}
|
||||
|
||||
/** 实验性功能类 */
|
||||
|
||||
+29
-4
@@ -96,6 +96,10 @@ const GMLIB_API = {
|
||||
registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"),
|
||||
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||
registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"),
|
||||
/** 注册有序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||
registerCustomShapedRecipe: ll.import("GMLIB_API", "registerCustomShapedRecipe"),
|
||||
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||
registerCustomShapelessRecipe: ll.import("GMLIB_API", "registerCustomShapelessRecipe"),
|
||||
/** 检测LRCA版本是否大于或等于此版本 @type {function(number,number,number):boolean} */
|
||||
isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"),
|
||||
/** 获取LRCA版本 @type {function():string} */
|
||||
@@ -539,9 +543,7 @@ class DynamicFloatingText extends StaticFloatingText {
|
||||
* @param {boolean} [papi=true] 是否使用PAPI变量
|
||||
*/
|
||||
constructor(pos, text, updateRate = 1, papi = true) {
|
||||
this.mPosition = pos;
|
||||
this.mText = text;
|
||||
this.mPlaceholderAPI = papi;
|
||||
super(pos, text, papi);
|
||||
this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText, this.mPlaceholderAPI);
|
||||
this.mUpdateRate = updateRate;
|
||||
this.mTaskId = null;
|
||||
@@ -1196,6 +1198,18 @@ class Recipes {
|
||||
return GMLIB_API.registerShapedRecipe(recipeId, shape, ingredients, result, count, unlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义有序合成表
|
||||
* @param {string} recipeId 合成表唯一标识
|
||||
* @param {[string,string,string]} shape 合成表摆放方式,数组元素为字符串
|
||||
* @param {Array.<string>} ingredients 材料数组
|
||||
* @param {Item} result 合成结果
|
||||
* @returns {boolean} 是否注册成功
|
||||
*/
|
||||
static registerCustomShapedRecipe(recipeId, shape, ingredients, result) {
|
||||
return GMLIB_API.registerCustomShapedRecipe(recipeId, shape, ingredients, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册无序合成表
|
||||
* @param {string} recipeId 合成表唯一标识
|
||||
@@ -1208,6 +1222,17 @@ class Recipes {
|
||||
static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") {
|
||||
return GMLIB_API.registerShapelessRecipe(recipeId, ingredients, result, count, unlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义无序合成表
|
||||
* @param {string} recipeId 合成表唯一标识
|
||||
* @param {Array.<string>} ingredients 合成材料
|
||||
* @param {Item} result 合成结果
|
||||
* @returns {boolean} 是否注册成功
|
||||
*/
|
||||
static registerCustomShapelessRecipe(recipeId, ingredients, result) {
|
||||
return GMLIB_API.registerCustomShapelessRecipe(recipeId, ingredients, result);
|
||||
}
|
||||
}
|
||||
|
||||
/** 实验性功能类 */
|
||||
@@ -2470,7 +2495,7 @@ LLSE_Player.prototype.getArmorValue =
|
||||
return GMLIB_API.getPlayerArmorValue(this);
|
||||
}
|
||||
|
||||
LLSE_Player.prototype.getEntityOwner =
|
||||
LLSE_Entity.prototype.getEntityOwner =
|
||||
/**
|
||||
* 获取实体的主人
|
||||
* @returns {Entity|null}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "${pluginName}",
|
||||
"entry": "${pluginFile}",
|
||||
"version": "0.13.2",
|
||||
"version": "0.13.3",
|
||||
"author": "GroupMountain",
|
||||
"type": "native",
|
||||
"passive": true,
|
||||
|
||||
@@ -958,4 +958,43 @@ void Export_Compatibility_API() {
|
||||
level->setDefaultGameType((GameType)gameMode);
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"registerCustomShapelessRecipe",
|
||||
[](std::string const& recipe_id, std::vector<std::string> ingredients, ItemStack* result) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
std::vector<Recipes::Type> types;
|
||||
char rt = 'A';
|
||||
for (auto& ing : ingredients) {
|
||||
auto key = Recipes::Type(ing, rt, 1, 0);
|
||||
types.push_back(key);
|
||||
rt++;
|
||||
}
|
||||
CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, *result);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"registerCustomShapedRecipe",
|
||||
[](std::string const& recipe_id,
|
||||
std::vector<std::string> shape,
|
||||
std::vector<std::string> ingredients,
|
||||
ItemStack* result) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
std::vector<Recipes::Type> types;
|
||||
char rt = 'A';
|
||||
for (auto& ing : ingredients) {
|
||||
auto key = Recipes::Type(ing, rt, 1, 0);
|
||||
types.push_back(key);
|
||||
rt++;
|
||||
}
|
||||
CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, *result);
|
||||
}
|
||||
);
|
||||
}
|
||||
+177
-268
@@ -1,329 +1,238 @@
|
||||
#include "Global.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class LegacyScriptEventManager {
|
||||
private:
|
||||
int64 mNextEventId = 0;
|
||||
std::unordered_map<int64, ll::event::ListenerPtr> mEventListeners;
|
||||
|
||||
public:
|
||||
std::string getNextEventId() {
|
||||
mNextEventId++;
|
||||
return "GMLIB_EVENT_" + std::to_string(mNextEventId);
|
||||
}
|
||||
|
||||
void emplaceListener(std::string const& scriptEventId, ll::event::ListenerPtr listenerPtr) {
|
||||
mEventListeners[doHash(scriptEventId)] = listenerPtr;
|
||||
}
|
||||
|
||||
void removeListener(std::string const& scriptEventId) {
|
||||
ll::event::EventBus::getInstance().removeListener(mEventListeners[doHash(scriptEventId)]);
|
||||
mEventListeners.erase(doHash(scriptEventId));
|
||||
}
|
||||
|
||||
public:
|
||||
static LegacyScriptEventManager& getInstance() {
|
||||
static std::unique_ptr<LegacyScriptEventManager> instance;
|
||||
if (!instance) {
|
||||
instance = std::make_unique<LegacyScriptEventManager>();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_EVENT_LISTEN(eventType, callFunction, eventParams, cancelFunction, otherFunction) \
|
||||
eventManager.emplaceListener( \
|
||||
eventId, \
|
||||
eventBus.emplaceListener<eventType>([eventName, eventId, &eventBus, &eventManager](eventType& ev) -> void { \
|
||||
if (!RemoteCall::hasFunc(eventName, eventId)) { \
|
||||
eventManager.removeListener(eventId); \
|
||||
return; \
|
||||
} \
|
||||
bool result = true; \
|
||||
try { \
|
||||
otherFunction; \
|
||||
result = RemoteCall::importAs<bool callFunction>(eventName, eventId) eventParams; \
|
||||
} catch (...) {} \
|
||||
if (!result) cancelFunction; \
|
||||
}) \
|
||||
); \
|
||||
return true;
|
||||
|
||||
void Export_Event_API() {
|
||||
auto eventBus = &ll::event::EventBus::getInstance();
|
||||
RemoteCall::exportAs("GMLIB_Event_API", "getNextScriptEventId", []() -> std::string {
|
||||
return LegacyScriptEventManager::getInstance().getNextEventId();
|
||||
});
|
||||
auto& eventBus = ll::event::EventBus::getInstance();
|
||||
auto& eventManager = LegacyScriptEventManager::getInstance();
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"GMLIB_Event_API",
|
||||
"callCustomEvent",
|
||||
[eventBus](std::string const& eventName, std::string const& eventId) -> bool {
|
||||
[&eventBus, &eventManager](std::string const& eventName, std::string const& eventId) -> bool {
|
||||
if (!RemoteCall::hasFunc(eventName, eventId)) return false;
|
||||
switch (doHash(eventName)) {
|
||||
case doHash("onClientLogin"): {
|
||||
auto Call = RemoteCall::importAs<bool(
|
||||
std::string const& realName,
|
||||
std::string const& uuid,
|
||||
std::string const& serverXuid,
|
||||
std::string const& clientXuid
|
||||
)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PacketEvent::ClientLoginAfterEvent>(
|
||||
[Call](Event::PacketEvent::ClientLoginAfterEvent& ev) {
|
||||
try {
|
||||
Call(
|
||||
ev.getRealName(),
|
||||
ev.getUuid().asString(),
|
||||
ev.getServerAuthXuid(),
|
||||
ev.getClientAuthXuid()
|
||||
);
|
||||
} catch (...) {}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::PacketEvent::ClientLoginAfterEvent,
|
||||
(std::string const& realName,
|
||||
std::string const& uuid,
|
||||
std::string const& serverXuid,
|
||||
std::string const& clientXuid),
|
||||
(ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
|
||||
logger.error("Event \"onClientLogin\" cannot be intercepted"),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onWeatherChange"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::LevelEvent::WeatherUpdateBeforeEvent>(
|
||||
[Call](Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(
|
||||
ev.getLightningLevel(),
|
||||
ev.getRainLevel(),
|
||||
ev.getLightningLastTick(),
|
||||
ev.getRainingLastTick()
|
||||
);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::LevelEvent::WeatherUpdateBeforeEvent,
|
||||
(int lightningLevel, int rainLevel, int lightningLast, int rainLast),
|
||||
(ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onMobPick"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::MobPickupItemBeforeEvent>(
|
||||
[Call](Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), (Actor*)&ev.getItemActor());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::MobPickupItemBeforeEvent,
|
||||
(Actor * mob, Actor * item),
|
||||
(&ev.self(), (Actor*)&ev.getItemActor()),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onItemTrySpawn"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnBeforeEvent>(
|
||||
[Call](Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.getItem(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::ItemActorSpawnBeforeEvent,
|
||||
(const ItemStack* item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||
(&ev.getItem(),
|
||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onItemSpawned"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>(
|
||||
eventName,
|
||||
eventId
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::ItemActorSpawnAfterEvent,
|
||||
(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||
(&ev.getItem(),
|
||||
(Actor*)&ev.getItemActor(),
|
||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||
logger.error("Event \"onItemSpawned\" cannot be intercepted"),
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnAfterEvent>(
|
||||
[Call](Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
try {
|
||||
Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEntityChangeDim"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
|
||||
[Call](Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), ev.getToDimensionId());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
case doHash("onEntityTryChangeDim"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::ActorChangeDimensionBeforeEvent,
|
||||
(Actor * entity, int toDimId),
|
||||
(&ev.self(), ev.getToDimensionId()),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onLeaveBed"): {
|
||||
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
|
||||
[Call](Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::PlayerEvent::PlayerStopSleepBeforeEvent,
|
||||
(Player * pl),
|
||||
(&ev.self()),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onDeathMessage"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(std::string const& message, std::vector<std::string>, Actor* dead)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::DeathMessageAfterEvent>(
|
||||
[Call](Event::EntityEvent::DeathMessageAfterEvent& ev) {
|
||||
auto msg = ev.getDeathMessage();
|
||||
auto source = ev.getDamageSource();
|
||||
try {
|
||||
Call(msg.first, msg.second, &ev.self());
|
||||
} catch (...) {}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::DeathMessageAfterEvent,
|
||||
(std::string const& message, std::vector<std::string>, Actor* dead),
|
||||
(ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()),
|
||||
logger.error("Event \"onDeathMessage\" cannot be intercepted"),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onMobHurted"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::MobHurtAfterEvent>(
|
||||
[Call](Event::EntityEvent::MobHurtAfterEvent& ev) {
|
||||
auto& damageSource = ev.getSource();
|
||||
Actor* source = nullptr;
|
||||
if (damageSource.isEntitySource()) {
|
||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
||||
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
||||
if (source->getOwner()) {
|
||||
source = source->getOwner();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause());
|
||||
} catch (...) {}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::MobHurtAfterEvent,
|
||||
(Actor * mob, Actor * source, float damage, int cause),
|
||||
(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()),
|
||||
logger.error("Event \"onMobHurted\" cannot be intercepted"),
|
||||
auto& damageSource = ev.getSource();
|
||||
Actor* source = nullptr;
|
||||
if (damageSource.isEntitySource()) {
|
||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
||||
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
||||
if (source->getOwner()) source = source->getOwner();
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEndermanTake"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
|
||||
[Call](Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::EndermanTakeBlockBeforeEvent,
|
||||
(Actor * mob),
|
||||
(&ev.self()),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEntityChangeDimAfter"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, int fromDimId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ActorChangeDimensionAfterEvent>(
|
||||
[Call](Event::EntityEvent::ActorChangeDimensionAfterEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), ev.getFromDimensionId());
|
||||
} catch (...) {}
|
||||
}
|
||||
case doHash("onEntityChangeDim"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::ActorChangeDimensionAfterEvent,
|
||||
(Actor * mob, int fromDimId),
|
||||
(&ev.self(), ev.getFromDimensionId()),
|
||||
logger.error("Event \"onEntityChangeDim\" cannot be intercepted"),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onDragonRespawn"): {
|
||||
auto Call = RemoteCall::importAs<bool(int64 enderDragonUniqueID)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::DragonRespawnBeforeEvent>(
|
||||
[Call](Event::EntityEvent::DragonRespawnBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(ev.getEnderDragon().id);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::DragonRespawnBeforeEvent,
|
||||
(int64 enderDragonUniqueID),
|
||||
(ev.getEnderDragon().id),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onProjectileTryCreate"): {
|
||||
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 {
|
||||
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||
result = Call(&ev.self(), uid);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::ProjectileCreateBeforeEvent,
|
||||
(Actor * mob, int64 uniqueId),
|
||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onProjectileCreate"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateAfterEvent>(
|
||||
[Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) {
|
||||
try {
|
||||
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||
Call(&ev.self(), uid);
|
||||
} catch (...) {}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::ProjectileCreateAfterEvent,
|
||||
(Actor * mob, int64 uniqueId),
|
||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||
logger.error("Event \"onProjectileCreate\" cannot be intercepted"),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onSpawnWanderingTrader"): {
|
||||
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(), ev.getRegion().getDimensionId()});
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::EntityEvent::SpawnWanderingTraderBeforeEvent,
|
||||
(std::pair<BlockPos, int> pos),
|
||||
({ev.getPos(), ev.getRegion().getDimensionId()}),
|
||||
ev.cancel(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onHandleRequestAction"): {
|
||||
auto Call = RemoteCall::importAs<bool(
|
||||
Player * player,
|
||||
std::string const& actionType,
|
||||
int count,
|
||||
std::string const& sourceContainerNetId,
|
||||
int sourceSlot,
|
||||
std::string const& destinationContainerNetId,
|
||||
int destinationSlot
|
||||
)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PlayerEvent::HandleRequestActionBeforeEvent>(
|
||||
[Call](Event::PlayerEvent::HandleRequestActionBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
auto requestAction = (ItemStackRequestActionTransferBase*)&ev.getRequestAction();
|
||||
auto source = requestAction->getSrc();
|
||||
// TODO: The next version of LeviLamina changes to a member function
|
||||
auto destination = ll::memory::dAccess<ItemStackRequestSlotInfo>(requestAction, 56);
|
||||
result = Call(
|
||||
&ev.self(),
|
||||
magic_enum::enum_name(requestAction->mActionType).data(),
|
||||
ll::memory::dAccess<uchar>(requestAction, 18),
|
||||
magic_enum::enum_name(source.mOpenContainerNetId).data(),
|
||||
source.mSlot,
|
||||
magic_enum::enum_name(destination.mOpenContainerNetId).data(),
|
||||
destination.mSlot
|
||||
);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(Event::PlayerEvent::HandleRequestActionBeforeEvent,
|
||||
(Player * player,
|
||||
std::string const& actionType,
|
||||
int count,
|
||||
std::string const& sourceContainerNetId,
|
||||
int sourceSlot,
|
||||
std::string const& destinationContainerNetId,
|
||||
int destinationSlot),
|
||||
((Player*)&ev.self(),
|
||||
magic_enum::enum_name(requestAction->mActionType).data(),
|
||||
(int)requestAction->mAmount,
|
||||
magic_enum::enum_name(requestAction->mSrc.mOpenContainerNetId).data(),
|
||||
(int)requestAction->mSrc.mSlot,
|
||||
magic_enum::enum_name(requestAction->mDst.mOpenContainerNetId).data(),
|
||||
(int)requestAction->mDst.mSlot),
|
||||
ev.cancel(),
|
||||
auto requestAction = (ItemStackRequestActionTransferBase*)&ev.getRequestAction();
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onSendContainerClosePacket"): {
|
||||
auto Call = RemoteCall::importAs<bool(Player * player, int ContainerNetId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PacketEvent::ContainerClosePacketSendAfterEvent>(
|
||||
[Call](Event::PacketEvent::ContainerClosePacketSendAfterEvent& ev) {
|
||||
try {
|
||||
Call(
|
||||
ev.getServerNetworkHandler()
|
||||
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
|
||||
(int)ev.getPacket().mContainerId
|
||||
);
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
Event::PacketEvent::ContainerClosePacketSendAfterEvent,
|
||||
(Player * player, int ContainerNetId),
|
||||
(ev.getServerNetworkHandler()
|
||||
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
|
||||
(int)ev.getPacket().mContainerId),
|
||||
logger.error("Event \"onSendContainerClosePacket\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onServerStopping"): {
|
||||
auto Call = RemoteCall::importAs<bool()>(eventName, eventId);
|
||||
eventBus->emplaceListener<ll::event::server::ServerStoppingEvent>(
|
||||
[Call](ll::event::server::ServerStoppingEvent& ev) {
|
||||
try {
|
||||
Call();
|
||||
} catch (...) {}
|
||||
}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
ll::event::server::ServerStoppingEvent,
|
||||
(),
|
||||
(),
|
||||
logger.error("Event \"onServerStopping\" cannot be intercepted"),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ using namespace Mod;
|
||||
|
||||
#define LIB_VERSION_MAJOR 0
|
||||
#define LIB_VERSION_MINOR 13
|
||||
#define LIB_VERSION_PATCH 2
|
||||
#define LIB_VERSION_PATCH 3
|
||||
|
||||
#define LIB_VERSION Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
|
||||
|
||||
|
||||
+2
-10
@@ -115,13 +115,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
JsonRecipe::registerSmithingTransformRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
base,
|
||||
addition,
|
||||
result
|
||||
);
|
||||
JsonRecipe::registerSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -192,7 +186,5 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
|
||||
VanillaFix::setFixI18nEnabled();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void { VanillaFix::setFixI18nEnabled(); });
|
||||
}
|
||||
+4
-19
@@ -15,9 +15,7 @@ bool isParameters(std::string const& str) {
|
||||
|
||||
std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from); }
|
||||
|
||||
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
|
||||
return PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
|
||||
}
|
||||
std::string GetValueWithPlayer(std::string const& key, Player* player) { return PlaceholderAPI::getValue(key, player); }
|
||||
|
||||
bool registerPlayerPlaceholder(
|
||||
std::string const& PluginName,
|
||||
@@ -38,11 +36,7 @@ bool registerPlayerPlaceholder(
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
|
||||
PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp) { return Call(sp); },
|
||||
PluginName
|
||||
);
|
||||
PlaceholderAPI::registerPlayerPlaceholder(PAPIName, [Call](Player* sp) { return Call(sp); }, PluginName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -84,18 +78,9 @@ bool registerStaticPlaceholder(
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
if (num == -1) {
|
||||
PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
PlaceholderAPI::registerStaticPlaceholder(PAPIName, [Call] { return Call(); }, PluginName);
|
||||
} else {
|
||||
PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
num,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
PlaceholderAPI::registerStaticPlaceholder(PAPIName, num, [Call] { return Call(); }, PluginName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 2,
|
||||
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
||||
"version": "0.13.2",
|
||||
"version": "0.13.3",
|
||||
"info": {
|
||||
"name": "GMLIB-LegacyRemoteCallApi",
|
||||
"description": "Legacy RemoteCall API for GMLIB",
|
||||
@@ -14,7 +14,7 @@
|
||||
"library"
|
||||
]
|
||||
},
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.13.2/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.13.3/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"dependencies": {
|
||||
"github.com/GroupMountain/GMLIB": ">=0.13.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user