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 000000000..eeff1d213 Binary files /dev/null and b/mods/default/textures/blocks/torch_on.png differ diff --git a/source/client/gui/TextButton.cpp b/source/client/gui/TextButton.cpp index 99214f57e..63caf6bc4 100644 --- a/source/client/gui/TextButton.cpp +++ b/source/client/gui/TextButton.cpp @@ -80,8 +80,8 @@ void TextButton::setText(const std::string &text) { m_text.setString(text); m_text.updateVertexBuffer(); m_text.setPosition( - std::roundf(m_width / 2.f - m_text.getSize().x / 2.f), - std::roundf(m_height / 2.f - m_text.getSize().y / 2.f) + std::roundf(m_width / 2.f - m_text.getSize().x / 2.f) + 0.5f, + std::roundf(m_height / 2.f - m_text.getSize().y / 2.f) + 0.5f ); } diff --git a/source/client/world/ChunkBuilder.cpp b/source/client/world/ChunkBuilder.cpp index e6d1c8fdb..059344c74 100644 --- a/source/client/world/ChunkBuilder.cpp +++ b/source/client/world/ChunkBuilder.cpp @@ -354,10 +354,10 @@ inline u8 ChunkBuilder::getAmbientOcclusion(s8f x, s8f y, s8f z, const gk::Vecto }; bool blockPresence[4] = { - blocks[0] && blocks[0]->block().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 000000000..a2ce41b8a Binary files /dev/null and b/texturepacks/minecraft/blocks/torch_on.png differ