From f506afdcb23fed22f2c7f345b94cb411487f89c9 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 26 Nov 2015 10:21:39 +0100 Subject: [PATCH] safer method for lighting entities --- src/world/world.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/world/world.cpp b/src/world/world.cpp index 28e4195..893285e 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -768,23 +768,23 @@ void World::GetLight( glm::vec3 &col, glm::vec3 &amb ) { - Chunk *chunk = chunks.Get(e.ChunkCoords()); - if (!chunk) { + BlockLookup center(chunks.Get(e.ChunkCoords()), e.Position()); + if (!center) { // chunk unavailable, so make it really dark and from // some arbitrary direction dir = glm::vec3(1.0f, 2.0f, 3.0f); col = glm::vec3(0.025f); // ~0.8^15 return; } - glm::ivec3 base(e.Position()); - int base_light = chunk->GetLight(base); + glm::ivec3 base(center.GetBlockPos()); + int base_light = center.GetLight(); int max_light = 0; int min_light = 15; glm::ivec3 acc(0, 0, 0); for (glm::ivec3 offset(-1, -1, -1); offset.z < 2; ++offset.z) { for (offset.y = -1; offset.y < 2; ++offset.y) { for (offset.x = -1; offset.x < 2; ++offset.x) { - BlockLookup block(chunk, base + offset); + BlockLookup block(¢er.GetChunk(), center.GetBlockPos() + offset); if (!block) { // missing, just ignore it continue; -- 2.39.2