From ffd61f72e5ceb76b47476ea9a55c4ac1a3e293c3 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 22 May 2026 16:59:12 +0200 Subject: [PATCH 1/3] fixed --- include/client/menus/Menu.hpp | 2 +- include/server/World.hpp | 2 +- src/client/App.cpp | 8 ++++++ src/client/menus/DebugHUD.cpp | 4 +-- src/client/menus/InventoryUI.cpp | 1 + src/client/menus/PlayerListHUD.cpp | 6 ++-- src/server/Server.cpp | 13 ++------- src/server/World.cpp | 44 ++++++++++++++++++------------ 8 files changed, 45 insertions(+), 35 deletions(-) diff --git a/include/client/menus/Menu.hpp b/include/client/menus/Menu.hpp index 1faa4da2..626f8a9a 100644 --- a/include/client/menus/Menu.hpp +++ b/include/client/menus/Menu.hpp @@ -56,7 +56,7 @@ class Menu { int menuWidth = 0; int menuHeight = 0; float menuScale = 0; - float textScale = 0.3f; + float textScale = 1.0f; Typer textRenderer; Typer titleRenderer; diff --git a/include/server/World.hpp b/include/server/World.hpp index cfb911c9..c576c40f 100644 --- a/include/server/World.hpp +++ b/include/server/World.hpp @@ -150,7 +150,7 @@ class World final : public CommonWorld std::vector> updatedBlocks; //returns true if item has been placed - bool processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseInputs &pkt, int32_t clientTick); + void processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseInputs &pkt, int32_t clientTick, std::vector &pktsToSend); void updateEntitiesPosition(const std::vector &players, int32_t clientTick); bool setBlockWorld(glm::ivec3 globalCoords, std::optional faceNormal, BlockType type) override; diff --git a/src/client/App.cpp b/src/client/App.cpp index 90f316a8..fcdbfe8a 100644 --- a/src/client/App.cpp +++ b/src/client/App.cpp @@ -233,6 +233,14 @@ void App::init(const std::string& serverIp) { app->lastMouseMoveTime = glfwGetTime(); }); + glfwSetScrollCallback(window, [](GLFWwindow* w, double xoffset, double yoffset) { + App* app = static_cast(glfwGetWindowUserPointer(w)); + + int slot = app->camera->getPlayer()->inventory->activeHotbarSlot; + if (slot - yoffset >= 0 && slot - yoffset < 9) + app->camera->getPlayer()->inventory->activeHotbarSlot -= yoffset; + }); + glfwSetCharCallback(window, [](GLFWwindow* w, unsigned int codepoint) { App* app = static_cast(glfwGetWindowUserPointer(w)); if (!app) return; diff --git a/src/client/menus/DebugHUD.cpp b/src/client/menus/DebugHUD.cpp index 47dd4435..c13fb08a 100644 --- a/src/client/menus/DebugHUD.cpp +++ b/src/client/menus/DebugHUD.cpp @@ -20,13 +20,13 @@ void DebugHUD::build() void DebugHUD::onRender() { const float pad = 8.0f * menuScale; - const float lineH = 18.0f * menuScale; + const float lineH = 18.0f * menuScale * textScale * 3; const float bgPadX = 2.0f * menuScale; // horizontal inset inside each bg const glm::vec4 bgColor{ 0.0f, 0.0f, 0.0f, 0.0f }; const glm::vec3 white{ 1.0f, 1.0f, 1.0f }; const float textX = pad; - float textY = static_cast(fullscreenHeight) - pad - 4.0f * menuScale; + float textY = static_cast(fullscreenHeight) - pad - 4.0f * menuScale * textScale * 5; char buf[64]; diff --git a/src/client/menus/InventoryUI.cpp b/src/client/menus/InventoryUI.cpp index 609e47e5..7f05d81a 100644 --- a/src/client/menus/InventoryUI.cpp +++ b/src/client/menus/InventoryUI.cpp @@ -173,6 +173,7 @@ void InventoryUI::build() craftingResultSlot.x = std::min(craftingResultSlot.x, maxX); textRenderer.setProjection(fullscreenWidth, fullscreenHeight); + textRenderer.setScale(textScale); } InventoryUI::~InventoryUI() diff --git a/src/client/menus/PlayerListHUD.cpp b/src/client/menus/PlayerListHUD.cpp index 048105ae..23ac242f 100644 --- a/src/client/menus/PlayerListHUD.cpp +++ b/src/client/menus/PlayerListHUD.cpp @@ -45,10 +45,10 @@ void PlayerListHUD::onRender() if (m_players.empty()) return; const float s = menuScale; - const float panelW = 300.0f * s; + const float panelW = 300.0f * s * textScale * 3; const float padX = 10.0f * s; - const float padY = 8.0f * s; - const float lineH = 20.0f * s; + const float padY = 8.0f * s * textScale * 3; + const float lineH = 20.0f * s * textScale * 3; const float iconSize = 12.0f * s; const float topGap = 10.0f * s; diff --git a/src/server/Server.cpp b/src/server/Server.cpp index f935cd83..0e77b03e 100644 --- a/src/server/Server.cpp +++ b/src/server/Server.cpp @@ -631,16 +631,9 @@ void Server::receivePlayerMouseInputs(NetPlayerMouseInputs &pkt, const sockaddr_ if (player->movement->health <= 0.0f || player->movement->pendingDeathRemovalTicks > 0) return; - if (world->processPlayerMouseInputs(*player, pkt, tick)) - { - NetInventory dropItem; - int slot = player->movement->inventory->activeHotbarSlot; - dropItem.inventoryTypeID = static_cast(InventoryType::PLAYER); - dropItem.type = player->movement->inventory->getActiveItemID(); - dropItem.amount = player->movement->inventory->getSlot(slot).second; - dropItem.slot = slot; - sendPacketTo(dropItem, cliaddr); - } + std::vector pktsToSend; + world->processPlayerMouseInputs(*player, pkt, tick, pktsToSend); + sendNewGroupPacketTo(pktsToSend, cliaddr); if (pkt.mouseButtons & (IN_LEFT_CLICK | IN_RIGHT_CLICK)) player->movement->pendingArmSwing = true; diff --git a/src/server/World.cpp b/src/server/World.cpp index ff5e8948..c5b7553b 100644 --- a/src/server/World.cpp +++ b/src/server/World.cpp @@ -923,7 +923,7 @@ void World::setWaterWorld(glm::ivec3 globalCoords, std::optional fac currChunk->setBlock(x, y, z, type); } -bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseInputs &pkt, int32_t clientTick) +void World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseInputs &pkt, int32_t clientTick, std::vector &pktsToSend) { LivingEntity* livingEntity = nullptr; glm::ivec3 blockPos, faceNormal; @@ -948,8 +948,11 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn { player.movement->inventory->removeItemsFromSlot(activeSlot, 1); int one = 1; - player.movement->inventory->insertItems(MiscType::EMPTY_BUCKET, one); - return true; + int slot = player.movement->inventory->insertItems(MiscType::EMPTY_BUCKET, one); + pktsToSend.push_back(player.movement->inventory->createNetInventoryPkt(activeSlot)); + if (slot != activeSlot) + pktsToSend.push_back(player.movement->inventory->createNetInventoryPkt(slot)); + return ; } } else if (m == MiscType::EMPTY_BUCKET) @@ -961,8 +964,11 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn { player.movement->inventory->removeItemsFromSlot(activeSlot, 1); int one = 1; - player.movement->inventory->insertItems(MiscType::WATER_BUCKET, one); - return true; + int slot = player.movement->inventory->insertItems(MiscType::WATER_BUCKET, one); + pktsToSend.push_back(player.movement->inventory->createNetInventoryPkt(activeSlot)); + if (slot != activeSlot) + pktsToSend.push_back(player.movement->inventory->createNetInventoryPkt(slot)); + return ; } } } @@ -975,7 +981,7 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn player.movement->hasBeaconSet = true; player.movement->beaconPos = blockPos; player.targetedMessages.push_back("[server] Spawn point set!"); - return false; + return ; } // Torch placement: orientation is derived from the clicked face. The held @@ -985,7 +991,7 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn && isTorch(std::get(item))) { if (target != TargetType::Block) - return false; + return ; BlockType torchVariant; if (faceNormal == glm::ivec3(0, 1, 0)) @@ -999,24 +1005,25 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn else if (faceNormal == glm::ivec3(0, 0, -1)) torchVariant = BlockType::TORCH_WALL_SOUTH; else - return false; // underside / unsupported face + return ; // underside / unsupported face // The clicked block must be a solid support (not air / another // torch), and the cell the torch would occupy must be empty so a // new torch never overwrites an existing one sharing that cell. if (!isBlockSolid(getBlockWorld(blockPos))) - return false; + return ; if (getBlockWorld(blockPos + faceNormal) != BlockType::AIR) - return false; + return ; // No entity-collision check: a torch has no real hitbox, so you can // place one in the cell you're standing in (unlike a full block). if (setBlockWorld(blockPos, faceNormal, torchVariant)) { player.movement->inventory->removeItemsFromSlot(player.movement->inventory->activeHotbarSlot, 1); - return true; + pktsToSend.push_back(player.movement->inventory->createNetInventoryPkt(activeSlot)); + return ; } - return false; + return ; } if (pkt.mouseButtons & IN_RIGHT_CLICK && std::holds_alternative(item) && std::get(item) != BlockType::BEGIN) @@ -1025,11 +1032,12 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn { //set block for (const auto &entity : livingEntities) - if (entity->entityCollidesWithBlock(blockPos + faceNormal)) return false; //only checks collision with living entities + if (entity->entityCollidesWithBlock(blockPos + faceNormal)) return ; //only checks collision with living entities if (setBlockWorld(blockPos, faceNormal, std::get(item))) { - player.movement->inventory->removeItemsFromSlot(player.movement->inventory->activeHotbarSlot, 1); - return true; + player.movement->inventory->removeItemsFromSlot(activeSlot, 1); + pktsToSend.push_back(player.movement->inventory->createNetInventoryPkt(activeSlot)); + return ; } } } @@ -1039,7 +1047,7 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn { BlockType dropped = getBlockWorld(blockPos); - if (dropped == BlockType::BEDROCK) return false; + if (dropped == BlockType::BEDROCK) return ; // Torches always drop as the inventory (floor) form so they // stack regardless of which wall variant was mined. @@ -1089,10 +1097,10 @@ bool World::processPlayerMouseInputs(CPlayerInfo &player, const NetPlayerMouseIn { breakDependentTorches(blockPos, clientTick, player.movement->gamemode == GAMEMODES::SURVIVAL); - return false; + return ; } } - return false; + return ; } void World::breakDependentTorches(const glm::ivec3& removedBlock, int32_t clientTick, bool dropItems) From b96b6f27219a7f5cb839d13bc3da6772f9deb22d Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 22 May 2026 17:33:55 +0200 Subject: [PATCH 2/3] fixed inventory --- src/client/menus/InventoryUI.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/client/menus/InventoryUI.cpp b/src/client/menus/InventoryUI.cpp index 7f05d81a..7981824c 100644 --- a/src/client/menus/InventoryUI.cpp +++ b/src/client/menus/InventoryUI.cpp @@ -2,8 +2,6 @@ #include -constexpr float textScale = 0.3f; - // Append the inventory icon for one item to the vertex stream. Routes to a // flat sprite for vegetation/weapons/misc and to an isometric cube for full // blocks, so blocks still look 3D and items look like 2D Minecraft items. @@ -173,7 +171,7 @@ void InventoryUI::build() craftingResultSlot.x = std::min(craftingResultSlot.x, maxX); textRenderer.setProjection(fullscreenWidth, fullscreenHeight); - textRenderer.setScale(textScale); + textRenderer.setScale(0.35f * menuScale); } InventoryUI::~InventoryUI() @@ -268,7 +266,6 @@ void InventoryUI::drawHotbar() if (!inv) return ; - // drawSimpleQuad(hotbar.x, hotbar.y, hotbar.width, hotbar.height, glm::vec4(0,0,0,0.5)); uint8_t i = 0; for (auto &hotbarSlotCoord : hotbarSlots) { @@ -305,7 +302,7 @@ void InventoryUI::drawHotbar() i = 0; for (auto &hotbarSlotCoord : hotbarSlots) { - textRenderer.renderText(std::to_string(inv->getSlot(i).second), hotbarSlotCoord.x, hotbarSlotCoord.y + hotbar.height * 0.7, glm::vec3(1.0f)); + textRenderer.renderText(std::to_string(inv->getSlot(i).second), hotbarSlotCoord.x + 3 * menuScale, hotbarSlotCoord.y + hotbar.height * 0.7, glm::vec3(1.0f)); //could optimize and only redo if inventory/hotbar has changed. TODO ? buildInventoryIcon(meshVertices, inv->getItemAtSlot(i), From 1bcab554204ca69340c7739b7892fca051f321ee Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 22 May 2026 17:43:01 +0200 Subject: [PATCH 3/3] moved text slightly --- src/client/menus/InventoryUI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/menus/InventoryUI.cpp b/src/client/menus/InventoryUI.cpp index 7981824c..d0f54fa3 100644 --- a/src/client/menus/InventoryUI.cpp +++ b/src/client/menus/InventoryUI.cpp @@ -763,7 +763,7 @@ void InventoryUI::onRender() return ; if (inv->getSlot(i).second) - textRenderer.renderText(std::to_string(inv->getSlot(i).second), inventorySlots[i].x, inventorySlots[i].y + hotbar.height * 0.7, glm::vec3(1.0f)); + textRenderer.renderText(std::to_string(inv->getSlot(i).second), inventorySlots[i].x + 3 * menuScale, inventorySlots[i].y + hotbar.height * 0.7, glm::vec3(1.0f)); //could optimize and only redo if inventory/hotbar has changed. TODO ? buildInventoryIcon(meshVertices, inv->getItemAtSlot(i), @@ -779,7 +779,7 @@ void InventoryUI::onRender() return ; if (inv->getSlot(i).second) - textRenderer.renderText(std::to_string(inv->getSlot(i).second), craftingStationSlots[i].x, craftingStationSlots[i].y + hotbar.height * 0.7, glm::vec3(1.0f)); + textRenderer.renderText(std::to_string(inv->getSlot(i).second), craftingStationSlots[i].x + 3 * menuScale, craftingStationSlots[i].y + hotbar.height * 0.7, glm::vec3(1.0f)); //could optimize and only redo if inventory/hotbar has changed. TODO ? buildInventoryIcon(meshVertices, inv->getItemAtSlot(i),