Skip to content

Commit

Permalink
[BlockCursor] It is now required to press Sneak key to place a block …
Browse files Browse the repository at this point in the history
…on a workbench/furnace without activating their GUI.
  • Loading branch information
Unarelith committed Feb 7, 2020
1 parent 070a689 commit 4cae1b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
12 changes: 6 additions & 6 deletions client/source/hud/BlockCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
#include <glm/gtc/matrix_transform.hpp>

#include <gk/core/input/GamePad.hpp>
#include <gk/gl/GLCheck.hpp>
#include <gk/gl/Vertex.hpp>
#include <gk/core/GameClock.hpp>
Expand All @@ -22,6 +23,7 @@
#include "ClientCommandHandler.hpp"
#include "ClientPlayer.hpp"
#include "Config.hpp"
#include "GameKey.hpp"
#include "Hotbar.hpp"
#include "Registry.hpp"

Expand Down Expand Up @@ -77,15 +79,13 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
const Block &block = Registry::getInstance().getBlock(blockId);
const Item &item = Registry::getInstance().getItem(hotbar.currentItem());

if (block.id()) {
bool blockActivationSent = false;
if (block.id() && block.canBeActivated() && !gk::GamePad::isKeyPressed(GameKey::Sneak)) {
m_client.sendBlockActivated(m_selectedBlock);
blockActivationSent = true;
}

// FIXME: Check if this block has a callback
// ServerBlock should contain onBlockActivated
// Block should contain hasBlockActivatedCallback
if (block.id()// && !block.onBlockActivated({m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z}, m_player, m_world)
&& hotbar.currentItem() && item.isBlock()) {
if (block.id() && !blockActivationSent && hotbar.currentItem() && item.isBlock()) {
s8 face = m_selectedBlock.w;

s32 x = m_selectedBlock.x;
Expand Down
2 changes: 2 additions & 0 deletions common/include/world/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Block : public ISerializable {
void setDrawType(BlockDrawType drawType) { m_drawType = drawType; }

bool canUpdate() const { return m_canUpdate; }
bool canBeActivated() const { return m_canBeActivated; }

bool isLightSource() const { return m_isLightSource; }
void setLightSource(bool isLightSource) { m_isLightSource = isLightSource; }
Expand All @@ -90,6 +91,7 @@ class Block : public ISerializable {
glm::vec4 getTexCoordsFromID(int textureID) const;

bool m_canUpdate = false;
bool m_canBeActivated = false;

private:
u32 m_id = 0;
Expand Down
4 changes: 2 additions & 2 deletions common/source/world/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Block::serialize(sf::Packet &packet) const {
<< m_hardness << m_harvestRequirements << m_itemDrop << m_itemDropAmount << m_tiles
<< m_boundingBox.x << m_boundingBox.y << m_boundingBox.z
<< m_boundingBox.width << m_boundingBox.height << m_boundingBox.depth
<< m_isLightSource;
<< m_isLightSource << m_canUpdate << m_canBeActivated;
}

void Block::deserialize(sf::Packet &packet) {
Expand All @@ -46,7 +46,7 @@ void Block::deserialize(sf::Packet &packet) {
>> m_harvestRequirements >> m_itemDrop >> m_itemDropAmount >> m_tiles
>> m_boundingBox.x >> m_boundingBox.y >> m_boundingBox.z
>> m_boundingBox.width >> m_boundingBox.height >> m_boundingBox.depth
>> m_isLightSource;
>> m_isLightSource >> m_canUpdate >> m_canBeActivated;

m_id = id;
m_drawType = BlockDrawType(drawType);
Expand Down
2 changes: 1 addition & 1 deletion server/include/world/ServerBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ServerBlock : public Block {

bool canUpdate() const { return m_onTick.valid(); }

void setOnBlockActivated(const sol::function &function) { m_onBlockActivated = function; }
void setOnBlockActivated(const sol::function &function) { m_onBlockActivated = function; m_canBeActivated = m_onBlockActivated.valid(); }
void setOnTick(const sol::function &function) { m_onTick = function; m_canUpdate = m_onTick.valid(); }
void setOnBlockPlaced(const sol::function &function) { m_onBlockPlaced = function; }

Expand Down

0 comments on commit 4cae1b9

Please sign in to comment.