diff --git a/src-server/ll/api/event/player/PlayerConnectEvent.cpp b/src-server/ll/api/event/player/PlayerConnectEvent.cpp index bfd68d9039..760e8595b7 100644 --- a/src-server/ll/api/event/player/PlayerConnectEvent.cpp +++ b/src-server/ll/api/event/player/PlayerConnectEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/player/PlayerConnectEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/network/ServerNetworkHandler.h" @@ -10,8 +11,8 @@ namespace ll::event::inline player { void PlayerConnectEvent::serialize(CompoundTag& nbt) const { Cancellable::serialize(nbt); - nbt["networkIdentifier"] = (uintptr_t)&networkIdentifier(); - nbt["connectionRequest"] = (uintptr_t)&connectionRequest(); + nbt["networkIdentifier"] = serializeRefObj(networkIdentifier()); + nbt["connectionRequest"] = serializeRefObj(connectionRequest()); } NetworkIdentifier const& PlayerConnectEvent::networkIdentifier() const { return mNetworkIdentifier; } diff --git a/src-server/ll/api/event/server/ServerStartedEvent.cpp b/src-server/ll/api/event/server/ServerStartedEvent.cpp index 19b3084250..a98c31a385 100644 --- a/src-server/ll/api/event/server/ServerStartedEvent.cpp +++ b/src-server/ll/api/event/server/ServerStartedEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/server/ServerStartedEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/world/events/ServerInstanceEventCoordinator.h" @@ -10,7 +11,7 @@ namespace ll::event::inline server { void ServerStartedEvent::serialize(CompoundTag& nbt) const { Event::serialize(nbt); - nbt["server"] = (uintptr_t)&server(); + nbt["server"] = serializeRefObj(server()); } ServerInstance& ServerStartedEvent::server() const { return mInstance; } diff --git a/src-server/ll/api/event/server/ServerStoppingEvent.cpp b/src-server/ll/api/event/server/ServerStoppingEvent.cpp index d68a3abc80..d64c39ac45 100644 --- a/src-server/ll/api/event/server/ServerStoppingEvent.cpp +++ b/src-server/ll/api/event/server/ServerStoppingEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/server/ServerStoppingEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -8,7 +9,7 @@ namespace ll::event::inline server { void ServerStoppingEvent::serialize(CompoundTag& nbt) const { Event::serialize(nbt); - nbt["server"] = (uintptr_t)&server(); + nbt["server"] = serializeRefObj(server()); } ServerInstance& ServerStoppingEvent::server() const { return mServer; } diff --git a/src-test/server/EventTest.cpp b/src-test/server/EventTest.cpp index d0f0e54e03..61ba1fd000 100644 --- a/src-test/server/EventTest.cpp +++ b/src-test/server/EventTest.cpp @@ -1,34 +1,19 @@ #include "ll/api/event/Cancellable.h" #include "ll/api/event/EventBus.h" +#include "ll/api/io/PatternFormatter.h" +#include "ll/api/io/Sink.h" #include "ll/api/memory/Hook.h" +#include "ll/api/thread/ServerThreadExecutor.h" #include "ll/api/utils/ErrorUtils.h" +#include "ll/api/utils/StringUtils.h" #include "ll/core/LeviLamina.h" +#include "mc/network/packet/TextPacket.h" #include "mc/server/ServerInstance.h" #include "mc/world/events/ServerInstanceEventCoordinator.h" #include "ll/api/event/DynamicListener.h" #include "ll/api/event/Emitter.h" #include "ll/api/event/MultiListener.h" -#include "ll/api/event/command/ExecuteCommandEvent.h" -#include "ll/api/event/entity/ActorHurtEvent.h" -#include "ll/api/event/player/PlayerAddExperienceEvent.h" -#include "ll/api/event/player/PlayerAttackEvent.h" -#include "ll/api/event/player/PlayerConnectEvent.h" -#include "ll/api/event/player/PlayerDestroyBlockEvent.h" -#include "ll/api/event/player/PlayerDieEvent.h" -#include "ll/api/event/player/PlayerDisconnectEvent.h" -#include "ll/api/event/player/PlayerInteractBlockEvent.h" -#include "ll/api/event/player/PlayerJoinEvent.h" -#include "ll/api/event/player/PlayerJumpEvent.h" -#include "ll/api/event/player/PlayerPickUpItemEvent.h" -#include "ll/api/event/player/PlayerPlaceBlockEvent.h" -#include "ll/api/event/player/PlayerRespawnEvent.h" -#include "ll/api/event/player/PlayerSneakEvent.h" -#include "ll/api/event/player/PlayerSprintEvent.h" -#include "ll/api/event/player/PlayerSwingEvent.h" -#include "ll/api/event/player/PlayerUseItemEvent.h" -#include "ll/api/event/world/BlockChangedEvent.h" -#include "ll/api/event/world/SpawnMobEvent.h" #include "ll/api/io/FileUtils.h" #include "mc/deps/core/utility/MCRESULT.h" #include "mc/nbt/CompoundTag.h" @@ -132,88 +117,33 @@ LL_AUTO_TYPE_INSTANCE_HOOK( using namespace ll::event; - bus.emplaceListener([](ExecutingCommandEvent& ev) { - ll::getLogger().debug("ExecutingCommandEvent: {}", ev.commandContext().mCommand); - ll::getLogger().debug("origin: {}", ev.commandContext().mOrigin->serialize().toSnbt()); - }); - bus.emplaceListener([](ExecutedCommandEvent& ev) { - ll::getLogger().debug("ExecutedCommandEvent: {}", ev.commandContext().mCommand); - ll::getLogger().debug("result: {}", ev.result().getFullCode()); - }); - bus.emplaceListener([](PlayerConnectEvent& ev) { - ll::getLogger().debug("Player connect: {} {}", ev.self().getRealName(), ev.self().getIPAndPort()); - }); - bus.emplaceListener([](PlayerJoinEvent& ev) { - ll::getLogger().debug("Player join: {} {}", ev.self().getRealName(), ev.self().getLocaleCode()); - }); - bus.emplaceListener([](PlayerDisconnectEvent& ev) { - ll::getLogger().debug("Player leave: {}", ev.self().getRealName()); - }); - bus.emplaceListener([](PlayerAttackEvent& ev) { - ll::getLogger().debug( - "Player {} attack {} cause {}", - ev.self().getRealName(), - ev.target().getTypeName(), - magic_enum::enum_name(ev.cause()) - ); - }); - bus.emplaceListener([](PlayerDieEvent& ev) { - ll::getLogger() - .debug("Player {} died source {}", ev.self().getRealName(), magic_enum::enum_name(ev.source().getCause())); - }); - bus.emplaceListener([](PlayerRespawnEvent& ev) { - ll::getLogger().debug("Player {} respawned", ev.self().getRealName()); - }); - bus.emplaceListener([](PlayerJumpEvent& ev) { - ll::getLogger().debug("Player {} jumped", ev.self().getRealName()); - }); - bus.emplaceListener([](PlayerAddExperienceEvent& ev) { - ll::getLogger().debug("Player {} add experience {}", ev.self().getRealName(), ev.experience()); - if (ev.experience() == 114514) { - ev.cancel(); - } - }); - bus.emplaceListener([](PlayerPickUpItemEvent& ev) { - ll::getLogger().debug("Player {} take {}", ev.self().getRealName(), ev.itemActor().item().getTypeName()); - }); - bus.emplaceListener([](PlayerSwingEvent& ev) { - ll::getLogger().debug("Player {} left click", ev.self().getRealName()); - }); - auto listenersp = Listener::create([](PlayerSprintEvent& ev) { - switch (ev.getId().hash) { - case ll::event::getEventId.hash: { - ll::getLogger().debug("Player {} start sprint", ev.self().getRealName()); - } break; - case ll::event::getEventId.hash: { - ll::getLogger().debug("Player {} stop sprint", ev.self().getRealName()); - } break; - default: - break; + std::vector> ids; + for (auto [modName, id] : bus.events()) { + ids.emplace_back(std::string{modName}, id); + } + for (auto [modName, id] : ids) { + if (!id.name.ends_with("::LevelTickEvent")) + bus.addListener( + DynamicListener::create([modName](CompoundTag& nbt) { + ll::getLogger().debug("event from {}, {}", modName, nbt.toSnbt(SnbtFormat::PrettyChatPrint)); + }), + id + ); + } + + class BroadcastSink : public ll::io::Sink { + public: + BroadcastSink() : Sink(ll::makePolymorphic("<{tit}|{lvl}> [{tm:%T}] {msg}")) {} + + void append(ll::io::LogMessageView const& view) override { + std::string buffer; + formatter->format(view, buffer); + ll::thread::ServerThreadExecutor::getDefault().execute( + [pkt = TextPacket::createRawMessage(ll::string_utils::replaceAnsiToMcCode(buffer))] { + pkt.sendToClients(); + } + ); } - }); - bus.addListener(listenersp); - bus.addListener(listenersp); - auto mul = MultiListener::create([](auto&& ev) { - ll::getLogger() - .debug("Player {} MultiListener of {}", ev.self().getRealName(), ll::reflection::type_raw_name_v); - }); - bus.addListener(mul); - - auto dl = DynamicListener::create([](CompoundTag& nbt) { - // nbt["cancelled"] = true; - ll::getLogger().debug("{}", nbt.toSnbt(SnbtFormat::PrettyConsolePrint)); - }); - - - bus.addListener(dl, getEventId); - bus.addListener(dl, getEventId); - bus.addListener(dl, getEventId); - bus.addListener(dl, getEventId); - bus.addListener(dl, getEventId); - bus.addListener(dl, getEventId); - - bus.emplaceListener([](BlockChangedEvent& ev) { - ll::getLogger() - .debug("Block Changed Pos: {} Dimension: {}", ev.pos().toString(), ev.blockSource().getDimensionId().id); - }); + }; + ll::getLogger().addSink(std::make_shared()); } diff --git a/src/ll/api/event/Cancellable.h b/src/ll/api/event/Cancellable.h index df78c1278f..3306baef71 100644 --- a/src/ll/api/event/Cancellable.h +++ b/src/ll/api/event/Cancellable.h @@ -22,8 +22,8 @@ class Cancellable : public T { Event::serializeWithCancel(nbt); } void deserialize(CompoundTag const& nbt) override { - T::deserialize(nbt); Event::deserializeWithCancel(nbt); + T::deserialize(nbt); } [[nodiscard]] constexpr bool isCancelled() { return Event::mCancelled; } diff --git a/src/ll/api/event/EventId.h b/src/ll/api/event/EventId.h index 9d39d63dae..c223862472 100644 --- a/src/ll/api/event/EventId.h +++ b/src/ll/api/event/EventId.h @@ -1,6 +1,6 @@ #pragma once -#include "ll/api/reflection/Reflection.h" +#include "ll/api/reflection/TypeName.h" #include "ll/api/utils/HashUtils.h" namespace ll::event { @@ -34,7 +34,7 @@ constexpr EventIdView getEventId = []() -> EventIdView { return self::CustomEventId; } else { static_assert(std::is_final_v, "Only final classes can use getEventId"); - return EventIdView{ll::reflection::type_unprefix_name_v}; + return EventIdView{reflection::type_unprefix_name_v}; } }(); } // namespace ll::event diff --git a/src/ll/api/event/EventRefObjSerializer.h b/src/ll/api/event/EventRefObjSerializer.h new file mode 100644 index 0000000000..e4b5c23150 --- /dev/null +++ b/src/ll/api/event/EventRefObjSerializer.h @@ -0,0 +1,31 @@ +#pragma once + +#include "ll/api/reflection/TypeName.h" +#include "mc/nbt/CompoundTag.h" + +namespace ll::event { +template +[[nodiscard]] inline ::CompoundTag serializeRefObj(T& obj) { + return ::CompoundTag{ + {"_nullable_", false}, + { "_pointer_", (uintptr_t)std::addressof(obj)}, + { "_type_", reflection::type_unprefix_name_v>}, + { "_isconst_", std::is_const_v}, + }; +} +template +[[nodiscard]] inline ::CompoundTag serializePtrObj(T* ptr) { + return ::CompoundTag{ + {"_nullable_", true}, + { "_pointer_", (uintptr_t)ptr}, + { "_type_", reflection::type_unprefix_name_v>}, + { "_isconst_", std::is_const_v}, + }; +} +[[nodiscard]] inline bool isEventSerializedObj(::CompoundTag const& tag) { + return tag.contains("_type_") && tag.contains("_pointer_"); +} +[[nodiscard]] inline bool isEventSerializedObj(::CompoundTagVariant const& tag) { + return tag.is_object() ? isEventSerializedObj(tag.get<::CompoundTag>()) : false; +} +} // namespace ll::event diff --git a/src/ll/api/event/command/ExecuteCommandEvent.cpp b/src/ll/api/event/command/ExecuteCommandEvent.cpp index 400c4029e4..229b0df108 100644 --- a/src/ll/api/event/command/ExecuteCommandEvent.cpp +++ b/src/ll/api/event/command/ExecuteCommandEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/command/ExecuteCommandEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/common/Globals.h" @@ -9,8 +10,8 @@ namespace ll::event::inline command { void ExecuteCommandEvent::serialize(CompoundTag& nbt) const { Event::serialize(nbt); - nbt["minecraftCommands"] = (uintptr_t)&minecraftCommands(); - nbt["commandContext"] = (uintptr_t)&commandContext(); + nbt["minecraftCommands"] = serializeRefObj(minecraftCommands()); + nbt["commandContext"] = serializeRefObj(commandContext()); nbt["suppressOutput"] = suppressOutput(); } void ExecutingCommandEvent::deserialize(CompoundTag const& nbt) { @@ -19,7 +20,10 @@ void ExecutingCommandEvent::deserialize(CompoundTag const& nbt) { } void ExecutedCommandEvent::serialize(CompoundTag& nbt) const { ExecuteCommandEvent::serialize(nbt); - nbt["result"] = (uintptr_t)&result(); + nbt["result"] = CompoundTag{ + {"success", result().mSuccess}, + { "code", result().mCode}, + }; } MinecraftCommands& ExecuteCommandEvent::minecraftCommands() const { return mMinecraftCommands; } diff --git a/src/ll/api/event/entity/ActorEvent.cpp b/src/ll/api/event/entity/ActorEvent.cpp index 710efb1445..aff59108c3 100644 --- a/src/ll/api/event/entity/ActorEvent.cpp +++ b/src/ll/api/event/entity/ActorEvent.cpp @@ -1,4 +1,5 @@ #include "ll/api/event/entity/ActorEvent.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "mc/nbt/CompoundTag.h" @@ -6,7 +7,7 @@ namespace ll::event::inline entity { void ActorEvent::serialize(CompoundTag& nbt) const { Event::serialize(nbt); - nbt["self"] = (uintptr_t)&self(); + nbt["self"] = serializeRefObj(self()); } Actor& ActorEvent::self() const { return mSelf; } diff --git a/src/ll/api/event/entity/ActorHurtEvent.cpp b/src/ll/api/event/entity/ActorHurtEvent.cpp index a41e1b3c1b..d3effb309c 100644 --- a/src/ll/api/event/entity/ActorHurtEvent.cpp +++ b/src/ll/api/event/entity/ActorHurtEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/entity/ActorHurtEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -8,7 +9,7 @@ namespace ll::event::inline entity { void ActorHurtEvent::serialize(CompoundTag& nbt) const { Cancellable::serialize(nbt); - nbt["source"] = (uintptr_t)&source(); + nbt["source"] = serializeRefObj(source()); nbt["damage"] = damage(); nbt["knock"] = knock(); nbt["ignite"] = ignite(); diff --git a/src/ll/api/event/entity/MobDieEvent.cpp b/src/ll/api/event/entity/MobDieEvent.cpp index ee635e0a63..f0537cc221 100644 --- a/src/ll/api/event/entity/MobDieEvent.cpp +++ b/src/ll/api/event/entity/MobDieEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/entity/MobDieEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -8,7 +9,7 @@ namespace ll::event::inline entity { void MobDieEvent::serialize(CompoundTag& nbt) const { MobEvent::serialize(nbt); - nbt["source"] = (uintptr_t)&source(); + nbt["source"] = serializeRefObj(source()); } ActorDamageSource const& MobDieEvent::source() const { return mSource; } diff --git a/src/ll/api/event/entity/MobEvent.cpp b/src/ll/api/event/entity/MobEvent.cpp index 2c306a9f22..ebece79737 100644 --- a/src/ll/api/event/entity/MobEvent.cpp +++ b/src/ll/api/event/entity/MobEvent.cpp @@ -1,7 +1,15 @@ #include "ll/api/event/entity/MobEvent.h" +#include "ll/api/event/EventRefObjSerializer.h" + +#include "mc/nbt/CompoundTag.h" namespace ll::event::inline entity { +void MobEvent::serialize(CompoundTag& nbt) const { + ActorEvent::serialize(nbt); + nbt["self"] = serializeRefObj(self()); +} + Mob& MobEvent::self() const { return static_cast(ActorEvent::self()); } } // namespace ll::event::inline entity diff --git a/src/ll/api/event/entity/MobEvent.h b/src/ll/api/event/entity/MobEvent.h index 795cf381aa..645cc51aab 100644 --- a/src/ll/api/event/entity/MobEvent.h +++ b/src/ll/api/event/entity/MobEvent.h @@ -11,6 +11,8 @@ class MobEvent : public ActorEvent { constexpr explicit MobEvent(Mob& mob) : ActorEvent(mob) {} public: + LLAPI void serialize(CompoundTag&) const override; + LLNDAPI Mob& self() const; }; } // namespace ll::event::inline entity diff --git a/src/ll/api/event/player/PlayerAttackEvent.cpp b/src/ll/api/event/player/PlayerAttackEvent.cpp index 14a7819df4..20c2b29496 100644 --- a/src/ll/api/event/player/PlayerAttackEvent.cpp +++ b/src/ll/api/event/player/PlayerAttackEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/player/PlayerAttackEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -8,7 +9,7 @@ namespace ll::event::inline player { void PlayerAttackEvent::serialize(CompoundTag& nbt) const { Cancellable::serialize(nbt); - nbt["target"] = (uintptr_t)&target(); + nbt["target"] = serializeRefObj(target()); nbt["cause"] = magic_enum::enum_name(cause()); } diff --git a/src/ll/api/event/player/PlayerDieEvent.cpp b/src/ll/api/event/player/PlayerDieEvent.cpp index 6dc8d63432..4d6d03409e 100644 --- a/src/ll/api/event/player/PlayerDieEvent.cpp +++ b/src/ll/api/event/player/PlayerDieEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/player/PlayerDieEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -8,7 +9,7 @@ namespace ll::event::inline player { void PlayerDieEvent::serialize(CompoundTag& nbt) const { PlayerEvent::serialize(nbt); - nbt["source"] = (uintptr_t)&source(); + nbt["source"] = serializeRefObj(source()); } ActorDamageSource const& PlayerDieEvent::source() const { return mSource; } diff --git a/src/ll/api/event/player/PlayerEvent.cpp b/src/ll/api/event/player/PlayerEvent.cpp index b4495be466..c40433ee5f 100644 --- a/src/ll/api/event/player/PlayerEvent.cpp +++ b/src/ll/api/event/player/PlayerEvent.cpp @@ -1,7 +1,15 @@ #include "ll/api/event/player/PlayerEvent.h" +#include "ll/api/event/EventRefObjSerializer.h" + +#include "mc/nbt/CompoundTag.h" namespace ll::event::inline player { +void PlayerEvent::serialize(CompoundTag& nbt) const { + MobEvent::serialize(nbt); + nbt["self"] = serializeRefObj(self()); +} + Player& PlayerEvent::self() const { return static_cast(MobEvent::self()); } } // namespace ll::event::inline player diff --git a/src/ll/api/event/player/PlayerEvent.h b/src/ll/api/event/player/PlayerEvent.h index e332503d92..7660bbfd65 100644 --- a/src/ll/api/event/player/PlayerEvent.h +++ b/src/ll/api/event/player/PlayerEvent.h @@ -11,6 +11,8 @@ class PlayerEvent : public MobEvent { constexpr explicit PlayerEvent(Player& player) : MobEvent(player) {} public: + LLAPI void serialize(CompoundTag&) const override; + LLNDAPI Player& self() const; }; } // namespace ll::event::inline player diff --git a/src/ll/api/event/player/PlayerInteractBlockEvent.cpp b/src/ll/api/event/player/PlayerInteractBlockEvent.cpp index f9b0b584ac..0b8120ee06 100644 --- a/src/ll/api/event/player/PlayerInteractBlockEvent.cpp +++ b/src/ll/api/event/player/PlayerInteractBlockEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/player/PlayerInteractBlockEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/world/gamemode/GameMode.h" @@ -11,13 +12,11 @@ namespace ll::event::inline player { void PlayerInteractBlockEvent::serialize(CompoundTag& nbt) const { Cancellable::serialize(nbt); - nbt["item"] = (uintptr_t)&item(); + nbt["item"] = serializeRefObj(item()); nbt["blockPos"] = ListTag{blockPos().x, blockPos().y, blockPos().z}; nbt["face"] = magic_enum::enum_name(face()); nbt["clickPos"] = ListTag{clickPos().x, clickPos().y, clickPos().z}; - if (block()) { - nbt["block"] = (uintptr_t)(block().as_ptr()); - } + nbt["block"] = serializePtrObj(block().as_ptr()); } ItemStack& PlayerInteractBlockEvent::item() const { return mItem; } BlockPos const& PlayerInteractBlockEvent::blockPos() const { return mBlockPos; } diff --git a/src/ll/api/event/player/PlayerPickUpItemEvent.cpp b/src/ll/api/event/player/PlayerPickUpItemEvent.cpp index d022736cc5..31573c5daa 100644 --- a/src/ll/api/event/player/PlayerPickUpItemEvent.cpp +++ b/src/ll/api/event/player/PlayerPickUpItemEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/player/PlayerPickUpItemEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -8,7 +9,7 @@ namespace ll::event::inline player { void PlayerPickUpItemEvent::serialize(CompoundTag& nbt) const { Cancellable::serialize(nbt); - nbt["item"] = (uintptr_t)&itemActor(); + nbt["item"] = serializeRefObj(itemActor()); nbt["orgCount"] = orgCount(); nbt["favoredSlot"] = favoredSlot(); } diff --git a/src/ll/api/event/player/PlayerPlaceBlockEvent.cpp b/src/ll/api/event/player/PlayerPlaceBlockEvent.cpp index 74cb64ee83..658abdbfa4 100644 --- a/src/ll/api/event/player/PlayerPlaceBlockEvent.cpp +++ b/src/ll/api/event/player/PlayerPlaceBlockEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/player/PlayerPlaceBlockEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -18,7 +19,7 @@ void PlayerPlacingBlockEvent::serialize(CompoundTag& nbt) const { } void PlayerPlacedBlockEvent::serialize(CompoundTag& nbt) const { PlayerPlaceBlockEvent::serialize(nbt); - nbt["placedBlock"] = (uintptr_t)&placedBlock(); + nbt["placedBlock"] = serializeRefObj(placedBlock()); } BlockPos const& PlayerPlaceBlockEvent::pos() const { return mPos; } diff --git a/src/ll/api/event/player/PlayerUseItemEvent.cpp b/src/ll/api/event/player/PlayerUseItemEvent.cpp index 1497ee08bc..1f83a0db82 100644 --- a/src/ll/api/event/player/PlayerUseItemEvent.cpp +++ b/src/ll/api/event/player/PlayerUseItemEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/player/PlayerUseItemEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/world/gamemode/GameMode.h" @@ -10,7 +11,7 @@ namespace ll::event::inline player { void PlayerUseItemEvent::serialize(CompoundTag& nbt) const { Cancellable::serialize(nbt); - nbt["item"] = (uintptr_t)&item(); + nbt["item"] =serializeRefObj(item()); } ItemStack& PlayerUseItemEvent::item() const { return mItem; } diff --git a/src/ll/api/event/world/BlockChangedEvent.cpp b/src/ll/api/event/world/BlockChangedEvent.cpp index 3e62c5c8ec..03bdce452b 100644 --- a/src/ll/api/event/world/BlockChangedEvent.cpp +++ b/src/ll/api/event/world/BlockChangedEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/world/BlockChangedEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/nbt/CompoundTag.h" @@ -10,8 +11,8 @@ namespace ll::event::inline world { void BlockChangedEvent::serialize(CompoundTag& nbt) const { WorldEvent::serialize(nbt); nbt["layer"] = layer(); - nbt["previousBlock"] = (uintptr_t)&previousBlock(); - nbt["newBlock"] = (uintptr_t)&newBlock(); + nbt["previousBlock"] = serializeRefObj(previousBlock()); + nbt["newBlock"] = serializeRefObj(newBlock()); nbt["pos"] = ListTag{pos().x, pos().y, pos().z}; } diff --git a/src/ll/api/event/world/LevelWorldEvent.cpp b/src/ll/api/event/world/LevelWorldEvent.cpp index 01263379d9..2db46e406c 100644 --- a/src/ll/api/event/world/LevelWorldEvent.cpp +++ b/src/ll/api/event/world/LevelWorldEvent.cpp @@ -1,3 +1,4 @@ +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/event/world/LevelEvent.h" #include "ll/api/event/world/WorldEvent.h" @@ -8,11 +9,11 @@ namespace ll::event::inline world { void LevelEvent::serialize(CompoundTag& nbt) const { Event::serialize(nbt); - nbt["level"] = (uintptr_t)&level(); + nbt["level"] = serializeRefObj(level()); } void WorldEvent::serialize(CompoundTag& nbt) const { Event::serialize(nbt); - nbt["blockSource"] = (uintptr_t)&blockSource(); + nbt["blockSource"] = serializeRefObj(blockSource()); } Level& LevelEvent::level() const { return mLevel; } BlockSource& WorldEvent::blockSource() const { return mBlockSource; } diff --git a/src/ll/api/event/world/SpawnMobEvent.cpp b/src/ll/api/event/world/SpawnMobEvent.cpp index f5cd94e8c4..0e4f658509 100644 --- a/src/ll/api/event/world/SpawnMobEvent.cpp +++ b/src/ll/api/event/world/SpawnMobEvent.cpp @@ -1,5 +1,6 @@ #include "ll/api/event/world/SpawnMobEvent.h" #include "ll/api/event/Emitter.h" +#include "ll/api/event/EventRefObjSerializer.h" #include "ll/api/memory/Hook.h" #include "mc/world/level/BedrockSpawner.h" @@ -9,7 +10,7 @@ namespace ll::event::inline world { void SpawnMobEvent::serialize(CompoundTag& nbt) const { WorldEvent::serialize(nbt); - nbt["identifier"] = (uintptr_t)&identifier(); + nbt["identifier"] = serializeRefObj(identifier()); if (spawner()) { nbt["spawner"] = (uintptr_t)(spawner().as_ptr()); }