diff --git a/include/bedrock/world/level/block/block_descriptor.h b/include/bedrock/world/level/block/block_descriptor.h index 905f497ff..5105b6a72 100644 --- a/include/bedrock/world/level/block/block_descriptor.h +++ b/include/bedrock/world/level/block/block_descriptor.h @@ -27,7 +27,7 @@ class BlockDescriptor { enum class CompareType; public: - ENDSTONE_HOOK [[nodiscard]] Block const *tryGetBlockNoLogging() const; + [[nodiscard]] ENDSTONE_HOOK Block const *tryGetBlockNoLogging() const; private: void *unknown1_; // +0 diff --git a/include/endstone/block/block_data.h b/include/endstone/block/block_data.h index 9417d277d..b115c5297 100644 --- a/include/endstone/block/block_data.h +++ b/include/endstone/block/block_data.h @@ -20,6 +20,8 @@ #include +#include "endstone/endstone.h" + namespace endstone { using BlockStates = std::unordered_map>; @@ -58,20 +60,11 @@ struct formatter : formatter { template auto format(const Type &val, FormatContext &ctx) const -> format_context::iterator { - return std::visit( - [&ctx](auto &&arg) { - using T = std::decay_t; - if constexpr (std::is_same_v) { - return format_to(ctx.out(), "{:?}", arg); - } - else if constexpr (std::is_same_v || std::is_same_v) { - return format_to(ctx.out(), "{}", arg); - } - else { - static_assert(false, "non-exhaustive visitor!"); - } - }, - val); + return std::visit(endstone::overloaded{ + [&ctx](const std::string &arg) { return format_to(ctx.out(), "{:?}", arg); }, + [&ctx](auto &&arg) { return format_to(ctx.out(), "{}", arg); }, + }, + val); } }; diff --git a/src/endstone_core/form/form_codec.cpp b/src/endstone_core/form/form_codec.cpp index c059879f0..3bd3ea116 100644 --- a/src/endstone_core/form/form_codec.cpp +++ b/src/endstone_core/form/form_codec.cpp @@ -17,6 +17,7 @@ #include #include +#include "endstone/endstone.h" #include "endstone/form/action_form.h" #include "endstone/form/controls/dropdown.h" #include "endstone/form/controls/label.h" @@ -33,21 +34,21 @@ namespace endstone::detail { template <> nlohmann::json FormCodec::toJson(const Message &message) { - return std::visit(entt::overloaded{[&](const std::string &arg) -> nlohmann::json { - nlohmann::json json; - json["rawtext"].push_back({ - {"text", arg}, - }); - return json; - }, - [&](const Translatable &arg) -> nlohmann::json { - nlohmann::json json; - json["rawtext"].push_back({ - {"translate", arg.getTranslationKey()}, - {"with", arg.getParameters()}, - }); - return json; - }}, + return std::visit(overloaded{[&](const std::string &arg) -> nlohmann::json { + nlohmann::json json; + json["rawtext"].push_back({ + {"text", arg}, + }); + return json; + }, + [&](const Translatable &arg) -> nlohmann::json { + nlohmann::json json; + json["rawtext"].push_back({ + {"translate", arg.getTranslationKey()}, + {"with", arg.getParameters()}, + }); + return json; + }}, message); } @@ -181,7 +182,7 @@ nlohmann::json FormCodec::toJson(const ModalForm &form) json["title"] = toJson(form.getTitle()); json["content"] = nlohmann::json::array(); for (const auto &control : form.getControls()) { - json["content"].push_back(std::visit(entt::overloaded{[](auto &&arg) { + json["content"].push_back(std::visit(overloaded{[](auto &&arg) { return toJson(arg); }}, control)); diff --git a/src/endstone_core/player.cpp b/src/endstone_core/player.cpp index 2725973d5..26f848c9c 100644 --- a/src/endstone_core/player.cpp +++ b/src/endstone_core/player.cpp @@ -556,7 +556,7 @@ void EndstonePlayer::sendForm(FormVariant form) auto packet = MinecraftPackets::createPacket(MinecraftPacketIds::ShowModalForm); std::shared_ptr pk = std::static_pointer_cast(packet); pk->form_id = ++form_ids_; - pk->form_json = std::visit(entt::overloaded{[](auto &&arg) { + pk->form_json = std::visit(overloaded{[](auto &&arg) { return FormCodec::toJson(arg); }}, form) @@ -587,7 +587,7 @@ void EndstonePlayer::onFormClose(int form_id, PlayerFormCloseReason /*reason*/) if (!isDead()) { try { - std::visit(entt::overloaded{[this](auto &&arg) { + std::visit(overloaded{[this](auto &&arg) { auto callback = arg.getOnClose(); if (callback) { callback(this); @@ -611,7 +611,7 @@ void EndstonePlayer::onFormResponse(int form_id, const nlohmann::json &json) if (!isDead()) { try { - std::visit(entt::overloaded{ + std::visit(overloaded{ [&](const MessageForm &form) { if (auto callback = form.getOnSubmit()) { callback(this, json.get() ? 0 : 1); diff --git a/src/endstone_core/scoreboard/scoreboard.cpp b/src/endstone_core/scoreboard/scoreboard.cpp index 99c5f7f46..35e48cea6 100644 --- a/src/endstone_core/scoreboard/scoreboard.cpp +++ b/src/endstone_core/scoreboard/scoreboard.cpp @@ -201,17 +201,16 @@ std::string EndstoneScoreboard::getDisplaySlotName(DisplaySlot slot) const ::ScoreboardId &EndstoneScoreboard::getScoreboardId(ScoreEntry entry) const { - return std::visit( - entt::overloaded{[&](Player *player) -> const ::ScoreboardId & { - return board_.getScoreboardId(static_cast(player)->getHandle()); - }, - [&](Actor *actor) -> const ::ScoreboardId & { - return board_.getScoreboardId(static_cast(actor)->getActor()); - }, - [&](const std::string &fake) -> const ::ScoreboardId & { - return board_.getScoreboardId(fake); - }}, - entry); + return std::visit(overloaded{[&](Player *player) -> const ::ScoreboardId & { + return board_.getScoreboardId(static_cast(player)->getHandle()); + }, + [&](Actor *actor) -> const ::ScoreboardId & { + return board_.getScoreboardId(static_cast(actor)->getActor()); + }, + [&](const std::string &fake) -> const ::ScoreboardId & { + return board_.getScoreboardId(fake); + }}, + entry); } const ::ScoreboardId &EndstoneScoreboard::getOrCreateScoreboardId(ScoreEntry entry) @@ -221,17 +220,17 @@ const ::ScoreboardId &EndstoneScoreboard::getOrCreateScoreboardId(ScoreEntry ent return scoreboard_id; } - return std::visit( - entt::overloaded{[&](Player *player) -> const ::ScoreboardId & { - return board_.createScoreboardId(static_cast(player)->getHandle()); - }, - [&](Actor *actor) -> const ::ScoreboardId & { - return board_.createScoreboardId(static_cast(actor)->getActor()); - }, - [&](const std::string &fake) -> const ::ScoreboardId & { - return board_.createScoreboardId(fake); - }}, - entry); + return std::visit(overloaded{[&](Player *player) -> const ::ScoreboardId & { + return board_.createScoreboardId( + static_cast(player)->getHandle()); + }, + [&](Actor *actor) -> const ::ScoreboardId & { + return board_.createScoreboardId(static_cast(actor)->getActor()); + }, + [&](const std::string &fake) -> const ::ScoreboardId & { + return board_.createScoreboardId(fake); + }}, + entry); } ::Scoreboard &EndstoneScoreboard::getHandle() const diff --git a/src/endstone_core/server.cpp b/src/endstone_core/server.cpp index 2887935ef..b9bd7983f 100644 --- a/src/endstone_core/server.cpp +++ b/src/endstone_core/server.cpp @@ -378,11 +378,11 @@ std::shared_ptr EndstoneServer::createBlockData(std::string type) con std::shared_ptr EndstoneServer::createBlockData(std::string type, BlockStates block_states) const { std::unordered_map> states; - for (const auto &[key, value] : block_states) { - std::visit(entt::overloaded{[&](auto &&arg) { - states.emplace(key, arg); + for (const auto &state : block_states) { + std::visit(overloaded{[&](auto &&arg) { + states.emplace(state.first, arg); }}, - value); + state.second); } const auto block_descriptor = ScriptModuleMinecraft::ScriptBlockUtils::createBlockDescriptor(type, states); diff --git a/src/endstone_devtools/devtools.cpp b/src/endstone_devtools/devtools.cpp index 3bf8fdf8b..1233288ac 100644 --- a/src/endstone_devtools/devtools.cpp +++ b/src/endstone_devtools/devtools.cpp @@ -37,6 +37,7 @@ #include "endstone/detail/devtools/vanilla_data.h" #include "endstone/detail/logger_factory.h" #include "endstone/detail/os.h" +#include "endstone/endstone.h" namespace fs = std::filesystem; @@ -260,19 +261,18 @@ void render() gFileBrowser->Display(); if (gFileBrowser->HasSelected()) { auto path = gFileBrowser->GetSelected(); - std::visit( - entt::overloaded{[&](std::monostate) { gLogger.error("Unable to save to {}: Empty.", path.string()); }, - [&](const nlohmann::json &arg) { - std::ofstream file(path); - file << arg; - }, - [&](const CompoundTag &arg) { - BigEndianStringByteOutput output; - NbtIo::writeNamedTag("", arg, output); - zstr::ofstream file(path.string(), std::ios::out | std::ios::binary); - file << output.buffer; - }}, - file_to_save); + std::visit(overloaded{[&](std::monostate) { gLogger.error("Unable to save to {}: Empty.", path.string()); }, + [&](const nlohmann::json &arg) { + std::ofstream file(path); + file << arg; + }, + [&](const CompoundTag &arg) { + BigEndianStringByteOutput output; + NbtIo::writeNamedTag("", arg, output); + zstr::ofstream file(path.string(), std::ios::out | std::ios::binary); + file << output.buffer; + }}, + file_to_save); file_to_save = std::monostate(); gFileBrowser->ClearSelected(); } diff --git a/src/endstone_runtime/bedrock/world/events/event_coordinator.cpp b/src/endstone_runtime/bedrock/world/events/event_coordinator.cpp index bf293557b..fa4ebae5d 100644 --- a/src/endstone_runtime/bedrock/world/events/event_coordinator.cpp +++ b/src/endstone_runtime/bedrock/world/events/event_coordinator.cpp @@ -103,7 +103,7 @@ void PlayerEventCoordinator::sendEvent(const EventRef> { void (PlayerEventCoordinator::*fp)(const EventRef> &) = &PlayerEventCoordinator::sendEvent; - auto visitor = entt::overloaded{ + auto visitor = endstone::overloaded{ [](const Details::ValueOrRef &value) { const auto event = value.asValue(); const auto &weak_ref = event.player;