25
25
* Represents a dynamic light source which is deferred to a {@link DynamicLightBehavior}.
26
26
*
27
27
* @author LambdAurora, Akarys
28
- * @version 4.0.0
28
+ * @version 4.0.1
29
29
* @since 4.0.0
30
30
*/
31
- public record DeferredDynamicLightSource (DynamicLightBehavior behavior ) implements DynamicLightSource {
31
+ public final class DeferredDynamicLightSource implements DynamicLightSource {
32
+ private final DynamicLightBehavior behavior ;
33
+ private DynamicLightBehavior .BoundingBox previousBoundingBox ;
34
+
35
+ public DeferredDynamicLightSource (DynamicLightBehavior behavior ) {
36
+ this .behavior = behavior ;
37
+ this .previousBoundingBox = null ;
38
+ }
39
+
40
+ public DynamicLightBehavior behavior () {
41
+ return this .behavior ;
42
+ }
43
+
32
44
@ Override
33
45
public Stream <SpatialLookupEntry > splitIntoDynamicLightEntries () {
34
46
DynamicLightBehavior .BoundingBox boundingBox = this .behavior .getBoundingBox ();
@@ -60,6 +72,17 @@ public LongSet getDynamicLightChunksToRebuild(boolean forced) {
60
72
61
73
var chunks = new LongOpenHashSet ();
62
74
75
+ addBoundingBoxToChunksSet (chunks , boundingBox );
76
+ if (this .previousBoundingBox != null ) {
77
+ addBoundingBoxToChunksSet (chunks , this .previousBoundingBox );
78
+ }
79
+
80
+ this .previousBoundingBox = boundingBox ;
81
+
82
+ return chunks ;
83
+ }
84
+
85
+ private static void addBoundingBoxToChunksSet (LongSet set , DynamicLightBehavior .BoundingBox boundingBox ) {
63
86
int chunkStartX = getStartChunk (boundingBox .startX ());
64
87
int chunkStartY = getStartChunk (boundingBox .startY ());
65
88
int chunkStartZ = getStartChunk (boundingBox .startZ ());
@@ -70,12 +93,10 @@ public LongSet getDynamicLightChunksToRebuild(boolean forced) {
70
93
for (int x = chunkStartX ; x <= chunkEndX ; x ++) {
71
94
for (int y = chunkStartY ; y <= chunkEndY ; y ++) {
72
95
for (int z = chunkStartZ ; z <= chunkEndZ ; z ++) {
73
- chunks .add (ChunkSectionPos .asLong (x , y , z ));
96
+ set .add (ChunkSectionPos .asLong (x , y , z ));
74
97
}
75
98
}
76
99
}
77
-
78
- return chunks ;
79
100
}
80
101
81
102
private static int getStartChunk (int blockPos ) {
0 commit comments