Skip to content

Commit

Permalink
[TerrainGenerator] Tall Grass added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Feb 19, 2020
1 parent cb356b4 commit 949cc46
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/include/gui/ItemWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions client/source/gui/ItemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void ItemWidget::update() {
m_isImage = false;
}
else
updateImage();
updateImage(&block);
}
else
updateImage();
Expand All @@ -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);
Expand All @@ -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;
}

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

3 changes: 2 additions & 1 deletion mods/default/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file added mods/default/textures/blocks/grass.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/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions server/include/world/TerrainGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
21 changes: 13 additions & 8 deletions server/source/world/TerrainGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>()).id();
m_grassBlockID = Registry::getInstance().getBlockFromStringID(table["grass"].get<std::string>()).id();
m_stoneBlockID = Registry::getInstance().getBlockFromStringID(table["stone"].get<std::string>()).id();
m_logBlockID = Registry::getInstance().getBlockFromStringID(table["log"].get<std::string>()).id();
m_leavesBlockID = Registry::getInstance().getBlockFromStringID(table["leaves"].get<std::string>()).id();
m_flowerBlockID = Registry::getInstance().getBlockFromStringID(table["flower"].get<std::string>()).id();
m_waterBlockID = Registry::getInstance().getBlockFromStringID(table["water"].get<std::string>()).id();
m_sandBlockID = Registry::getInstance().getBlockFromStringID(table["sand"].get<std::string>()).id();
m_dirtBlockID = Registry::getInstance().getBlockFromStringID(table["dirt"].get<std::string>()).id();
m_grassBlockID = Registry::getInstance().getBlockFromStringID(table["grass"].get<std::string>()).id();
m_stoneBlockID = Registry::getInstance().getBlockFromStringID(table["stone"].get<std::string>()).id();
m_logBlockID = Registry::getInstance().getBlockFromStringID(table["log"].get<std::string>()).id();
m_leavesBlockID = Registry::getInstance().getBlockFromStringID(table["leaves"].get<std::string>()).id();
m_flowerBlockID = Registry::getInstance().getBlockFromStringID(table["flower"].get<std::string>()).id();
m_waterBlockID = Registry::getInstance().getBlockFromStringID(table["water"].get<std::string>()).id();
m_sandBlockID = Registry::getInstance().getBlockFromStringID(table["sand"].get<std::string>()).id();
m_tallgrassBlockID = Registry::getInstance().getBlockFromStringID(table["tallgrass"].get<std::string>()).id();
}

void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 949cc46

Please sign in to comment.