Skip to content

Commit

Permalink
[blocks.lua] Sugar canes added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Mar 15, 2020
1 parent 4b58389 commit c5f83f9
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/source/graphics/TextureAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions common/source/core/TilesDef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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 @@ -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) {
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions common/source/world/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_
9 changes: 9 additions & 0 deletions mods/default/blocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Binary file added mods/default/textures/blocks/reeds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/default/textures/items/reeds_item.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/default/textures_mc/blocks/reeds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/default/textures_mc/items/reeds_item.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion server/source/lua/loader/LuaBlockLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<std::string>(""));
}

inline void LuaBlockLoader::loadBoundingBox(ServerBlock &block, const sol::table &table) const {
Expand Down

0 comments on commit c5f83f9

Please sign in to comment.