Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 'RaidMobSpawnEvent' event #1229

Merged
merged 1 commit into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions LiteLoader/include/llapi/EventAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class BlockLegacy;
class ArmorStand;
class Objective;
struct ScoreboardId;
class Village;

/**
* @brief The event system.
Expand Down Expand Up @@ -713,6 +714,38 @@ class MobSpawnedEvent : public EventTemplate<MobSpawnedEvent> {
Vec3 mPos;
int mDimensionId = -1;
};
/**
* @brief An event that Raid mob spawn.
*
* @note This event cannot be suppressed.
*/
class RaidMobSpawnEvent : public EventTemplate<RaidMobSpawnEvent> {
public:

/**
* @brief Village Center generated by which village raid
*
*/
Vec3 mVillageCenter;

/**
* @brief Spawn Pos;
*
*/
Vec3 mPos;

/**
* @brief Raid spawn wave number
*
*/
int mWaveNum;

/**
* @brief Spawn Entity IDs;
*
*/
int mActorNum;
};

/* endregion */

Expand Down
16 changes: 16 additions & 0 deletions LiteLoader/src/llapi/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ DECLARE_EVENT_DATA(PlayerBedEnterEvent);
DECLARE_EVENT_DATA(ScriptPluginManagerEvent);
DECLARE_EVENT_DATA(MobTrySpawnEvent);
DECLARE_EVENT_DATA(MobSpawnedEvent);
DECLARE_EVENT_DATA(RaidMobSpawnEvent);
DECLARE_EVENT_DATA(FormResponsePacketEvent);
DECLARE_EVENT_DATA(ResourcePackInitEvent);
DECLARE_EVENT_DATA(PlayerOpenInventoryEvent);
Expand Down Expand Up @@ -2129,6 +2130,21 @@ TClasslessInstanceHook(void, "?_setRespawnStage@EndDragonFight@@AEAAXW4RespawnAn
IF_LISTENED_END(MobSpawnedEvent)
}
}
#include "llapi/mc/Village.hpp"
TInstanceHook(void,"?_spawnRaidGroup@Village@@AEBA_NVVec3@@EAEAV?$unordered_set@UActorUniqueID@@U?$hash@UActorUniqueID@@@std@@U?$equal_to@UActorUniqueID@@@3@V?$allocator@UActorUniqueID@@@3@@std@@@Z",
Village, Vec3 pos, unsigned char num, std::unordered_set<long long> &actorIDs){
// actorIDs其实是std::unordered_set<ActorUniqueID>,懒得写hash函数
original(this,pos,num,actorIDs);
IF_LISTENED(RaidMobSpawnEvent) {
RaidMobSpawnEvent ev{};
ev.mVillageCenter = this->getCenter();
ev.mPos = pos;
ev.mWaveNum = num;
ev.mActorNum = actorIDs.size();
ev.call();
}
IF_LISTENED_END(RaidMobSpawnEvent)
}

#include "llapi/impl/FormPacketHelper.h"
#include "llapi/mc/Json.hpp"
Expand Down
11 changes: 11 additions & 0 deletions ScriptEngine/src/api/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ enum class EVENT_TYPES : int {
/* Entity Events */
onMobDie,
onMobHurt,
onRaidMobSpawn,
onEntityExplode,
onProjectileHitEntity,
onWitherBossDestroy,
Expand Down Expand Up @@ -839,6 +840,16 @@ void EnableEventListener(int eventId) {
});
break;

case EVENT_TYPES::onRaidMobSpawn:
Event::RaidMobSpawnEvent::subscribe([](const RaidMobSpawnEvent& ev) {
IF_LISTENED(EVENT_TYPES::onRaidMobSpawn) {
CallEvent(EVENT_TYPES::onRaidMobSpawn, IntPos::newPos(ev.mVillageCenter), IntPos::newPos(ev.mPos),
Number::newNumber(ev.mWaveNum), Number::newNumber(ev.mActorNum));
}
IF_LISTENED_END(EVENT_TYPES::onRaidMobSpawn)
});
break;

case EVENT_TYPES::onStepOnPressurePlate:
Event::EntityStepOnPressurePlateEvent::subscribe([](const EntityStepOnPressurePlateEvent& ev) {
IF_LISTENED(EVENT_TYPES::onStepOnPressurePlate) {
Expand Down