[BlockCursor] It is now required to press Sneak key to place a block on a workbench/furnace without activating their GUI.

This commit is contained in:
Quentin Bazin 2020-02-08 01:30:39 +09:00
parent 070a689208
commit 4cae1b9c50
4 changed files with 11 additions and 9 deletions

View File

@ -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>
@ -22,6 +23,7 @@
#include "ClientCommandHandler.hpp"
#include "ClientPlayer.hpp"
#include "Config.hpp"
#include "GameKey.hpp"
#include "Hotbar.hpp"
#include "Registry.hpp"
@ -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;

View File

@ -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; }
@ -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;

View File

@ -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) {
@ -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);

View File

@ -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; }