Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeBryant114514 authored Mar 1, 2023
1 parent 91a5745 commit 4a08c29
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions LiteLoader/src/llapi/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ TInstanceHook(float, "?getDamageAfterResistanceEffect@Mob@@UEBAMAEBVActorDamageS
return original(this, src, damage);
}

//////////////// PlayerUseItem & PlayerEat ////////////////
//////////////// PlayerUseItem & PlayerEat&Ate ////////////////
#include "llapi/mc/ComponentItem.hpp"

TInstanceHook(bool, "?baseUseItem@GameMode@@QEAA_NAEAVItemStack@@@Z", GameMode, ItemStack& it) {
Expand All @@ -1554,19 +1554,28 @@ TInstanceHook(bool, "?baseUseItem@GameMode@@QEAA_NAEAVItemStack@@@Z", GameMode,
return false;
}
IF_LISTENED_END(PlayerUseItemEvent)
IF_LISTENED(PlayerEatEvent) {
if (it.getItem()->isFood() && (pl->isHungry() || pl->forceAllowEating())) {
return original(this, it);
}

TInstanceHook(void, "?eat@Player@@QEAAXAEBVItemStack@@@Z", Player, ItemStack* a1) {
IF_LISTENED(PlayerEatEvent) {
PlayerEatEvent ev{};
ev.mPlayer = pl;
ev.mFoodItem = ⁢
ev.mPlayer = this;
ev.mFoodItem = a1;
if (!ev.call()) {
pl->refreshAttribute(Player::HUNGER);
return false;
return;
}
}
}
IF_LISTENED_END(PlayerEatEvent)
return original(this, it);
IF_LISTENED_END(PlayerEatEvent)
original(this, a1);
IF_LISTENED(PlayerAteEvent) {
PlayerAteEvent ev{};
ev.mPlayer = this;
ev.mFoodItem = a1;
ev.call();
}
IF_LISTENED_END(PlayerAteEvent)
return;
}

TInstanceHook(ItemStack*, "?use@BucketItem@@UEBAAEAVItemStack@@AEAV2@AEAVPlayer@@@Z", BucketItem, ItemStack* a1,
Expand Down Expand Up @@ -1599,21 +1608,6 @@ TClasslessInstanceHook(ItemStack*, "?use@PotionItem@@UEBAAEAVItemStack@@AEAV2@AE
return original(this, a1, a2);
}

/////////////////// PlayerAte ////////////////////
#include "llapi/mc/FoodItemComponentLegacy.hpp"

TInstanceHook(Item*, "?useTimeDepleted@FoodItemComponentLegacy@@UEAAPEBVItem@@AEAVItemStack@@AEAVPlayer@@AEAVLevel@@@Z",
FoodItemComponentLegacy, ItemStack* a, Player* b, Level* c) {
IF_LISTENED(PlayerAteEvent) {
PlayerAteEvent ev{};
ev.mPlayer = b;
ev.mFoodItem = a;
ev.call();
}
IF_LISTENED_END(PlayerAteEvent)
return original(this, a, b, c);
}

/////////////////// MobDie ///////////////////
TInstanceHook(bool, "?die@Mob@@UEAAXAEBVActorDamageSource@@@Z", Mob, ActorDamageSource* ads) {
IF_LISTENED(MobDieEvent) {
Expand Down Expand Up @@ -2196,4 +2190,4 @@ TInstanceHook(void, "?openInventory@ServerPlayer@@UEAAXXZ", ServerPlayer) {
}
IF_LISTENED_END(PlayerOpenInventoryEvent)
original(this);
}
}

0 comments on commit 4a08c29

Please sign in to comment.