Compare commits

...

14 Commits

11 changed files with 290 additions and 332 deletions
+6 -6
View File
@@ -55,8 +55,8 @@ declare class Event {
item: Item, item: Item,
/** 尝试生成的坐标对象 */ /** 尝试生成的坐标对象 */
pos: FloatPos, pos: FloatPos,
/** 创建掉落物的实体对象 */ /** 创建掉落物的实体uniqueId */
spawnerEntity: Entity spawnerUniqueId: number
) => boolean | void ) => boolean | void
): boolean; ): boolean;
@@ -72,15 +72,15 @@ declare class Event {
entity: Entity, entity: Entity,
/** 实体生成的坐标 */ /** 实体生成的坐标 */
pos: FloatPos, pos: FloatPos,
/** 创建掉落物的实体对象 */ /** 创建掉落物的实体uniqueId */
spawnerEntity: Entity spawnerUniqueId: number
) => void ) => void
): boolean; ): boolean;
/** 实体切换维度 */ /** 实体切换维度 */
static listen( static listen(
/** 事件名 */ /** 事件名 */
event: "onEntityChangeDim", event: "onEntityTryChangeDim",
/** 回调函数 */ /** 回调函数 */
listener: ( listener: (
/** 切换维度的实体对象 */ /** 切换维度的实体对象 */
@@ -93,7 +93,7 @@ declare class Event {
/** 实体切换维度后(不可拦截) */ /** 实体切换维度后(不可拦截) */
static listen( static listen(
/** 事件名 */ /** 事件名 */
event: "onEntityChangeDimAfter", event: "onEntityChangeDim",
/** 回调函数 */ /** 回调函数 */
listener: ( listener: (
/** 切换维度的实体对象 */ /** 切换维度的实体对象 */
+7 -21
View File
@@ -1,23 +1,11 @@
/** 事件创建函数 @type {function(string,string):boolean} */ /** 事件创建函数 @type {function(string,string):boolean} */
const CallEvent = ll.import("GMLIB_API", "callCustomEvent"); const CallEvent = ll.import("GMLIB_Event_API", "callCustomEvent");
/** 获取事件ID函数 @type {function():string} */
/** 事件ID @type {number} */ const getNextEventId = ll.import("GMLIB_Event_API", "getNextScriptEventId");
let NextEventId = 0;
/**
* 获取事件ID标识名
* @returns {string} 事件ID标识名
*/
function getNextEventId() {
NextEventId++;
return "GMLIB_Event_" + NextEventId;
}
/** 事件类 */ /** 事件类 */
class Event { class Event {
constructor() { constructor() { throw new Error("Static class cannot be instantiated"); }
throw new Error("Static class cannot be instantiated");
}
/** /**
* 监听事件 * 监听事件
@@ -30,13 +18,11 @@ class Event {
ll.export(callback, event, eventId); ll.export(callback, event, eventId);
let result = CallEvent(event, eventId); let result = CallEvent(event, eventId);
if (!result) { if (!result) {
logger.error(`Cannot listen event "${event}"!`); logger.error(`Cannot listen event "${event}" !`);
logger.error(`Event "${event}" No Found!`); logger.error(`GMLIB Script Event "${event}" does not exist !`);
} }
return result; return result;
} }
} }
module.exports = { module.exports = { Event };
Event
};
+22
View File
@@ -509,6 +509,28 @@ declare class Recipes {
/** 解锁条件(也可以填物品命名空间ID) */ /** 解锁条件(也可以填物品命名空间ID) */
unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined
): boolean; ): 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
View File
@@ -96,6 +96,10 @@ const GMLIB_API = {
registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"), registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"),
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */ /** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"), 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} */ /** 检测LRCA版本是否大于或等于此版本 @type {function(number,number,number):boolean} */
isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"), isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"),
/** 获取LRCA版本 @type {function():string} */ /** 获取LRCA版本 @type {function():string} */
@@ -539,9 +543,7 @@ class DynamicFloatingText extends StaticFloatingText {
* @param {boolean} [papi=true] 是否使用PAPI变量 * @param {boolean} [papi=true] 是否使用PAPI变量
*/ */
constructor(pos, text, updateRate = 1, papi = true) { constructor(pos, text, updateRate = 1, papi = true) {
this.mPosition = pos; super(pos, text, papi);
this.mText = text;
this.mPlaceholderAPI = papi;
this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText, this.mPlaceholderAPI); this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText, this.mPlaceholderAPI);
this.mUpdateRate = updateRate; this.mUpdateRate = updateRate;
this.mTaskId = null; this.mTaskId = null;
@@ -1196,6 +1198,18 @@ class Recipes {
return GMLIB_API.registerShapedRecipe(recipeId, shape, ingredients, result, count, unlock); 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 合成表唯一标识 * @param {string} recipeId 合成表唯一标识
@@ -1208,6 +1222,17 @@ class Recipes {
static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") { static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") {
return GMLIB_API.registerShapelessRecipe(recipeId, ingredients, result, count, unlock); 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); return GMLIB_API.getPlayerArmorValue(this);
} }
LLSE_Player.prototype.getEntityOwner = LLSE_Entity.prototype.getEntityOwner =
/** /**
* 获取实体的主人 * 获取实体的主人
* @returns {Entity|null} * @returns {Entity|null}
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "${pluginName}", "name": "${pluginName}",
"entry": "${pluginFile}", "entry": "${pluginFile}",
"version": "0.13.2", "version": "0.13.3",
"author": "GroupMountain", "author": "GroupMountain",
"type": "native", "type": "native",
"passive": true, "passive": true,
+39
View File
@@ -958,4 +958,43 @@ void Export_Compatibility_API() {
level->setDefaultGameType((GameType)gameMode); 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);
}
);
} }
+163 -254
View File
@@ -1,329 +1,238 @@
#include "Global.h" #include "Global.h"
using namespace ll::hash_utils; 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() { 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( RemoteCall::exportAs(
"GMLIB_API", "GMLIB_Event_API",
"callCustomEvent", "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; if (!RemoteCall::hasFunc(eventName, eventId)) return false;
switch (doHash(eventName)) { switch (doHash(eventName)) {
case doHash("onClientLogin"): { case doHash("onClientLogin"): {
auto Call = RemoteCall::importAs<bool( REGISTER_EVENT_LISTEN(
std::string const& realName, Event::PacketEvent::ClientLoginAfterEvent,
(std::string const& realName,
std::string const& uuid, std::string const& uuid,
std::string const& serverXuid, std::string const& serverXuid,
std::string const& clientXuid std::string const& clientXuid),
)>(eventName, eventId); (ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
eventBus->emplaceListener<Event::PacketEvent::ClientLoginAfterEvent>( logger.error("Event \"onClientLogin\" cannot be intercepted"),
[Call](Event::PacketEvent::ClientLoginAfterEvent& ev) {
try {
Call(
ev.getRealName(),
ev.getUuid().asString(),
ev.getServerAuthXuid(),
ev.getClientAuthXuid()
); );
} catch (...) {}
}
);
return true;
} }
case doHash("onWeatherChange"): { case doHash("onWeatherChange"): {
auto Call = REGISTER_EVENT_LISTEN(
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>( Event::LevelEvent::WeatherUpdateBeforeEvent,
eventName, (int lightningLevel, int rainLevel, int lightningLast, int rainLast),
eventId (ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
ev.cancel(),
); );
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();
}
}
);
return true;
} }
case doHash("onMobPick"): { case doHash("onMobPick"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::EntityEvent::MobPickupItemBeforeEvent>( Event::EntityEvent::MobPickupItemBeforeEvent,
[Call](Event::EntityEvent::MobPickupItemBeforeEvent& ev) { (Actor * mob, Actor * item),
bool result = true; (&ev.self(), (Actor*)&ev.getItemActor()),
try { ev.cancel(),
result = Call(&ev.self(), (Actor*)&ev.getItemActor());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
); );
return true;
} }
case doHash("onItemTrySpawn"): { case doHash("onItemTrySpawn"): {
auto Call = REGISTER_EVENT_LISTEN(
RemoteCall::importAs<bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>( Event::EntityEvent::ItemActorSpawnBeforeEvent,
eventName, (const ItemStack* item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
eventId (&ev.getItem(),
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
ev.cancel(),
); );
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();
}
}
);
return true;
} }
case doHash("onItemSpawned"): { case doHash("onItemSpawned"): {
auto Call = RemoteCall::importAs< REGISTER_EVENT_LISTEN(
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>( Event::EntityEvent::ItemActorSpawnAfterEvent,
eventName, (const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, int64 spawnerUniqueId),
eventId (&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 (...) {}
} }
case doHash("onEntityTryChangeDim"): {
REGISTER_EVENT_LISTEN(
Event::EntityEvent::ActorChangeDimensionBeforeEvent,
(Actor * entity, int toDimId),
(&ev.self(), ev.getToDimensionId()),
ev.cancel(),
); );
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();
}
}
);
return true;
} }
case doHash("onLeaveBed"): { case doHash("onLeaveBed"): {
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::PlayerEvent::PlayerStopSleepBeforeEvent>( Event::PlayerEvent::PlayerStopSleepBeforeEvent,
[Call](Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) { (Player * pl),
bool result = true; (&ev.self()),
try { ev.cancel(),
result = Call(&ev.self());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
); );
return true;
} }
case doHash("onDeathMessage"): { case doHash("onDeathMessage"): {
auto Call = REGISTER_EVENT_LISTEN(
RemoteCall::importAs<bool(std::string const& message, std::vector<std::string>, Actor* dead)>( Event::EntityEvent::DeathMessageAfterEvent,
eventName, (std::string const& message, std::vector<std::string>, Actor* dead),
eventId (ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()),
logger.error("Event \"onDeathMessage\" cannot be intercepted"),
); );
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 (...) {}
}
);
return true;
} }
case doHash("onMobHurted"): { case doHash("onMobHurted"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>( REGISTER_EVENT_LISTEN(
eventName, Event::EntityEvent::MobHurtAfterEvent,
eventId (Actor * mob, Actor * source, float damage, int cause),
); (&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()),
eventBus->emplaceListener<Event::EntityEvent::MobHurtAfterEvent>( logger.error("Event \"onMobHurted\" cannot be intercepted"),
[Call](Event::EntityEvent::MobHurtAfterEvent& ev) {
auto& damageSource = ev.getSource(); auto& damageSource = ev.getSource();
Actor* source = nullptr; Actor* source = nullptr;
if (damageSource.isEntitySource()) { if (damageSource.isEntitySource()) {
auto uniqueId = damageSource.getDamagingEntityUniqueID(); auto uniqueId = damageSource.getDamagingEntityUniqueID();
source = ll::service::getLevel()->fetchEntity(uniqueId); source = ll::service::getLevel()->fetchEntity(uniqueId);
if (source->getOwner()) { if (source->getOwner()) source = source->getOwner();
source = source->getOwner();
}
}
try {
Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause());
} catch (...) {}
} }
); );
return true;
} }
case doHash("onEndermanTake"): { case doHash("onEndermanTake"): {
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::EntityEvent::EndermanTakeBlockBeforeEvent>( Event::EntityEvent::EndermanTakeBlockBeforeEvent,
[Call](Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) { (Actor * mob),
bool result = true; (&ev.self()),
try { ev.cancel(),
result = Call(&ev.self());
} catch (...) {}
if (!result) {
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"): { case doHash("onDragonRespawn"): {
auto Call = RemoteCall::importAs<bool(int64 enderDragonUniqueID)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::EntityEvent::DragonRespawnBeforeEvent>( Event::EntityEvent::DragonRespawnBeforeEvent,
[Call](Event::EntityEvent::DragonRespawnBeforeEvent& ev) { (int64 enderDragonUniqueID),
bool result = true; (ev.getEnderDragon().id),
try { ev.cancel(),
result = Call(ev.getEnderDragon().id); )
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
} }
case doHash("onProjectileTryCreate"): { case doHash("onProjectileTryCreate"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateBeforeEvent>( Event::EntityEvent::ProjectileCreateBeforeEvent,
[Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) { (Actor * mob, int64 uniqueId),
bool result = true; (&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
try { ev.cancel(),
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
result = Call(&ev.self(), uid);
} catch (...) {}
if (!result) {
ev.cancel();
}
}
); );
return true;
} }
case doHash("onProjectileCreate"): { case doHash("onProjectileCreate"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateAfterEvent>( Event::EntityEvent::ProjectileCreateAfterEvent,
[Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) { (Actor * mob, int64 uniqueId),
try { (&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1; logger.error("Event \"onProjectileCreate\" cannot be intercepted"),
Call(&ev.self(), uid);
} catch (...) {}
}
); );
return true;
} }
case doHash("onSpawnWanderingTrader"): { case doHash("onSpawnWanderingTrader"): {
auto Call = RemoteCall::importAs<bool(std::pair<BlockPos, int> pos)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::EntityEvent::SpawnWanderingTraderBeforeEvent>( Event::EntityEvent::SpawnWanderingTraderBeforeEvent,
[Call](Event::EntityEvent::SpawnWanderingTraderBeforeEvent& ev) { (std::pair<BlockPos, int> pos),
bool result = true; ({ev.getPos(), ev.getRegion().getDimensionId()}),
try { ev.cancel(),
result = Call({ev.getPos(), ev.getRegion().getDimensionId()});
} catch (...) {}
if (!result) {
ev.cancel();
}
}
); );
return true;
} }
case doHash("onHandleRequestAction"): { case doHash("onHandleRequestAction"): {
auto Call = RemoteCall::importAs<bool( REGISTER_EVENT_LISTEN(Event::PlayerEvent::HandleRequestActionBeforeEvent,
Player * player, (Player * player,
std::string const& actionType, std::string const& actionType,
int count, int count,
std::string const& sourceContainerNetId, std::string const& sourceContainerNetId,
int sourceSlot, int sourceSlot,
std::string const& destinationContainerNetId, std::string const& destinationContainerNetId,
int destinationSlot int destinationSlot),
)>(eventName, eventId); ((Player*)&ev.self(),
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(), magic_enum::enum_name(requestAction->mActionType).data(),
ll::memory::dAccess<uchar>(requestAction, 18), (int)requestAction->mAmount,
magic_enum::enum_name(source.mOpenContainerNetId).data(), magic_enum::enum_name(requestAction->mSrc.mOpenContainerNetId).data(),
source.mSlot, (int)requestAction->mSrc.mSlot,
magic_enum::enum_name(destination.mOpenContainerNetId).data(), magic_enum::enum_name(requestAction->mDst.mOpenContainerNetId).data(),
destination.mSlot (int)requestAction->mDst.mSlot),
ev.cancel(),
auto requestAction = (ItemStackRequestActionTransferBase*)&ev.getRequestAction();
); );
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
} }
case doHash("onSendContainerClosePacket"): { case doHash("onSendContainerClosePacket"): {
auto Call = RemoteCall::importAs<bool(Player * player, int ContainerNetId)>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<Event::PacketEvent::ContainerClosePacketSendAfterEvent>( Event::PacketEvent::ContainerClosePacketSendAfterEvent,
[Call](Event::PacketEvent::ContainerClosePacketSendAfterEvent& ev) { (Player * player, int ContainerNetId),
try { (ev.getServerNetworkHandler()
Call(
ev.getServerNetworkHandler()
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId), .getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
(int)ev.getPacket().mContainerId (int)ev.getPacket().mContainerId),
); logger.error("Event \"onSendContainerClosePacket\" cannot be intercepted"),
} catch (...) {} )
}
);
return true;
} }
case doHash("onServerStopping"): { case doHash("onServerStopping"): {
auto Call = RemoteCall::importAs<bool()>(eventName, eventId); REGISTER_EVENT_LISTEN(
eventBus->emplaceListener<ll::event::server::ServerStoppingEvent>( ll::event::server::ServerStoppingEvent,
[Call](ll::event::server::ServerStoppingEvent& ev) { (),
try { (),
Call(); logger.error("Event \"onServerStopping\" cannot be intercepted"),
} catch (...) {}
}
); );
return true;
} }
default: default:
return false; return false;
+1 -1
View File
@@ -11,7 +11,7 @@ using namespace Mod;
#define LIB_VERSION_MAJOR 0 #define LIB_VERSION_MAJOR 0
#define LIB_VERSION_MINOR 13 #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) #define LIB_VERSION Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
+2 -10
View File
@@ -115,13 +115,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) { if (!level) {
return; return;
} }
JsonRecipe::registerSmithingTransformRecipe( JsonRecipe::registerSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result);
recipe_id,
smithing_template,
base,
addition,
result
);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -192,7 +186,5 @@ void Export_Legacy_GMLib_ModAPI() {
} }
return false; return false;
}); });
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void { RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void { VanillaFix::setFixI18nEnabled(); });
VanillaFix::setFixI18nEnabled();
});
} }
+4 -19
View File
@@ -15,9 +15,7 @@ bool isParameters(std::string const& str) {
std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from); } std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from); }
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) { std::string GetValueWithPlayer(std::string const& key, Player* player) { return PlaceholderAPI::getValue(key, player); }
return PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
}
bool registerPlayerPlaceholder( bool registerPlayerPlaceholder(
std::string const& PluginName, std::string const& PluginName,
@@ -38,11 +36,7 @@ bool registerPlayerPlaceholder(
); );
} else { } else {
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName); auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
PlaceholderAPI::registerPlayerPlaceholder( PlaceholderAPI::registerPlayerPlaceholder(PAPIName, [Call](Player* sp) { return Call(sp); }, PluginName);
PAPIName,
[Call](Player* sp) { return Call(sp); },
PluginName
);
} }
return true; return true;
} }
@@ -84,18 +78,9 @@ bool registerStaticPlaceholder(
if (isParameters(PAPIName)) { if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName); auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
if (num == -1) { if (num == -1) {
PlaceholderAPI::registerStaticPlaceholder( PlaceholderAPI::registerStaticPlaceholder(PAPIName, [Call] { return Call(); }, PluginName);
PAPIName,
[Call] { return Call(); },
PluginName
);
} else { } else {
PlaceholderAPI::registerStaticPlaceholder( PlaceholderAPI::registerStaticPlaceholder(PAPIName, num, [Call] { return Call(); }, PluginName);
PAPIName,
num,
[Call] { return Call(); },
PluginName
);
} }
} }
return true; return true;
+2 -2
View File
@@ -1,7 +1,7 @@
{ {
"format_version": 2, "format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "0.13.2", "version": "0.13.3",
"info": { "info": {
"name": "GMLIB-LegacyRemoteCallApi", "name": "GMLIB-LegacyRemoteCallApi",
"description": "Legacy RemoteCall API for GMLIB", "description": "Legacy RemoteCall API for GMLIB",
@@ -14,7 +14,7 @@
"library" "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": { "dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.13.0" "github.com/GroupMountain/GMLIB": ">=0.13.0"
}, },