Skip to content

Commit

Permalink
[Block] isLightSource attribute added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Feb 7, 2020
1 parent 81e37de commit e198cd2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions common/include/world/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Block : public ISerializable {

bool canUpdate() const { return m_canUpdate; }

bool isLightSource() const { return m_isLightSource; }
void setLightSource(bool isLightSource) { m_isLightSource = isLightSource; }

protected:
glm::vec4 getTexCoordsFromID(int textureID) const;

Expand All @@ -109,6 +112,8 @@ class Block : public ISerializable {
BlockDrawType m_drawType = BlockDrawType::Solid;

bool m_isOpaque = true;

bool m_isLightSource = false;
};

#endif // BLOCK_HPP_
6 changes: 4 additions & 2 deletions common/source/world/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void Block::serialize(sf::Packet &packet) const {
packet << u32(m_id) << m_name << m_label << u8(m_drawType)
<< m_hardness << m_harvestRequirements << m_itemDrop << m_itemDropAmount << m_tiles
<< m_boundingBox.x << m_boundingBox.y << m_boundingBox.z
<< m_boundingBox.width << m_boundingBox.height << m_boundingBox.depth;
<< m_boundingBox.width << m_boundingBox.height << m_boundingBox.depth
<< m_isLightSource;
}

void Block::deserialize(sf::Packet &packet) {
Expand All @@ -44,7 +45,8 @@ void Block::deserialize(sf::Packet &packet) {
packet >> id >> m_name >> m_label >> drawType >> m_hardness
>> m_harvestRequirements >> m_itemDrop >> m_itemDropAmount >> m_tiles
>> m_boundingBox.x >> m_boundingBox.y >> m_boundingBox.z
>> m_boundingBox.width >> m_boundingBox.height >> m_boundingBox.depth;
>> m_boundingBox.width >> m_boundingBox.height >> m_boundingBox.depth
>> m_isLightSource;

m_id = id;
m_drawType = BlockDrawType(drawType);
Expand Down
6 changes: 1 addition & 5 deletions common/source/world/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ void Chunk::setBlock(int x, int y, int z, u16 type) {
if (m_data[x][y][z] == type) return;

const Block &block = Registry::getInstance().getBlock(type);
// if (type == 8)
// DEBUG("at (", m_x, m_y, m_z, ")", "(", x, y, z, ")", type, "is", block.canUpdate());
if (block.canUpdate()) {
m_tickingBlocks.emplace(x + y * width + z * width * height, block);
}
Expand All @@ -70,12 +68,10 @@ void Chunk::setBlock(int x, int y, int z, u16 type) {
m_tickingBlocks.erase(it);
}

if (type == BlockType::Glowstone)
if (block.isLightSource())
m_lightmap.addTorchlight(x, y, z, 14);
else {
// else if (m_data[x][y][z] == BlockType::Glowstone)
m_lightmap.removeTorchlight(x, y, z);
// else {
m_lightmap.removeSunlight(x, y, z);
}

Expand Down
3 changes: 2 additions & 1 deletion mods/default/blocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ mod:block {
mod:block {
id = "glowstone",
name = "Glowstone",
tiles = "glowstone.png"
tiles = "glowstone.png",
is_light_source = true
}

dofile("mods/default/workbench.lua")
Expand Down
3 changes: 1 addition & 2 deletions mods/default/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ function init(player)
player_inv:add_stack("default:glowstone", 64);
player_inv:add_stack("default:furnace", 1);
player_inv:add_stack("default:stone_pickaxe", 1);
player_inv:add_stack("default:stone_axe", 1);

player_inv:add_stack("default:wood", 64);
player_inv:add_stack("default:planks", 64);
player_inv:add_stack("default:cobblestone", 64);
player_inv:add_stack("default:stick", 64);
player_inv:add_stack("default:stone_axe", 1);
player_inv:add_stack("default:stone_hoe", 1);
player_inv:add_stack("default:stone_pickaxe", 1);
player_inv:add_stack("default:stone_shovel", 1);
player_inv:add_stack("default:iron_ore", 64);
player_inv:add_stack("default:coal", 64);
Expand Down
1 change: 1 addition & 0 deletions server/source/lua/LuaMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void LuaMod::registerBlock(const sol::table &table) {
block.setHarvestRequirements(table["harvest_requirements"].get_or(0));
block.setHardness(table["hardness"].get_or(1.0f));
block.setOpaque(table["is_opaque"].get_or(true));
block.setLightSource(table["is_light_source"].get_or(false));
block.setOnBlockActivated(onBlockActivated);
block.setOnTick(onTick);

Expand Down

0 comments on commit e198cd2

Please sign in to comment.