mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-15 11:51:53 +01:00
Don't relight entire chunk
This commit is contained in:
parent
225a834ef8
commit
aca67fc5d8
@ -775,12 +775,13 @@ public abstract class Instance implements Block.Getter, Block.Setter,
|
||||
if (chunk == null) return 0;
|
||||
Section section = chunk.getSectionAt(blockY);
|
||||
Light light = section.blockLight();
|
||||
int sectionCoordinate = ChunkUtils.getChunkCoordinate(blockY);
|
||||
|
||||
int coordX = ChunkUtils.toSectionRelativeCoordinate(blockX);
|
||||
int coordY = ChunkUtils.toSectionRelativeCoordinate(blockY);
|
||||
int coordZ = ChunkUtils.toSectionRelativeCoordinate(blockZ);
|
||||
|
||||
if (light.requiresUpdate()) LightingChunk.relight(chunk.getInstance(), List.of(chunk));
|
||||
if (light.requiresUpdate()) LightingChunk.relightSection(chunk.getInstance(), chunk.chunkX, sectionCoordinate, chunk.chunkZ);
|
||||
return light.getLevel(coordX, coordY, coordZ);
|
||||
}
|
||||
|
||||
@ -789,12 +790,13 @@ public abstract class Instance implements Block.Getter, Block.Setter,
|
||||
if (chunk == null) return 0;
|
||||
Section section = chunk.getSectionAt(blockY);
|
||||
Light light = section.skyLight();
|
||||
int sectionCoordinate = ChunkUtils.getChunkCoordinate(blockY);
|
||||
|
||||
int coordX = ChunkUtils.toSectionRelativeCoordinate(blockX);
|
||||
int coordY = ChunkUtils.toSectionRelativeCoordinate(blockY);
|
||||
int coordZ = ChunkUtils.toSectionRelativeCoordinate(blockZ);
|
||||
|
||||
if (light.requiresUpdate()) LightingChunk.relight(chunk.getInstance(), List.of(chunk));
|
||||
if (light.requiresUpdate()) LightingChunk.relightSection(chunk.getInstance(), chunk.chunkX, sectionCoordinate, chunk.chunkZ);
|
||||
return light.getLevel(coordX, coordY, coordZ);
|
||||
}
|
||||
}
|
@ -323,16 +323,15 @@ public class LightingChunk extends DynamicChunk {
|
||||
*
|
||||
* @param instance the instance
|
||||
* @param chunks the chunks to relight
|
||||
* @return the chunks which have been relighted
|
||||
*/
|
||||
public static void relight(Instance instance, Collection<Chunk> chunks) {
|
||||
public static List<Chunk> relight(Instance instance, Collection<Chunk> chunks) {
|
||||
Set<Point> sections = new HashSet<>();
|
||||
|
||||
synchronized (instance) {
|
||||
for (Chunk chunk : chunks) {
|
||||
if (chunk == null) continue;
|
||||
if (chunk instanceof LightingChunk lighting) {
|
||||
if (!lighting.isLightingCalculated()) return;
|
||||
|
||||
for (int section = chunk.minSection; section < chunk.maxSection; section++) {
|
||||
chunk.getSection(section).blockLight().invalidate();
|
||||
chunk.getSection(section).skyLight().invalidate();
|
||||
@ -358,6 +357,17 @@ public class LightingChunk extends DynamicChunk {
|
||||
|
||||
relight(instance, blockSections, LightType.BLOCK);
|
||||
relight(instance, skySections, LightType.SKY);
|
||||
|
||||
var chunksToRelight = new HashSet<Chunk>();
|
||||
for (Point point : blockSections) {
|
||||
chunksToRelight.add(instance.getChunk(point.blockX(), point.blockZ()));
|
||||
}
|
||||
|
||||
for (Point point : skySections) {
|
||||
chunksToRelight.add(instance.getChunk(point.blockX(), point.blockZ()));
|
||||
}
|
||||
|
||||
return new ArrayList<>(chunksToRelight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,6 +352,31 @@ public class BlockLightMergeIntegrationTest {
|
||||
assertEquals(5, val2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lightLookupTest(Env env) {
|
||||
Instance instance = env.createFlatInstance();
|
||||
instance.setChunkSupplier(LightingChunk::new);
|
||||
for (int x = 4; x <= 7; x++) {
|
||||
for (int z = 6; z <= 8; z++) {
|
||||
instance.loadChunk(x, z).join();
|
||||
}
|
||||
}
|
||||
|
||||
instance.setBlock(94, -35, 128, Block.GLOW_LICHEN.withProperties(Map.of("west", "true")));
|
||||
|
||||
var val = instance.getBlockLight(94, -35, 128);
|
||||
assertEquals(7, val);
|
||||
|
||||
var val2 = instance.getBlockLight(94, -36, 128);
|
||||
assertEquals(6, val2);
|
||||
|
||||
var val3 = instance.getSkyLight(94, -34, 128);
|
||||
assertEquals(0, val3);
|
||||
|
||||
var val4 = instance.getSkyLight(94, 41, 128);
|
||||
assertEquals(15, val4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skylight(Env env) {
|
||||
Instance instance = env.createFlatInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user