From 64ddacd08fc86964e80de698911636ac55d121f6 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Mon, 20 Jul 2020 15:31:43 +0200 Subject: [PATCH] [mods/default] 'Torch' added. [BlockState] 'isCollidable' attribute added. [TextButton] Now rounding position. --- docs/lua-api-block.md | 11 +++++++++++ mods/default/blocks.lua | 10 ++++++++++ mods/default/textures/blocks/torch_on.png | Bin 0 -> 340 bytes source/client/gui/TextButton.cpp | 4 ++-- source/client/world/ChunkBuilder.cpp | 8 ++++---- source/client/world/ClientPlayer.cpp | 2 +- source/common/world/BlockState.cpp | 4 ++-- source/common/world/BlockState.hpp | 3 +++ source/server/lua/loader/LuaBlockLoader.cpp | 9 ++++++++- texturepacks/minecraft/blocks/torch_on.png | Bin 0 -> 159 bytes 10 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 mods/default/textures/blocks/torch_on.png create mode 100644 texturepacks/minecraft/blocks/torch_on.png diff --git a/docs/lua-api-block.md b/docs/lua-api-block.md index 6355c66d4..8f17d1246 100644 --- a/docs/lua-api-block.md +++ b/docs/lua-api-block.md @@ -123,6 +123,17 @@ If you set this parameter the block will be displayed as an item in the inventor The texture is loaded from `mods//textures/items/`. +### `is_collidable` + +Defines if the block can block the player or not. + +Example: +```lua +is_collidable = true -- this is the default value +``` + +The default value changes to `false` if the draw type is `liquid` or `xshape`. + ### `is_light_source` Defines if the block is the light source or not. diff --git a/mods/default/blocks.lua b/mods/default/blocks.lua index 45ed4620c..5ec764fd4 100644 --- a/mods/default/blocks.lua +++ b/mods/default/blocks.lua @@ -433,6 +433,16 @@ mod:block { end } +mod:block { + id = "torch", + name = "Torch", + tiles = "torch_on.png", + is_light_source = true, + is_collidable = false, + draw_type = "boundingbox", + bounding_box = {7 / 16, 7 / 16, 0, 2 / 16, 2 / 16, 10 / 16}, +} + dofile("blocks/workbench.lua") dofile("blocks/furnace.lua") dofile("blocks/door.lua") diff --git a/mods/default/textures/blocks/torch_on.png b/mods/default/textures/blocks/torch_on.png new file mode 100644 index 0000000000000000000000000000000000000000..eeff1d21352071d2c232cfcfc24ce69c5669059d GIT binary patch literal 340 zcmV-a0jvIrP)q1WF4!=};(i>FC&paqA?mzJpVq z!pCswrd5=HDP)j>hC+)4D+%{Fg!lmGN-yI5wmbYkANL;a0guPy@%(oJZBR@q09;R- zqDx&@s1*Ppn_9)~1%@eHh_!?YF{#KiB1S}vs4Wh(!K?EdV8X*<#OC8uTVweIz)?50 z%BuzXNkqBck`*gA0$~`^OF9fsx^4tovSLLPMQ#LUPfK?<5XXm{jgHA*H&j)%e}UgZ zEwI~tQLeYtb?ru=#n}wZ^O9cD0U!v}OZ5-Wzblock().id() != 0 && blocks[0]->isOpaque(), - blocks[1] && blocks[1]->block().id() != 0 && blocks[1]->isOpaque(), - blocks[2] && blocks[2]->block().id() != 0 && blocks[2]->isOpaque(), - blocks[3] && blocks[3]->block().id() != 0 && blocks[3]->isOpaque() + blocks[0] && blocks[0]->block().id() != 0 && blocks[0]->isOpaque() && !blocks[0]->isLightSource(), + blocks[1] && blocks[1]->block().id() != 0 && blocks[1]->isOpaque() && !blocks[1]->isLightSource(), + blocks[2] && blocks[2]->block().id() != 0 && blocks[2]->isOpaque() && !blocks[2]->isLightSource(), + blocks[3] && blocks[3]->block().id() != 0 && blocks[3]->isOpaque() && !blocks[3]->isLightSource() }; bool side1 = blockPresence[(minOffset.x != 0) ? 2 : 1]; diff --git a/source/client/world/ClientPlayer.cpp b/source/client/world/ClientPlayer.cpp index f1f86e16e..01941fb61 100644 --- a/source/client/world/ClientPlayer.cpp +++ b/source/client/world/ClientPlayer.cpp @@ -186,7 +186,7 @@ void ClientPlayer::checkCollisions(const ClientWorld &world) { bool passable(const ClientWorld &world, double x, double y, double z) { const BlockState *blockState = world.getBlockState(floor(x), floor(y), floor(z)); - return !blockState || !blockState->block().id() || blockState->drawType() == BlockDrawType::Liquid || blockState->drawType() == BlockDrawType::XShape; + return !blockState || !blockState->block().id() || !blockState->isCollidable(); } void ClientPlayer::testPoint(const ClientWorld &world, double x, double y, double z, glm::vec3 &vel) { diff --git a/source/common/world/BlockState.cpp b/source/common/world/BlockState.cpp index 88aa104bf..451e76994 100644 --- a/source/common/world/BlockState.cpp +++ b/source/common/world/BlockState.cpp @@ -34,7 +34,7 @@ void BlockState::serialize(sf::Packet &packet) const { << m_boundingBox << u8(m_drawType) << m_colorMultiplier << m_isOpaque << m_isLightSource << m_inventoryImage << m_fogDepth << m_fogColor - << m_drawOffset << m_attrs; + << m_drawOffset << m_isCollidable << m_attrs; } void BlockState::deserialize(sf::Packet &packet) { @@ -46,7 +46,7 @@ void BlockState::deserialize(sf::Packet &packet) { >> m_boundingBox >> drawType >> m_colorMultiplier >> m_isOpaque >> m_isLightSource >> m_inventoryImage >> m_fogDepth >> m_fogColor - >> m_drawOffset >> m_attrs; + >> m_drawOffset >> m_isCollidable >> m_attrs; m_drawType = BlockDrawType(drawType); } diff --git a/source/common/world/BlockState.hpp b/source/common/world/BlockState.hpp index 4c1327cf5..9e6bf09c2 100644 --- a/source/common/world/BlockState.hpp +++ b/source/common/world/BlockState.hpp @@ -128,6 +128,7 @@ class BlockState : public gk::ISerializable { attr_fogDepth = 1 << 12, attr_fogColor = 1 << 13, attr_drawOffset = 1 << 14, + attr_isCollidable = 1 << 15, }; BLOCK_ATTR(std::string, label); @@ -154,6 +155,8 @@ class BlockState : public gk::ISerializable { BLOCK_ATTR_V(gk::Vector3f, drawOffset, (gk::Vector3f{0, 0, 0})); + BLOCK_ATTR_V(bool, isCollidable, true); + u32 m_attrs = 0; // isOpaque needs a custom getter diff --git a/source/server/lua/loader/LuaBlockLoader.cpp b/source/server/lua/loader/LuaBlockLoader.cpp index bce3b389e..a4bcf172d 100644 --- a/source/server/lua/loader/LuaBlockLoader.cpp +++ b/source/server/lua/loader/LuaBlockLoader.cpp @@ -71,9 +71,9 @@ void LuaBlockLoader::loadBlockState(BlockState &state, const sol::table &table, if (!tiles.textureFilenames().empty()) state.tiles(tiles); + loadDrawType(state, table, block); loadProperties(state, table); loadBoundingBox(state, table); - loadDrawType(state, table, block); loadItemDrop(state, table); loadColorMultiplier(state, table); @@ -121,6 +121,9 @@ inline void LuaBlockLoader::loadProperties(BlockState &state, const sol::table & drawOffset.value().get(3), }); } + + if (table["is_collidable"].get_type() == sol::type::boolean) + state.isCollidable(table["is_collidable"].get()); } inline void LuaBlockLoader::loadBoundingBox(BlockState &state, const sol::table &table) const { @@ -161,6 +164,10 @@ inline void LuaBlockLoader::loadDrawType(BlockState &state, const sol::table &ta else gkError() << "In" << block.stringID() << " definition: Block draw type must be a string"; } + + if (state.drawType() == BlockDrawType::Liquid || state.drawType() == BlockDrawType::XShape) { + state.isCollidable(false); + } } inline void LuaBlockLoader::loadItemDrop(BlockState &state, const sol::table &table) const { diff --git a/texturepacks/minecraft/blocks/torch_on.png b/texturepacks/minecraft/blocks/torch_on.png new file mode 100644 index 0000000000000000000000000000000000000000..a2ce41b8ad537bb691d7ad063286503cd1fcfc30 GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`X`U{QAr-fh6C_xhW&Z3x_~C!O z{o(pgyg%&!+H*|Eb?}{Zw_ZNl^b_xlm^Yv9yT!NFFfW_7>u