Skip to content

Commit b7779f4

Browse files
authored
fix: fix onAte event #222 (#223)
1 parent 2eeeef6 commit b7779f4

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/lse/events/EventHooks.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "mc/world/events/PlayerOpenContainerEvent.h"
7474
#include "mc/world/level/material/Material.h"
7575
#include "mc/world/level/dimension/Dimension.h"
76+
#include "mc/world/actor/player/PlayerItemInUse.h"
7677
#include "ll/api/thread/ThreadName.h"
7778

7879
namespace lse::events {
@@ -578,7 +579,7 @@ LL_TYPE_INSTANCE_HOOK(
578579
return shouldPush;
579580
}
580581

581-
LL_TYPE_INSTANCE_HOOK(PlayerEatHook, HookPriority::Normal, Player, &Player::eat, void, ItemStack const& instance) {
582+
LL_TYPE_INSTANCE_HOOK(PlayerEatHook1, HookPriority::Normal, Player, &Player::eat, void, ItemStack const& instance) {
582583
IF_LISTENED(EVENT_TYPES::onAte) {
583584
if (!CallEvent(
584585
EVENT_TYPES::onAte,
@@ -592,6 +593,26 @@ LL_TYPE_INSTANCE_HOOK(PlayerEatHook, HookPriority::Normal, Player, &Player::eat,
592593
origin(instance);
593594
}
594595

596+
LL_TYPE_INSTANCE_HOOK(
597+
PlayerEatHook2,
598+
HookPriority::Normal,
599+
ItemStack,
600+
&ItemStack::useTimeDepleted,
601+
::ItemUseMethod,
602+
Level* level,
603+
Player* player
604+
) {
605+
IF_LISTENED(EVENT_TYPES::onAte) {
606+
if (isPotionItem() || getTypeName() == "minecraft:milk_bucket") {
607+
if (!CallEvent(EVENT_TYPES::onAte, PlayerClass::newPlayer(player), ItemClass::newItem(this))) {
608+
return ItemUseMethod::Unknown;
609+
}
610+
}
611+
}
612+
IF_LISTENED_END(EVENT_TYPES::onAte);
613+
return origin(level, player);
614+
}
615+
595616
LL_TYPE_INSTANCE_HOOK(ExplodeHook, HookPriority::Normal, Level, &Level::$explode, bool, ::Explosion& explosion) {
596617
IF_LISTENED(EVENT_TYPES::onEntityExplode) {
597618
if (explosion.mSourceID->rawID != ActorUniqueID::INVALID_ID().rawID) {
@@ -1332,7 +1353,10 @@ void ActorRideEvent() { ActorRideHook::hook(); }
13321353
void WitherDestroyEvent() { WitherDestroyHook::hook(); }
13331354
void FarmDecayEvent() { FarmDecayHook::hook(); }
13341355
void PistonPushEvent() { PistonPushHook::hook(); }
1335-
void PlayerEatEvent() { PlayerEatHook::hook(); }
1356+
void PlayerEatEvent() {
1357+
PlayerEatHook1::hook();
1358+
PlayerEatHook2::hook();
1359+
}
13361360
void ExplodeEvent() { ExplodeHook::hook(); }
13371361
void RespawnAnchorExplodeEvent() { RespawnAnchorExplodeHook::hook(); }
13381362
void BlockExplodedEvent() { BlockExplodedHook ::hook(); }

0 commit comments

Comments
 (0)