diff --git a/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp b/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp index 17cf37d1a..2a694c73a 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp @@ -30,7 +30,7 @@ static int l_place(lua::State* L) { auto offset = tovec3(L, 2); int rotation = tointeger(L, 3); fragment->getFragment(rotation)->place( - *scripting::level->chunks, offset + *scripting::controller, offset ); } return 0; diff --git a/src/world/generator/VoxelFragment.cpp b/src/world/generator/VoxelFragment.cpp index 8e86c1a78..68257f32e 100644 --- a/src/world/generator/VoxelFragment.cpp +++ b/src/world/generator/VoxelFragment.cpp @@ -11,6 +11,8 @@ #include "voxels/GlobalChunks.hpp" #include "voxels/VoxelsVolume.hpp" #include "voxels/blocks_agent.hpp" +#include "logic/LevelController.hpp" +#include "lighting/Lighting.hpp" #include "world/Level.hpp" #include "core_defs.hpp" @@ -171,8 +173,12 @@ void VoxelFragment::prepare(const Content& content) { } void VoxelFragment::place( - GlobalChunks& chunks, const glm::ivec3& offset + LevelController& controller, const glm::ivec3& offset ) { + auto& level = *controller.getLevel(); + auto& chunks = *level.chunks; + auto lighting = controller.getChunksController()->lighting.get(); + const auto& defs = level.content.getIndices()->blocks; auto& structVoxels = getRuntimeVoxels(); for (int y = 0; y < size.y; y++) { int sy = y + offset.y; @@ -189,6 +195,10 @@ void VoxelFragment::place( blocks_agent::set( chunks, sx, sy, sz, structVoxel.id, structVoxel.state ); + if (lighting) { + const auto& def = defs.require(structVoxel.id); + lighting->onBlockSet(sx, sy, sz, def.rt.id); + } } } } diff --git a/src/world/generator/VoxelFragment.hpp b/src/world/generator/VoxelFragment.hpp index 8b49110e4..ac32dd050 100644 --- a/src/world/generator/VoxelFragment.hpp +++ b/src/world/generator/VoxelFragment.hpp @@ -12,6 +12,7 @@ inline constexpr int STRUCTURE_FORMAT_VERSION = 1; class Level; class Content; class GlobalChunks; +class LevelController; class VoxelFragment : public Serializable { glm::ivec3 size; @@ -45,7 +46,7 @@ public: /// @brief Place fragment to the world /// @param offset target location - void place(GlobalChunks& chunks, const glm::ivec3& offset); + void place(LevelController& controller, const glm::ivec3& offset); /// @brief Create structure copy rotated 90 deg. clockwise std::unique_ptr rotated(const Content& content) const;