diff --git a/client/include/gui/ItemWidget.hpp b/client/include/gui/ItemWidget.hpp index 9f9c9654..31f49259 100644 --- a/client/include/gui/ItemWidget.hpp +++ b/client/include/gui/ItemWidget.hpp @@ -35,7 +35,7 @@ class ItemWidget : public Widget { ItemWidget(Inventory &inventory, u16 x, u16 y, Widget *parent = nullptr); void update() override; - void updateImage(); + void updateImage(const Block *block = nullptr); const ItemStack &stack() const { return m_inventory.getStack(m_x, m_y); } void setStack(const std::string &name, unsigned int amount = 1); diff --git a/client/source/gui/ItemWidget.cpp b/client/source/gui/ItemWidget.cpp index 38677b03..994c6288 100644 --- a/client/source/gui/ItemWidget.cpp +++ b/client/source/gui/ItemWidget.cpp @@ -43,7 +43,7 @@ void ItemWidget::update() { m_isImage = false; } else - updateImage(); + updateImage(&block); } else updateImage(); @@ -52,7 +52,7 @@ void ItemWidget::update() { m_text.setPosition(16 - 4 - 6 * floor(log10(stack().amount())), 16 - 6, 0); } -void ItemWidget::updateImage() { +void ItemWidget::updateImage(const Block *block) { if (m_image.width() == 0) { m_image.load(m_textureAtlas.texture()); m_image.setPosition(1, 1, 0); @@ -63,6 +63,9 @@ void ItemWidget::updateImage() { m_image.setClipRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height); m_image.setScale(16.0f / clipRect.width, 16.0f / clipRect.height); + if (block) + m_image.setColor(block->colorMultiplier()); + m_isImage = true; } diff --git a/mods/default/blocks.lua b/mods/default/blocks.lua index c4188069..aff46d4a 100644 --- a/mods/default/blocks.lua +++ b/mods/default/blocks.lua @@ -144,3 +144,12 @@ mod:block { bounding_box = {0.25, 0.0, 0.25, 0.5, 0.5, 0.5}, } +mod:block { + id = "tallgrass", + name = "Tall Grass", + tiles = "grass.png", + color_multiplier = {129, 191, 91, 255}, + hardness = 0.05, + draw_type = 1, -- FIXME: Use string instead +} + diff --git a/mods/default/init.lua b/mods/default/init.lua index 0eacdb8a..eaa43e46 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -34,7 +34,8 @@ openminer:world():terrain_generator():set_blocks({ leaves = "default:leaves", flower = "default:flower", water = "default:water", - sand = "default:sand" + sand = "default:sand", + tallgrass = "default:tallgrass" }) function init(player) diff --git a/mods/default/textures/blocks/grass.png b/mods/default/textures/blocks/grass.png new file mode 100755 index 00000000..122ca1ba Binary files /dev/null and b/mods/default/textures/blocks/grass.png differ diff --git a/mods/default/textures_mc/blocks/grass.png b/mods/default/textures_mc/blocks/grass.png new file mode 100644 index 00000000..489dfa9a Binary files /dev/null and b/mods/default/textures_mc/blocks/grass.png differ diff --git a/server/include/world/TerrainGenerator.hpp b/server/include/world/TerrainGenerator.hpp index 225da26e..050a6744 100644 --- a/server/include/world/TerrainGenerator.hpp +++ b/server/include/world/TerrainGenerator.hpp @@ -51,6 +51,7 @@ class TerrainGenerator { u16 m_flowerBlockID = 0; u16 m_waterBlockID = 0; u16 m_sandBlockID = 0; + u16 m_tallgrassBlockID = 0; }; #endif // TERRAINGENERATOR_HPP_ diff --git a/server/source/world/TerrainGenerator.cpp b/server/source/world/TerrainGenerator.cpp index e868fac0..5e17ec26 100644 --- a/server/source/world/TerrainGenerator.cpp +++ b/server/source/world/TerrainGenerator.cpp @@ -37,14 +37,15 @@ void TerrainGenerator::generate(ServerChunk &chunk) const { } void TerrainGenerator::setBlocksFromLuaTable(const sol::table &table) { - m_dirtBlockID = Registry::getInstance().getBlockFromStringID(table["dirt"].get()).id(); - m_grassBlockID = Registry::getInstance().getBlockFromStringID(table["grass"].get()).id(); - m_stoneBlockID = Registry::getInstance().getBlockFromStringID(table["stone"].get()).id(); - m_logBlockID = Registry::getInstance().getBlockFromStringID(table["log"].get()).id(); - m_leavesBlockID = Registry::getInstance().getBlockFromStringID(table["leaves"].get()).id(); - m_flowerBlockID = Registry::getInstance().getBlockFromStringID(table["flower"].get()).id(); - m_waterBlockID = Registry::getInstance().getBlockFromStringID(table["water"].get()).id(); - m_sandBlockID = Registry::getInstance().getBlockFromStringID(table["sand"].get()).id(); + m_dirtBlockID = Registry::getInstance().getBlockFromStringID(table["dirt"].get()).id(); + m_grassBlockID = Registry::getInstance().getBlockFromStringID(table["grass"].get()).id(); + m_stoneBlockID = Registry::getInstance().getBlockFromStringID(table["stone"].get()).id(); + m_logBlockID = Registry::getInstance().getBlockFromStringID(table["log"].get()).id(); + m_leavesBlockID = Registry::getInstance().getBlockFromStringID(table["leaves"].get()).id(); + m_flowerBlockID = Registry::getInstance().getBlockFromStringID(table["flower"].get()).id(); + m_waterBlockID = Registry::getInstance().getBlockFromStringID(table["water"].get()).id(); + m_sandBlockID = Registry::getInstance().getBlockFromStringID(table["sand"].get()).id(); + m_tallgrassBlockID = Registry::getInstance().getBlockFromStringID(table["tallgrass"].get()).id(); } void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const { @@ -94,6 +95,10 @@ void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const { } } } + // Or tallgrass + else if(chunk.getBlock(x, y - 1, z) == m_grassBlockID && (rand() % 32) == 0) { + chunk.setBlockRaw(x, y, z, m_tallgrassBlockID); + } // Or a flower else if(chunk.getBlock(x, y - 1, z) == m_grassBlockID && (rand() & 0xff) == 0) { chunk.setBlockRaw(x, y, z, m_flowerBlockID);