5
5
import cn .nukkit .entity .Entity ;
6
6
import cn .nukkit .level .DimensionData ;
7
7
import cn .nukkit .level .biome .Biome ;
8
+ import cn .nukkit .nbt .tag .CompoundTag ;
8
9
import cn .nukkit .utils .collection .nb .Long2ObjectNonBlockingMap ;
9
10
import com .google .common .base .Preconditions ;
10
11
11
12
import java .io .IOException ;
13
+ import java .util .ArrayList ;
14
+ import java .util .List ;
12
15
import java .util .Map ;
13
16
14
17
/**
19
22
public class Chunk implements IChunk {
20
23
protected final Map <Long , Entity > entities ;
21
24
protected final Map <Long , BlockEntity > blockEntities ;
25
+ //delay load block entity and entity
26
+ protected List <CompoundTag > blockEntityNBT ;
27
+ protected List <CompoundTag > entityNBT ;
22
28
protected final LevelProvider provider ;
23
29
protected final ChunkSection [] sections ;
24
30
protected final short [] heightMap ;//256 size
@@ -41,6 +47,8 @@ private Chunk(
41
47
this .heightMap = new short [256 ];
42
48
this .entities = new Long2ObjectNonBlockingMap <>();
43
49
this .blockEntities = new Long2ObjectNonBlockingMap <>();
50
+ this .entityNBT = new ArrayList <>();
51
+ this .blockEntityNBT = new ArrayList <>();
44
52
}
45
53
46
54
private Chunk (
@@ -51,7 +59,9 @@ private Chunk(
51
59
final ChunkSection [] sections ,
52
60
final short [] heightMap ,
53
61
final Map <Long , Entity > entities ,
54
- final Map <Long , BlockEntity > blockEntities
62
+ final Map <Long , BlockEntity > blockEntities ,
63
+ final List <CompoundTag > entityNBT ,
64
+ final List <CompoundTag > blockEntityNBT
55
65
) {
56
66
this .chunkState = state ;
57
67
this .x = chunkX ;
@@ -61,6 +71,8 @@ private Chunk(
61
71
this .heightMap = heightMap ;
62
72
this .entities = entities ;
63
73
this .blockEntities = blockEntities ;
74
+ this .entityNBT = entityNBT ;
75
+ this .blockEntityNBT = blockEntityNBT ;
64
76
}
65
77
66
78
@ Override
@@ -380,8 +392,10 @@ public static class Builder implements IChunkBuilder {
380
392
cn .nukkit .level .newformat .LevelProvider levelProvider ;
381
393
ChunkSection [] sections ;
382
394
short [] heightMap ;
383
- Map <Long , Entity > entities ;
384
- Map <Long , BlockEntity > blockEntities ;
395
+ List <CompoundTag > entities ;
396
+ List <CompoundTag > blockEntities ;
397
+ List <CompoundTag > blockEntityNBT ;
398
+ List <CompoundTag > entityNBT ;
385
399
386
400
public Builder chunkX (int chunkX ) {
387
401
this .chunkX = chunkX ;
@@ -424,17 +438,22 @@ public Builder sections(ChunkSection[] sections) {
424
438
return this ;
425
439
}
426
440
441
+ @ Override
442
+ public ChunkSection [] getSections () {
443
+ return sections ;
444
+ }
445
+
427
446
public Builder heightMap (short [] heightMap ) {
428
447
this .heightMap = heightMap ;
429
448
return this ;
430
449
}
431
450
432
- public Builder entities (Map < Long , Entity > entities ) {
451
+ public Builder entities (List < CompoundTag > entities ) {
433
452
this .entities = entities ;
434
453
return this ;
435
454
}
436
455
437
- public Builder blockEntities (Map < Long , BlockEntity > blockEntities ) {
456
+ public Builder blockEntities (List < CompoundTag > blockEntities ) {
438
457
this .blockEntities = blockEntities ;
439
458
return this ;
440
459
}
@@ -444,15 +463,17 @@ public Chunk build() {
444
463
if (state == null ) state = ChunkState .NEW ;
445
464
if (sections == null ) sections = new ChunkSection [levelProvider .getDimensionData ().getChunkSectionCount ()];
446
465
if (heightMap == null ) heightMap = new short [256 ];
447
- if (entities == null ) entities = new Long2ObjectNonBlockingMap <>();
448
- if (blockEntities == null ) blockEntities = new Long2ObjectNonBlockingMap <>();
466
+ if (entities == null ) entities = new ArrayList <>();
467
+ if (blockEntities == null ) blockEntities = new ArrayList <>();
449
468
return new Chunk (
450
469
state ,
451
470
chunkX ,
452
471
chunkZ ,
453
472
levelProvider ,
454
473
sections ,
455
474
heightMap ,
475
+ new Long2ObjectNonBlockingMap <>(),
476
+ new Long2ObjectNonBlockingMap <>(),
456
477
entities ,
457
478
blockEntities
458
479
);
0 commit comments