Skip to content

Commit 04d3b6c

Browse files
committed
fix: fix trident consumption for onSpawnProjectile #143
1 parent 8f910fd commit 04d3b6c

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/legacy/api/EventAPI.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ inline std::string EventTypeToString(EVENT_TYPES e) { return std::string(magic_e
150150
lse::getSelfPluginInstance().getLogger().error("In Plugin: " + ENGINE_OWN_DATA()->pluginName); \
151151
}
152152

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

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

185-
// 调用事件监听函数,拦截返回
185+
// 调用事件监听函数,拦截则返回
186186
#define CallEventVoid(TYPE, ...) \
187187
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
188188
bool isCancelled = false; \

src/legacy/events/EventHooks.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <mc/world/actor/ArmorStand.h>
2727
#include <mc/world/actor/FishingHook.h>
2828
#include <mc/world/actor/Hopper.h>
29+
#include <mc/world/actor/VanillaActorRendererId.h>
2930
#include <mc/world/actor/boss/WitherBoss.h>
3031
#include <mc/world/actor/item/ItemActor.h>
3132
#include <mc/world/actor/player/Player.h>
@@ -35,6 +36,7 @@
3536
#include <mc/world/item/BucketItem.h>
3637
#include <mc/world/item/CrossbowItem.h>
3738
#include <mc/world/item/ItemInstance.h>
39+
#include <mc/world/item/TridentItem.h>
3840
#include <mc/world/item/registry/ItemStack.h>
3941
#include <mc/world/level/BlockEventCoordinator.h>
4042
#include <mc/world/level/BlockSource.h>
@@ -59,6 +61,7 @@
5961
#include <mc/world/phys/AABB.h>
6062
#include <mc/world/scores/ServerScoreboard.h>
6163

64+
6265
namespace lse::events {
6366

6467
// NOLINTBEGIN(modernize-use-trailing-return-type)
@@ -358,12 +361,14 @@ LL_TYPE_INSTANCE_HOOK(
358361
Vec3 const& direction
359362
) {
360363
IF_LISTENED(EVENT_TYPES::onSpawnProjectile) {
361-
CallEventRtnValue(
362-
EVENT_TYPES::onSpawnProjectile,
363-
nullptr,
364-
EntityClass::newEntity(spawner),
365-
String::newString(id.getCanonicalName())
366-
);
364+
if (id._getLegacyActorType() != ActorType::Trident) {
365+
CallEventRtnValue(
366+
EVENT_TYPES::onSpawnProjectile,
367+
nullptr,
368+
EntityClass::newEntity(spawner),
369+
String::newString(id.getCanonicalName())
370+
);
371+
}
367372
}
368373
IF_LISTENED_END(EVENT_TYPES::onSpawnProjectile);
369374
Actor* projectile = origin(region, id, spawner, position, direction);
@@ -398,6 +403,27 @@ LL_TYPE_INSTANCE_HOOK(
398403
origin(projectileInstance, player);
399404
}
400405

406+
LL_TYPE_INSTANCE_HOOK(
407+
ProjectileSpawnHook3,
408+
HookPriority::Normal,
409+
TridentItem,
410+
"?releaseUsing@TridentItem@@UEBAXAEAVItemStack@@PEAVPlayer@@H@Z",
411+
void,
412+
ItemStack& item,
413+
Player* player,
414+
int durationLeft
415+
) {
416+
IF_LISTENED(EVENT_TYPES::onSpawnProjectile) {
417+
CallEventVoid(
418+
EVENT_TYPES::onSpawnProjectile,
419+
EntityClass::newEntity(player),
420+
String::newString(VanillaActorRendererId::trident.getString())
421+
);
422+
}
423+
IF_LISTENED_END(EVENT_TYPES::onSpawnProjectile);
424+
origin(item, player, durationLeft);
425+
}
426+
401427
LL_TYPE_INSTANCE_HOOK(
402428
PressurePlateTriggerHook,
403429
HookPriority::Normal,
@@ -1141,7 +1167,8 @@ void PlayerUseFrameEvent() {
11411167
}
11421168
void ProjectileSpawnEvent() {
11431169
ProjectileSpawnHook1::hook();
1144-
ProjectileSpawnHook2 ::hook();
1170+
ProjectileSpawnHook2::hook();
1171+
ProjectileSpawnHook3::hook();
11451172
};
11461173
void ProjectileCreatedEvent() { ProjectileSpawnHook1::hook(); };
11471174
void PressurePlateTriggerEvent() { PressurePlateTriggerHook::hook(); }

0 commit comments

Comments
 (0)