From c5f83f9084b1fe2dea373f09e2698f1520a3a93e Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sun, 15 Mar 2020 16:54:24 +0100 Subject: [PATCH] [blocks.lua] Sugar canes added. --- client/source/graphics/TextureAtlas.cpp | 2 +- common/source/core/TilesDef.hpp | 1 + common/source/world/Block.cpp | 4 ++-- common/source/world/Block.hpp | 5 +++++ mods/default/blocks.lua | 9 +++++++++ mods/default/textures/blocks/reeds.png | Bin 0 -> 293 bytes mods/default/textures/items/reeds_item.png | Bin 0 -> 325 bytes mods/default/textures_mc/blocks/reeds.png | Bin 0 -> 186 bytes mods/default/textures_mc/items/reeds_item.png | Bin 0 -> 204 bytes server/source/lua/loader/LuaBlockLoader.cpp | 8 +++++++- 10 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 mods/default/textures/blocks/reeds.png create mode 100644 mods/default/textures/items/reeds_item.png create mode 100644 mods/default/textures_mc/blocks/reeds.png create mode 100644 mods/default/textures_mc/items/reeds_item.png diff --git a/client/source/graphics/TextureAtlas.cpp b/client/source/graphics/TextureAtlas.cpp index 1690af591..83088a986 100644 --- a/client/source/graphics/TextureAtlas.cpp +++ b/client/source/graphics/TextureAtlas.cpp @@ -117,7 +117,7 @@ void TextureAtlas::loadFromRegistry() { } for (auto &item : Registry::getInstance().items()) { - if (!item.isBlock()) { + if (!item.isBlock() || !item.tiles().textureFilenames().empty()) { const TilesDef &tiles = item.tiles(); for (auto &textureFilename : tiles.textureFilenames()) addFile("mods/" + item.modName() + "/textures/items/", textureFilename); diff --git a/common/source/core/TilesDef.hpp b/common/source/core/TilesDef.hpp index a405f28fd..912c13888 100644 --- a/common/source/core/TilesDef.hpp +++ b/common/source/core/TilesDef.hpp @@ -50,6 +50,7 @@ enum BlockFace : u8 { class TilesDef : public ISerializable { public: TilesDef() = default; + TilesDef(const std::string &texture) { m_textureFilenames.emplace_back(texture); } const std::string &getTextureForFace(u8 face, bool useAltTiles = false) const; diff --git a/common/source/world/Block.cpp b/common/source/world/Block.cpp index c65f4eb51..9eedf2fa4 100644 --- a/common/source/world/Block.cpp +++ b/common/source/world/Block.cpp @@ -50,7 +50,7 @@ void Block::serialize(sf::Packet &packet) const { << m_boundingBox.sizeX << m_boundingBox.sizeY << m_boundingBox.sizeZ << m_isLightSource << m_canUpdate << m_canBeActivated << m_colorMultiplier.r << m_colorMultiplier.g << m_colorMultiplier.b << m_colorMultiplier.a - << m_isRotatable; + << m_isRotatable << m_inventoryImage; } void Block::deserialize(sf::Packet &packet) { @@ -63,7 +63,7 @@ void Block::deserialize(sf::Packet &packet) { >> m_boundingBox.sizeX >> m_boundingBox.sizeY >> m_boundingBox.sizeZ >> m_isLightSource >> m_canUpdate >> m_canBeActivated >> m_colorMultiplier.r >> m_colorMultiplier.g >> m_colorMultiplier.b >> m_colorMultiplier.a - >> m_isRotatable; + >> m_isRotatable >> m_inventoryImage; m_id = id; m_drawType = BlockDrawType(drawType); diff --git a/common/source/world/Block.hpp b/common/source/world/Block.hpp index 5e53f8095..8e4395b58 100644 --- a/common/source/world/Block.hpp +++ b/common/source/world/Block.hpp @@ -106,6 +106,9 @@ class Block : public ISerializable { bool isRotatable() const { return m_isRotatable; } void setRotatable(bool isRotatable) { m_isRotatable = isRotatable; } + const std::string &inventoryImage() const { return m_inventoryImage; } + void setInventoryImage(const std::string &inventoryImage) { m_inventoryImage = inventoryImage; } + protected: glm::vec4 getTexCoordsFromID(int textureID) const; @@ -136,6 +139,8 @@ class Block : public ISerializable { gk::Color m_colorMultiplier = gk::Color::White; bool m_isRotatable = false; + + std::string m_inventoryImage; }; #endif // BLOCK_HPP_ diff --git a/mods/default/blocks.lua b/mods/default/blocks.lua index 4916ecdf6..c68a94bd1 100644 --- a/mods/default/blocks.lua +++ b/mods/default/blocks.lua @@ -275,3 +275,12 @@ mod:block { hardness = 2, } +mod:block { + id = "reeds", + name = "Sugar Canes", + tiles = "reeds.png", + draw_type = "xshape", + hardness = 0.2, + inventory_image = "reeds_item.png" +} + diff --git a/mods/default/textures/blocks/reeds.png b/mods/default/textures/blocks/reeds.png new file mode 100644 index 0000000000000000000000000000000000000000..8298624b81f552350f9479485153d8855ce897be GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJH=ZtzAr-fhfBgS%&&;uYSL~KW0Jtv@KmYIF<6#=26IB8 zVZvL+h?onzY#l;GE^Gpl%`CGSHwZ{=VBKti-kK$8ua0c8s+hF}<@56Q?__h)lQD6Vi3opSHlu`kI$ zM8lFXbb&6=V$<_=M~evney54%$BBL}AmIpEiC9(KFo4$M>I1-F#9`XJ*X3Fj0l+V} z{VM>`nKOKQ97&7mO1K0V4iLjRaGiq7s<{L>`x)81s1pj z>2Nh+Zq7poP}L6-Y*=&D++&!6f17!cKx=sM7?!?RnthbEf}4-x+HjLV3wZxC`U`<4 XlxJtNeS?em00000NkvXXu0mjf{6U0= literal 0 HcmV?d00001 diff --git a/mods/default/textures_mc/blocks/reeds.png b/mods/default/textures_mc/blocks/reeds.png new file mode 100644 index 0000000000000000000000000000000000000000..64bbfe0ecbe99c55c7cf3edb9a3bb89190a6f4b3 GIT binary patch literal 186 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jh-%!Ar-fh6BwG7zt8_Wzs%sR zJ+sJ~U9q3`XS%9ftYH&S-+Xs&2JZ{8L!v%4`CsJcGcIK}{g=F1z?pF)n~^|~(ym4q z>4tYMPK`bn*kT%aJ}aHP*d~;w5Uk~-6@S03$RB=~6S=lIJ jpIj_>^JRlp90NmWN<(Of-Lx*CV;DSL{an^LB{Ts5=KDWb literal 0 HcmV?d00001 diff --git a/mods/default/textures_mc/items/reeds_item.png b/mods/default/textures_mc/items/reeds_item.png new file mode 100644 index 0000000000000000000000000000000000000000..40872c6619d308eec874e302ed1680f0ed85b546 GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`lRaG=Ln>}1CrAh-Tzxy~zpu8^ z|Lo`!|J0){Z)wg<;7!T2`?vqE{fUM%W#tU5Z-iFq1WJW!ox4=P`J?`njxgN@xNA D276Gu literal 0 HcmV?d00001 diff --git a/server/source/lua/loader/LuaBlockLoader.cpp b/server/source/lua/loader/LuaBlockLoader.cpp index 0680da755..bc0d9b6fd 100644 --- a/server/source/lua/loader/LuaBlockLoader.cpp +++ b/server/source/lua/loader/LuaBlockLoader.cpp @@ -46,7 +46,12 @@ void LuaBlockLoader::loadBlock(const sol::table &table) const { loadItemDrop(block, table); loadColorMultiplier(block, table); - Registry::getInstance().registerItem(block.tiles(), stringID, label).setIsBlock(true); + if (!block.inventoryImage().empty()) { + Registry::getInstance().registerItem(TilesDef{block.inventoryImage()}, stringID, label).setIsBlock(true); + } + else { + Registry::getInstance().registerItem(block.tiles(), stringID, label).setIsBlock(true); + } } inline void LuaBlockLoader::loadProperties(ServerBlock &block, const sol::table &table) const { @@ -58,6 +63,7 @@ inline void LuaBlockLoader::loadProperties(ServerBlock &block, const sol::table block.setOnTick(table["on_tick"]); block.setOnBlockPlaced(table["on_block_placed"]); block.setRotatable(table["is_rotatable"].get_or(false)); + block.setInventoryImage(table["inventory_image"].get_or("")); } inline void LuaBlockLoader::loadBoundingBox(ServerBlock &block, const sol::table &table) const {