4747#include " lse/events/OtherEvents.h"
4848#include " lse/events/PlayerEvents.h"
4949#include " main/Global.h"
50- #include " mc/legacy/ActorRuntimeID.h"
51- #include " mc/deps/core/string/HashedString.h"
50+ #include " mc/legacy/ActorUniqueID.h"
5251#include " mc/server/commands/CommandOriginType.h"
53- #include " mc/world/actor/ActorType.h"
5452#include " mc/world/actor/player/Player.h"
53+ #include " mc/world/attribute/AttributeInstance.h"
5554#include " mc/world/item/Item.h"
5655#include " mc/world/item/VanillaItemNames.h"
5756#include " mc/world/level/dimension/Dimension.h"
@@ -236,6 +235,7 @@ void EnableEventListener(int eventId) {
236235 IF_LISTENED (EVENT_TYPES::onPlayerDie) {
237236 Actor* source = ll::service::getLevel ()
238237 ->getDimension (ev.self ().getDimensionId ())
238+ .lock ()
239239 ->fetchEntity (ev.source ().getEntityUniqueID (), false );
240240 CallEvent (
241241 EVENT_TYPES::onPlayerDie,
@@ -466,15 +466,17 @@ void EnableEventListener(int eventId) {
466466 case EVENT_TYPES::onEat:
467467 bus.emplaceListener <PlayerUseItemEvent>([](PlayerUseItemEvent& ev) {
468468 IF_LISTENED (EVENT_TYPES::onEat) {
469- if ((ev.item ().getItem ()->isFood () || ev.item ().isPotionItem ()
470- || ev.item ().getTypeName () == VanillaItemNames::MilkBucket ().getString ())
471- && (ev.self ().isHungry () || ev.self ().forceAllowEating ())) {
472- if (!CallEvent (
473- EVENT_TYPES::onEat,
474- PlayerClass::newPlayer (&ev.self ()),
475- ItemClass::newItem (&ev.item ())
476- )) {
477- ev.cancel ();
469+ if (ev.item ().getItem ()->isFood () || ev.item ().isPotionItem ()
470+ || ev.item ().getTypeName () == VanillaItemNames::MilkBucket ().getString ()) {
471+ auto attribute = ev.self ().getAttribute (Player::HUNGER ());
472+ if (attribute.mCurrentMaxValue > attribute.mCurrentValue ) {
473+ if (!CallEvent (
474+ EVENT_TYPES::onEat,
475+ PlayerClass::newPlayer (&ev.self ()),
476+ ItemClass::newItem (&ev.item ())
477+ )) {
478+ ev.cancel ();
479+ }
478480 }
479481 }
480482 }
@@ -560,7 +562,7 @@ void EnableEventListener(int eventId) {
560562 EVENT_TYPES::onMobDie,
561563 EntityClass::newEntity (&ev.self ()),
562564 (source ? EntityClass::newEntity (source) : Local<Value>()),
563- Number::newNumber ((int )ev.source ().getCause () )
565+ Number::newNumber ((int )ev.source ().mCause )
564566 ); // Not cancellable
565567 }
566568 IF_LISTENED_END (EVENT_TYPES::onMobDie);
@@ -668,7 +670,7 @@ void EnableEventListener(int eventId) {
668670 IF_LISTENED (EVENT_TYPES::onMobSpawn) {
669671 CallEvent (
670672 EVENT_TYPES::onMobSpawn,
671- String::newString (ev.identifier ().getFullName () ),
673+ String::newString (ev.identifier ().mFullName ),
672674 FloatPos::newPos (ev.pos (), ev.blockSource ().getDimensionId ())
673675 ); // Not cancellable
674676 }
@@ -681,7 +683,7 @@ void EnableEventListener(int eventId) {
681683 IF_LISTENED (EVENT_TYPES::onMobTrySpawn) {
682684 if (!CallEvent (
683685 EVENT_TYPES::onMobTrySpawn,
684- String::newString (ev.identifier ().getFullName () ),
686+ String::newString (ev.identifier ().mFullName ),
685687 FloatPos::newPos (ev.pos (), ev.blockSource ().getDimensionId ())
686688 )) {
687689 ev.cancel ();
@@ -745,7 +747,7 @@ void InitBasicEventListeners() {
745747 EventBus& bus = EventBus::getInstance ();
746748
747749 bus.emplaceListener <ExecutingCommandEvent>([](ExecutingCommandEvent& ev) {
748- auto originType = ev.commandContext ().getCommandOrigin (). getOriginType ();
750+ auto originType = ev.commandContext ().mOrigin -> getOriginType ();
749751 if (originType == CommandOriginType::DedicatedServer) {
750752 std::string cmd = ev.commandContext ().mCommand ;
751753 if (cmd.starts_with (" /" )) {
0 commit comments