[Block] isLightSource attribute added.
This commit is contained in:
parent
81e37de144
commit
e198cd272d
@ -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;
|
||||
|
||||
@ -109,6 +112,8 @@ class Block : public ISerializable {
|
||||
BlockDrawType m_drawType = BlockDrawType::Solid;
|
||||
|
||||
bool m_isOpaque = true;
|
||||
|
||||
bool m_isLightSource = false;
|
||||
};
|
||||
|
||||
#endif // BLOCK_HPP_
|
||||
|
@ -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) {
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user