Skip to content

Commit

Permalink
fix: fix trident consumption for onSpawnProjectile #143
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Jul 14, 2024
1 parent 8f910fd commit 04d3b6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/legacy/api/EventAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ inline std::string EventTypeToString(EVENT_TYPES e) { return std::string(magic_e
lse::getSelfPluginInstance().getLogger().error("In Plugin: " + ENGINE_OWN_DATA()->pluginName); \
}

// 调用事件监听函数,取消事件
// 调用事件监听函数,拦截则取消事件
#define CallEvent(TYPE, ...) \
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
for (auto& listener : nowList) { \
Expand All @@ -164,7 +164,7 @@ inline std::string EventTypeToString(EVENT_TYPES e) { return std::string(magic_e
LISTENER_CATCH(TYPE) \
}

// 调用事件监听函数,拦截返回RETURN_VALUE
// 调用事件监听函数,拦截则返回RETURN_VALUE
#define CallEventRtnValue(TYPE, RETURN_VALUE, ...) \
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
bool isCancelled = false; \
Expand All @@ -182,7 +182,7 @@ inline std::string EventTypeToString(EVENT_TYPES e) { return std::string(magic_e
return RETURN_VALUE; \
}

// 调用事件监听函数,拦截返回
// 调用事件监听函数,拦截则返回
#define CallEventVoid(TYPE, ...) \
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
bool isCancelled = false; \
Expand Down
41 changes: 34 additions & 7 deletions src/legacy/events/EventHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <mc/world/actor/ArmorStand.h>
#include <mc/world/actor/FishingHook.h>
#include <mc/world/actor/Hopper.h>
#include <mc/world/actor/VanillaActorRendererId.h>
#include <mc/world/actor/boss/WitherBoss.h>
#include <mc/world/actor/item/ItemActor.h>
#include <mc/world/actor/player/Player.h>
Expand All @@ -35,6 +36,7 @@
#include <mc/world/item/BucketItem.h>
#include <mc/world/item/CrossbowItem.h>
#include <mc/world/item/ItemInstance.h>
#include <mc/world/item/TridentItem.h>
#include <mc/world/item/registry/ItemStack.h>
#include <mc/world/level/BlockEventCoordinator.h>
#include <mc/world/level/BlockSource.h>
Expand All @@ -59,6 +61,7 @@
#include <mc/world/phys/AABB.h>
#include <mc/world/scores/ServerScoreboard.h>


namespace lse::events {

// NOLINTBEGIN(modernize-use-trailing-return-type)
Expand Down Expand Up @@ -358,12 +361,14 @@ LL_TYPE_INSTANCE_HOOK(
Vec3 const& direction
) {
IF_LISTENED(EVENT_TYPES::onSpawnProjectile) {
CallEventRtnValue(
EVENT_TYPES::onSpawnProjectile,
nullptr,
EntityClass::newEntity(spawner),
String::newString(id.getCanonicalName())
);
if (id._getLegacyActorType() != ActorType::Trident) {
CallEventRtnValue(
EVENT_TYPES::onSpawnProjectile,
nullptr,
EntityClass::newEntity(spawner),
String::newString(id.getCanonicalName())
);
}
}
IF_LISTENED_END(EVENT_TYPES::onSpawnProjectile);
Actor* projectile = origin(region, id, spawner, position, direction);
Expand Down Expand Up @@ -398,6 +403,27 @@ LL_TYPE_INSTANCE_HOOK(
origin(projectileInstance, player);
}

LL_TYPE_INSTANCE_HOOK(
ProjectileSpawnHook3,
HookPriority::Normal,
TridentItem,
"?releaseUsing@TridentItem@@UEBAXAEAVItemStack@@PEAVPlayer@@H@Z",
void,
ItemStack& item,
Player* player,
int durationLeft
) {
IF_LISTENED(EVENT_TYPES::onSpawnProjectile) {
CallEventVoid(
EVENT_TYPES::onSpawnProjectile,
EntityClass::newEntity(player),
String::newString(VanillaActorRendererId::trident.getString())
);
}
IF_LISTENED_END(EVENT_TYPES::onSpawnProjectile);
origin(item, player, durationLeft);
}

LL_TYPE_INSTANCE_HOOK(
PressurePlateTriggerHook,
HookPriority::Normal,
Expand Down Expand Up @@ -1141,7 +1167,8 @@ void PlayerUseFrameEvent() {
}
void ProjectileSpawnEvent() {
ProjectileSpawnHook1::hook();
ProjectileSpawnHook2 ::hook();
ProjectileSpawnHook2::hook();
ProjectileSpawnHook3::hook();
};
void ProjectileCreatedEvent() { ProjectileSpawnHook1::hook(); };
void PressurePlateTriggerEvent() { PressurePlateTriggerHook::hook(); }
Expand Down

0 comments on commit 04d3b6c

Please sign in to comment.