Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/client/menus/Menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/server/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class World final : public CommonWorld<ChunkGeneration>
std::vector<std::pair<glm::ivec3, BlockType>> 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<PacketPtr> &pktsToSend);
void updateEntitiesPosition(const std::vector<CPlayerInfo> &players, int32_t clientTick);

bool setBlockWorld(glm::ivec3 globalCoords, std::optional<glm::ivec3> faceNormal, BlockType type) override;
Expand Down
8 changes: 8 additions & 0 deletions src/client/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@
app->lastMouseMoveTime = glfwGetTime();
});

glfwSetScrollCallback(window, [](GLFWwindow* w, double xoffset, double yoffset) {
App* app = static_cast<App*>(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<App*>(glfwGetWindowUserPointer(w));
if (!app) return;
Expand Down Expand Up @@ -316,7 +324,7 @@


glfwSetMouseButtonCallback(window, [](GLFWwindow* w, int button, int action, int mods) {
App* app = static_cast<App*>(glfwGetWindowUserPointer(w));

Check warning on line 327 in src/client/App.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=ldominiq_ft_minecraft&issues=AZ5QNDJoiT-NlG6WfngO&open=AZ5QNDJoiT-NlG6WfngO&pullRequest=107
if (!app) return;

auto manager = app->menuManager.lock();
Expand Down
4 changes: 2 additions & 2 deletions src/client/menus/DebugHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(fullscreenHeight) - pad - 4.0f * menuScale;
float textY = static_cast<float>(fullscreenHeight) - pad - 4.0f * menuScale * textScale * 5;

char buf[64];

Expand Down
10 changes: 4 additions & 6 deletions src/client/menus/InventoryUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <algorithm>

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.
Expand Down Expand Up @@ -173,6 +171,7 @@ void InventoryUI::build()
craftingResultSlot.x = std::min(craftingResultSlot.x, maxX);

textRenderer.setProjection(fullscreenWidth, fullscreenHeight);
textRenderer.setScale(0.35f * menuScale);
}

InventoryUI::~InventoryUI()
Expand Down Expand Up @@ -267,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)
{
Expand Down Expand Up @@ -304,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),
Expand Down Expand Up @@ -765,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),
Expand All @@ -781,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),
Expand Down
6 changes: 3 additions & 3 deletions src/client/menus/PlayerListHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 3 additions & 10 deletions src/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(InventoryType::PLAYER);
dropItem.type = player->movement->inventory->getActiveItemID();
dropItem.amount = player->movement->inventory->getSlot(slot).second;
dropItem.slot = slot;
sendPacketTo(dropItem, cliaddr);
}
std::vector<PacketPtr> pktsToSend;
world->processPlayerMouseInputs(*player, pkt, tick, pktsToSend);
sendNewGroupPacketTo(pktsToSend, cliaddr);

if (pkt.mouseButtons & (IN_LEFT_CLICK | IN_RIGHT_CLICK))
player->movement->pendingArmSwing = true;
Expand Down
44 changes: 26 additions & 18 deletions src/server/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@
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<PacketPtr> &pktsToSend)

Check failure on line 926 in src/server/World.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 87 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=ldominiq_ft_minecraft&issues=AZ5QNC_6iT-NlG6WfngM&open=AZ5QNC_6iT-NlG6WfngM&pullRequest=107
{
LivingEntity* livingEntity = nullptr;
glm::ivec3 blockPos, faceNormal;
Expand All @@ -948,8 +948,11 @@
{
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)
Expand All @@ -961,8 +964,11 @@
{
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 ;
}
}
}
Expand All @@ -975,7 +981,7 @@
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
Expand All @@ -985,7 +991,7 @@
&& isTorch(std::get<BlockType>(item)))
{
if (target != TargetType::Block)
return false;
return ;

BlockType torchVariant;
if (faceNormal == glm::ivec3(0, 1, 0))
Expand All @@ -999,24 +1005,25 @@
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<BlockType>(item) && std::get<BlockType>(item) != BlockType::BEGIN)
Expand All @@ -1025,11 +1032,12 @@
{
//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

Check failure on line 1035 in src/server/World.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=ldominiq_ft_minecraft&issues=AZ5QNC_6iT-NlG6WfngN&open=AZ5QNC_6iT-NlG6WfngN&pullRequest=107
if (setBlockWorld(blockPos, faceNormal, std::get<BlockType>(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 ;
}
}
}
Expand All @@ -1039,7 +1047,7 @@
{
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.
Expand Down Expand Up @@ -1089,10 +1097,10 @@
{
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)
Expand Down
Loading