Skip to content

Commit

Permalink
[blocks.lua] Redstone Lamp now works with states. [furnace.lua] Now e…
Browse files Browse the repository at this point in the history
…mits light when on.
  • Loading branch information
Unarelith committed Jul 10, 2020
1 parent d68e17a commit a24deef
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions mods/default/blocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,16 @@ mod:block {

mod:block {
id = "redstone_lamp",
name = "Redstone Lamp (with states)",
name = "Redstone Lamp",
tiles = "redstone_lamp_off.png",

states = {
{ is_light_source = true, tiles = "redstone_lamp_on.png" }
},

on_block_activated = function(pos, block, player, world, client, server, screen_width, screen_height, gui_scale)
local current_state = math.abs(world:get_block_state(pos.x, pos.y, pos.z):id() - 1)
world:set_block_state(pos.x, pos.y, pos.z, current_state)
local next_state = math.abs(world:get_block_state(pos.x, pos.y, pos.z):id() - 1)
world:set_block_state(pos.x, pos.y, pos.z, next_state)
end
}

Expand Down
11 changes: 6 additions & 5 deletions mods/default/blocks/furnace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ mod:block {
is_rotatable = true,

states = {
{ tiles = {"furnace_top.png", "furnace_top.png", "furnace_front_on.png", "furnace_side.png"} },
{
is_light_source = true,
tiles = {"furnace_top.png", "furnace_top.png", "furnace_front_on.png", "furnace_side.png"},
},
},

on_block_placed = function(pos, world)
Expand Down Expand Up @@ -199,8 +202,7 @@ mod:block {
data.inventory:set_stack(2, 0, fuel_stack:item():string_id(), fuel_stack:amount() - 1)
ticks_remaining = fuel_stack:item():get_group_value("group:om_fuel")
current_burn_time = fuel_stack:item():get_group_value("group:om_fuel")
world:set_data(pos.x, pos.y, pos.z,
block:param():set_param(BlockParamType.State, block_param, 1))
world:set_block_state(pos.x, pos.y, pos.z, 1)
elseif ticks_remaining > 0 then
ticks_remaining = ticks_remaining - 1

Expand All @@ -212,8 +214,7 @@ mod:block {
end
elseif ticks_remaining == 0 then
current_burn_time = 0
world:set_data(pos.x, pos.y, pos.z,
block:param():set_param(BlockParamType.State, block_param, 0))
world:set_block_state(pos.x, pos.y, pos.z, 0)
end

if item_progress >= 200 and recipe then
Expand Down
3 changes: 2 additions & 1 deletion source/server/world/ServerChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ ServerChunk::ServerChunk(s32 x, s32 y, s32 z, World &world) : Chunk(x, y, z, wor
}

void ServerChunk::updateLights() {
if (m_lightmap.updateLights() || m_hasChanged) {
if (m_lightmap.updateLights() || m_hasChanged || m_hasLightChanged) {
m_isSent = false;
m_hasChanged = false;
m_hasLightChanged = false;
}
}

Expand Down
5 changes: 3 additions & 2 deletions source/server/world/ServerWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ void ServerWorld::update() {
for (auto &it : m_chunks) {
it.second->tick(*this, *m_server);

if (it.second->areAllNeighboursLoaded())
if (it.second->areAllNeighboursLoaded()) {
it.second->updateLights();
}

if (it.second->isInitialized() && !it.second->isSent()) {
for (auto &client : m_server->server().info().clients())
Expand Down Expand Up @@ -131,7 +132,7 @@ void ServerWorld::sendChunkData(const ClientInfo &client, ServerChunk &chunk) {
chunk.setSent(true);
chunk.setChanged(false);

// std::cout << "Chunk at (" << chunk.x() << ", " << chunk.y() << ", " << chunk.z() << ") sent to client" << std::endl;
// gkDebug() << "Chunk at" << chunk.x() << chunk.y() << chunk.z() << "sent to client";
}

void ServerWorld::sendRequestedData(ClientInfo &client, int cx, int cy, int cz) {
Expand Down

0 comments on commit a24deef

Please sign in to comment.