Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeBryant114514 authored Apr 19, 2023
1 parent ca5d015 commit f31da34
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions LiteLoader/include/llapi/EventAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ copies or substantial portions of the Software.
#include "llapi/mc/AABB.hpp"
#include "llapi/mc/EnderDragon.hpp"
#include "llapi/mc/BlockLegacy.hpp"
#include "llapi/mc/ItemActor.hpp"
#include "llapi/mc/FishingHook.hpp"

class Actor;
class ServerPlayer;
Expand Down Expand Up @@ -229,6 +231,16 @@ class PlayerUseItemOnEvent : public EventTemplate<PlayerUseItemOnEvent> {
Vec3 mClickPos;
};

class PlayerPullFishingHookEvent : public EventTemplate<PlayerPullFishingHookEvent> {
public:

Player* mPlayer = nullptr;
FishingHook* mFishingHook = nullptr;
Actor* mActor = nullptr;
ItemActor* mItemActor = nullptr;
ItemStack* mItemStack = nullptr;
};

/**
* @brief An event that fires as players use bucket.
*
Expand Down
21 changes: 21 additions & 0 deletions LiteLoader/src/llapi/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ DECLARE_EVENT_DATA(FormResponsePacketEvent);
DECLARE_EVENT_DATA(ResourcePackInitEvent);
DECLARE_EVENT_DATA(PlayerOpenInventoryEvent);
DECLARE_EVENT_DATA(PlayerSwingEvent);
DECLARE_EVENT_DATA(PlayerPullFishingHookEvent);

#define IF_LISTENED(EVENT) \
if (EVENT::hasListener()) { \
Expand Down Expand Up @@ -2195,3 +2196,23 @@ TInstanceHook(void, "?openInventory@ServerPlayer@@UEAAXXZ", ServerPlayer) {
IF_LISTENED_END(PlayerOpenInventoryEvent)
original(this);
}

TInstanceHook(void, "?_pullCloser@FishingHook@@IEAAXAEAVActor@@M@Z", FishingHook, Actor* a, float b) {
if (this->getPlayerOwner()) {
IF_LISTENED(PlayerPullFishingHookEvent) {
PlayerPullFishingHookEvent ev{};
ev.mPlayer = this->getPlayerOwner();
ev.mFishingHook = this;
ev.mActor = a;
if (a->isItemActor()) {
ev.mItemActor = (ItemActor*)a;
ev.mItemStack = ((ItemActor*)a)->getItemStack();
}
if (!ev.call()) {
return;
}
}
IF_LISTENED_END(PlayerPullFishingHookEvent)
}
return original(this, a, b);
}
12 changes: 12 additions & 0 deletions ScriptEngine/src/api/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum class EVENT_TYPES : int {
onOpenContainer,
onCloseContainer,
onInventoryChange,
onPlayerPullFishingHook,
//onMove,
onChangeSprinting,
onSetArmor,
Expand Down Expand Up @@ -1145,6 +1146,17 @@ void EnableEventListener(int eventId) {
});
break;

case EVENT_TYPES::onPlayerPullFishingHook:
Event::PlayerPullFishingHookEvent::subscribe([](const PlayerPullFishingHookEvent& ev) {
IF_LISTENED(EVENT_TYPES::onPlayerPullFishingHook) {
CallEvent(EVENT_TYPES::onPlayerPullFishingHook, PlayerClass::newPlayer(ev.mPlayer),
ev.mActor ? EntityClass::newEntity(ev.mActor) : Local<Value>(), ev.mItemStack ? ItemClass::newItem(ev.mItemStack) : Local<Value>());
}
IF_LISTENED_END(EVENT_TYPES::onPlayerPullFishingHook);
return true;
});
break;

/* DEPRECATED AND RECENTLY REMOVED - END */

default:
Expand Down

0 comments on commit f31da34

Please sign in to comment.