1010import com .fastasyncworldedit .core .queue .IChunkGet ;
1111import com .fastasyncworldedit .core .queue .IChunkSet ;
1212import com .fastasyncworldedit .core .queue .implementation .QueueHandler ;
13- import com .fastasyncworldedit .core .queue .implementation .blocks .CharGetBlocks ;
13+ import com .fastasyncworldedit .core .queue .implementation .blocks .DataArray ;
14+ import com .fastasyncworldedit .core .queue .implementation .blocks .DataArrayGetBlocks ;
1415import com .fastasyncworldedit .core .util .MathMan ;
1516import com .fastasyncworldedit .core .util .collection .AdaptedMap ;
1617import com .google .common .base .Suppliers ;
6364
6465import static net .minecraft .core .registries .Registries .BIOME ;
6566
66- public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBlocks {
67+ public class PaperweightGetBlocks extends DataArrayGetBlocks implements BukkitGetBlocks {
6768
6869 private static final Logger LOGGER = LogManagerCompat .getLogger ();
6970
@@ -445,7 +446,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
445446 );
446447 LevelChunkSection newSection = PaperweightPlatformAdapter .newChunkSection (
447448 layerNo ,
448- new char [ 4096 ] ,
449+ DataArray . createEmpty () ,
449450 adapter ,
450451 biomeRegistry ,
451452 biomeData
@@ -456,7 +457,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
456457 newSection ,
457458 getSectionIndex
458459 )) {
459- updateGet (nmsChunk , levelChunkSections , newSection , new char [ 4096 ] , getSectionIndex );
460+ updateGet (nmsChunk , levelChunkSections , newSection , DataArray . createEmpty () , getSectionIndex );
460461 continue ;
461462 } else {
462463 existingSection = levelChunkSections [getSectionIndex ];
@@ -479,9 +480,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
479480
480481 // setArr is modified by PaperweightPlatformAdapter#newChunkSection. This is in order to write changes to
481482 // this chunk GET when #updateGet is called. Future dords, please listen this time.
482- char [] tmp = set .load (layerNo );
483- char [] setArr = new char [tmp .length ];
484- System .arraycopy (tmp , 0 , setArr , 0 , tmp .length );
483+ DataArray setArr = DataArray .createCopy (set .load (layerNo ));
485484
486485 // synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
487486 // submitted to keep loaded internal chunks to queue target size.
@@ -498,10 +497,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
498497 }
499498
500499 if (createCopy ) {
501- char [] tmpLoad = loadPrivately (layerNo );
502- char [] copyArr = new char [4096 ];
503- System .arraycopy (tmpLoad , 0 , copyArr , 0 , 4096 );
504- copy .storeSection (getSectionIndex , copyArr );
500+ copy .storeSection (getSectionIndex , DataArray .createCopy (loadPrivately (layerNo )));
505501 if (biomes != null && existingSection != null ) {
506502 copy .storeBiomes (getSectionIndex , existingSection .getBiomes ());
507503 }
@@ -563,10 +559,8 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
563559 } else if (existingSection != getSections (false )[getSectionIndex ]) {
564560 this .sections [getSectionIndex ] = existingSection ;
565561 this .reset ();
566- } else if (!Arrays .equals (
567- update (getSectionIndex , new char [4096 ], true ),
568- loadPrivately (layerNo )
569- )) {
562+ } else if (!update (getSectionIndex , DataArray .createEmpty (), true )
563+ .equals (loadPrivately (layerNo ))) {
570564 this .reset (layerNo );
571565 /*} else if (lock.isModified()) {
572566 this.reset(layerNo);*/
@@ -837,7 +831,7 @@ private void updateGet(
837831 LevelChunk nmsChunk ,
838832 LevelChunkSection [] chunkSections ,
839833 LevelChunkSection section ,
840- char [] arr ,
834+ DataArray arr ,
841835 int layer
842836 ) {
843837 try {
@@ -862,14 +856,12 @@ private void updateGet(
862856 this .blocks [layer ] = arr ;
863857 }
864858
865- private char [] loadPrivately (int layer ) {
859+ private DataArray loadPrivately (int layer ) {
866860 layer -= getMinSectionPosition ();
867861 if (super .sections [layer ] != null ) {
868862 synchronized (super .sectionLocks [layer ]) {
869863 if (super .sections [layer ].isFull () && super .blocks [layer ] != null ) {
870- char [] blocks = new char [4096 ];
871- System .arraycopy (super .blocks [layer ], 0 , blocks , 0 , 4096 );
872- return blocks ;
864+ return DataArray .createCopy (super .blocks [layer ]);
873865 }
874866 }
875867 }
@@ -893,21 +885,14 @@ public synchronized void send(int mask, boolean lighting) {
893885 */
894886 @ Override
895887 @ SuppressWarnings ("unchecked" )
896- public char [] update (int layer , char [] data , boolean aggressive ) {
888+ public DataArray update (int layer , DataArray data , boolean aggressive ) {
897889 LevelChunkSection section = getSections (aggressive )[layer ];
898890 // Section is null, return empty array
899891 if (section == null ) {
900- data = new char [4096 ];
901- Arrays .fill (data , (char ) BlockTypesCache .ReservedIDs .AIR );
902- return data ;
892+ return DataArray .createFilled (BlockTypesCache .ReservedIDs .AIR );
903893 }
904- if (data != null && data .length != 4096 ) {
905- data = new char [4096 ];
906- Arrays .fill (data , (char ) BlockTypesCache .ReservedIDs .AIR );
907- }
908- if (data == null || data == FaweCache .INSTANCE .EMPTY_CHAR_4096 ) {
909- data = new char [4096 ];
910- Arrays .fill (data , (char ) BlockTypesCache .ReservedIDs .AIR );
894+ if (data == null || data == FaweCache .INSTANCE .EMPTY_DATA ) {
895+ data = DataArray .createFilled (BlockTypesCache .ReservedIDs .AIR );
911896 }
912897 Semaphore lock = PaperweightPlatformAdapter .applyLock (section );
913898 synchronized (lock ) {
@@ -920,7 +905,7 @@ public char[] update(int layer, char[] data, boolean aggressive) {
920905 final BitStorage bits = (BitStorage ) PaperweightPlatformAdapter .fieldStorage .get (dataObject );
921906
922907 if (bits instanceof ZeroBitStorage ) {
923- Arrays . fill ( data , adapter .adaptToChar (blocks .get (0 , 0 , 0 ))); // get(int) is only public on paper
908+ data . setAll ( adapter .adaptToChar (blocks .get (0 , 0 , 0 ))); // get(int) is only public on paper
924909 return data ;
925910 }
926911
@@ -937,9 +922,9 @@ public char[] update(int layer, char[] data, boolean aggressive) {
937922 } else {
938923 // The section's palette is the global block palette.
939924 for (int i = 0 ; i < 4096 ; i ++) {
940- char paletteVal = data [ i ] ;
925+ char paletteVal = ( char ) data . getAt ( i ) ;
941926 char ordinal = adapter .ibdIDToOrdinal (paletteVal );
942- data [ i ] = ordinal ;
927+ data . setAt ( i , ordinal ) ;
943928 }
944929 return data ;
945930 }
@@ -952,17 +937,17 @@ public char[] update(int layer, char[] data, boolean aggressive) {
952937 paletteToOrdinal [i ] = ordinal ;
953938 }
954939 for (int i = 0 ; i < 4096 ; i ++) {
955- char paletteVal = data [ i ] ;
940+ char paletteVal = ( char ) data . getAt ( i ) ;
956941 char val = paletteToOrdinal [paletteVal ];
957942 if (val == Character .MAX_VALUE ) {
958943 val = ordinal (palette .valueFor (i ), adapter );
959944 paletteToOrdinal [i ] = val ;
960945 }
961- data [ i ] = val ;
946+ data . setAt ( i , val ) ;
962947 }
963948 } else {
964949 char ordinal = ordinal (palette .valueFor (0 ), adapter );
965- Arrays . fill ( data , ordinal );
950+ data . setAll ( ordinal );
966951 }
967952 } finally {
968953 for (int i = 0 ; i < num_palette ; i ++) {
0 commit comments