7
7
import com .fastasyncworldedit .core .history .change .MutableEntityChange ;
8
8
import com .fastasyncworldedit .core .history .change .MutableFullBlockChange ;
9
9
import com .fastasyncworldedit .core .history .change .MutableTileChange ;
10
+ import com .fastasyncworldedit .core .history .change .BlockPositionChange ;
10
11
import com .fastasyncworldedit .core .internal .exception .FaweSmallEditUnsupportedException ;
11
12
import com .fastasyncworldedit .core .internal .io .FaweInputStream ;
12
13
import com .fastasyncworldedit .core .internal .io .FaweOutputStream ;
22
23
import com .sk89q .worldedit .world .World ;
23
24
import com .sk89q .worldedit .world .biome .BiomeType ;
24
25
import com .sk89q .worldedit .world .block .BlockTypes ;
26
+ import org .jetbrains .annotations .ApiStatus ;
25
27
import org .jetbrains .annotations .NotNull ;
26
28
import org .jetbrains .annotations .Nullable ;
27
29
30
32
import java .io .InputStream ;
31
33
import java .io .OutputStream ;
32
34
import java .util .ArrayDeque ;
33
- import java .util .Arrays ;
34
35
import java .util .Collections ;
35
36
import java .util .Iterator ;
36
37
import java .util .List ;
42
43
/**
43
44
* FAWE stream ChangeSet offering support for extended-height worlds
44
45
*/
46
+ @ ApiStatus .Internal
45
47
public abstract class FaweStreamChangeSet extends AbstractChangeSet {
46
48
47
49
public static final int HEADER_SIZE = 9 ;
@@ -85,19 +87,15 @@ private void init(boolean storeRedo, boolean smallLoc) {
85
87
}
86
88
}
87
89
88
- public interface FaweStreamPositionDelegate {
90
+ interface FaweStreamPositionDelegate {
89
91
90
92
void write (OutputStream out , int x , int y , int z ) throws IOException ;
91
93
92
- int readX (FaweInputStream in ) throws IOException ;
93
-
94
- int readY (FaweInputStream in ) throws IOException ;
95
-
96
- int readZ (FaweInputStream in ) throws IOException ;
94
+ void read (FaweInputStream in , BlockPositionChange change ) throws IOException ;
97
95
98
96
}
99
97
100
- public interface FaweStreamIdDelegate {
98
+ interface FaweStreamIdDelegate {
101
99
102
100
void writeChange (FaweOutputStream out , int from , int to ) throws IOException ;
103
101
@@ -155,6 +153,7 @@ public void readCombined(FaweInputStream is, MutableFullBlockChange change) thro
155
153
}
156
154
if (mode == 1 || mode == 4 ) { // small
157
155
posDel = new FaweStreamPositionDelegate () {
156
+ final byte [] buffer = new byte [4 ];
158
157
int lx ;
159
158
int ly ;
160
159
int lz ;
@@ -179,23 +178,14 @@ public void write(OutputStream out, int x, int y, int z) throws IOException {
179
178
out .write (b4 );
180
179
}
181
180
182
- final byte [] buffer = new byte [4 ];
183
-
184
181
@ Override
185
- public int readX ( FaweInputStream in ) throws IOException {
182
+ public void read ( final FaweInputStream in , final BlockPositionChange change ) throws IOException {
186
183
in .readFully (buffer );
187
- return lx = lx + ((((buffer [1 ] & 0xFF ) | ((MathMan .unpair16x (buffer [3 ])) << 8 )) << 20 ) >> 20 );
184
+ change .x = lx = lx + ((((buffer [1 ] & 0xFF ) | ((MathMan .unpair16x (buffer [3 ])) << 8 )) << 20 ) >> 20 );
185
+ change .y = (ly = ly + buffer [0 ]) & 0xFF ;
186
+ change .z = lz = lz + ((((buffer [2 ] & 0xFF ) | ((MathMan .unpair16y (buffer [3 ])) << 8 )) << 20 ) >> 20 );
188
187
}
189
188
190
- @ Override
191
- public int readY (FaweInputStream in ) {
192
- return (ly = ly + buffer [0 ]) & 0xFF ;
193
- }
194
-
195
- @ Override
196
- public int readZ (FaweInputStream in ) throws IOException {
197
- return lz = lz + ((((buffer [2 ] & 0xFF ) | ((MathMan .unpair16y (buffer [3 ])) << 8 )) << 20 ) >> 20 );
198
- }
199
189
};
200
190
} else {
201
191
posDel = new FaweStreamPositionDelegate () {
@@ -232,25 +222,11 @@ public void write(OutputStream stream, int x, int y, int z) throws IOException {
232
222
}
233
223
234
224
@ Override
235
- public int readX (FaweInputStream is ) throws IOException {
236
- is .readFully (buffer );
237
- // Don't break reading version 1 history (just in case)
238
- if (version == 2 && Arrays .equals (buffer , MAGIC_NEW_RELATIVE )) {
239
- lx = ((is .read () << 24 ) + (is .read () << 16 ) + (is .read () << 8 ) + is .read ());
240
- lz = ((is .read () << 24 ) + (is .read () << 16 ) + (is .read () << 8 ) + is .read ());
241
- is .readFully (buffer );
242
- }
243
- return lx = lx + ((buffer [0 ] & 0xFF ) | (buffer [1 ] << 8 ));
244
- }
245
-
246
- @ Override
247
- public int readY (FaweInputStream is ) throws IOException {
248
- return ly = ly + ((buffer [4 ] & 0xFF ) | (buffer [5 ]) << 8 );
249
- }
250
-
251
- @ Override
252
- public int readZ (FaweInputStream is ) throws IOException {
253
- return lz = lz + ((buffer [2 ] & 0xFF ) | (buffer [3 ]) << 8 );
225
+ public void read (final FaweInputStream in , final BlockPositionChange change ) throws IOException {
226
+ in .readFully (buffer );
227
+ change .x = lx = lx + ((buffer [0 ] & 0xFF ) | (buffer [1 ] << 8 ));
228
+ change .z = lz = lz + ((buffer [2 ] & 0xFF ) | (buffer [3 ]) << 8 );
229
+ change .y = ly = ly + ((buffer [4 ] & 0xFF ) | (buffer [5 ]) << 8 );
254
230
}
255
231
};
256
232
}
@@ -453,9 +429,9 @@ public Iterator<MutableBlockChange> getBlockIterator(final boolean dir) throws I
453
429
454
430
public MutableBlockChange read () {
455
431
try {
456
- change . x = posDel .readX (is ) + originX ;
457
- change .y = posDel . readY ( is ) ;
458
- change .z = posDel . readZ ( is ) + originZ ;
432
+ posDel .read (is , change ) ;
433
+ change .x += originX ;
434
+ change .z += originZ ;
459
435
idDel .readCombined (is , change , dir );
460
436
return change ;
461
437
} catch (EOFException ignored ) {
@@ -570,9 +546,9 @@ public Iterator<MutableFullBlockChange> getFullBlockIterator(BlockBag blockBag,
570
546
571
547
public MutableFullBlockChange read () {
572
548
try {
573
- change . x = posDel .readX (is ) + originX ;
574
- change .y = posDel . readY ( is ) ;
575
- change .z = posDel . readZ ( is ) + originZ ;
549
+ posDel .read (is , change ) ;
550
+ change .x += originX ;
551
+ change .z += originZ ;
576
552
idDel .readCombined (is , change );
577
553
return change ;
578
554
} catch (EOFException ignored ) {
@@ -872,10 +848,10 @@ class Populator implements ChangePopulator<MutableFullBlockChange> {
872
848
@ Override
873
849
public @ Nullable MutableFullBlockChange populate (@ NotNull final MutableFullBlockChange change ) {
874
850
try {
875
- change .x = posDel .readX (is ) + originX ;
876
- change .y = posDel .readY (is );
877
- change .z = posDel .readZ (is ) + originZ ;
851
+ posDel .read (is , change );
878
852
idDel .readCombined (is , change );
853
+ change .x += originX ;
854
+ change .z += originZ ;
879
855
return change ;
880
856
} catch (EOFException ignored ) {
881
857
} catch (Exception e ) {
@@ -914,10 +890,10 @@ class Populator implements ChangePopulator<MutableBlockChange> {
914
890
@ Override
915
891
public @ Nullable MutableBlockChange populate (@ NotNull final MutableBlockChange change ) {
916
892
try {
917
- change .x = posDel .readX (is ) + originX ;
918
- change .y = posDel .readY (is );
919
- change .z = posDel .readZ (is ) + originZ ;
893
+ posDel .read (is , change );
920
894
idDel .readCombined (is , change , dir );
895
+ change .x += originX ;
896
+ change .z += originZ ;
921
897
return change ;
922
898
} catch (EOFException ignored ) {
923
899
} catch (Exception e ) {
@@ -1068,11 +1044,9 @@ public SimpleChangeSetSummary summarize(Region region, boolean shallow) {
1068
1044
int amount = (Settings .settings ().HISTORY .BUFFER_SIZE - HEADER_SIZE ) / 9 ;
1069
1045
MutableFullBlockChange change = new MutableFullBlockChange (null , 0 , false );
1070
1046
for (int i = 0 ; i < amount ; i ++) {
1071
- int x = posDel .readX (fis ) + ox ;
1072
- int y = posDel .readY (fis );
1073
- int z = posDel .readZ (fis ) + ox ;
1047
+ posDel .read (fis , change );
1074
1048
idDel .readCombined (fis , change );
1075
- summary .add (x , z , change .to );
1049
+ summary .add (change . x + ox , change . z + oz , change .to );
1076
1050
}
1077
1051
}
1078
1052
} catch (EOFException ignored ) {
0 commit comments