66import com .fastasyncworldedit .core .history .change .MutableEntityChange ;
77import com .fastasyncworldedit .core .history .change .MutableFullBlockChange ;
88import com .fastasyncworldedit .core .history .change .MutableTileChange ;
9+ import com .fastasyncworldedit .core .history .change .BlockPositionChange ;
910import com .fastasyncworldedit .core .internal .exception .FaweSmallEditUnsupportedException ;
1011import com .fastasyncworldedit .core .internal .io .FaweInputStream ;
1112import com .fastasyncworldedit .core .internal .io .FaweOutputStream ;
2021import com .sk89q .worldedit .world .World ;
2122import com .sk89q .worldedit .world .biome .BiomeType ;
2223import com .sk89q .worldedit .world .block .BlockTypes ;
24+ import org .jetbrains .annotations .ApiStatus ;
2325
2426import java .io .EOFException ;
2527import java .io .IOException ;
3234/**
3335 * FAWE stream ChangeSet offering support for extended-height worlds
3436 */
37+ @ ApiStatus .Internal
3538public abstract class FaweStreamChangeSet extends AbstractChangeSet {
3639
3740 public static final int HEADER_SIZE = 9 ;
@@ -68,19 +71,15 @@ private void init(boolean storeRedo, boolean smallLoc) {
6871 }
6972 }
7073
71- public interface FaweStreamPositionDelegate {
74+ interface FaweStreamPositionDelegate {
7275
7376 void write (OutputStream out , int x , int y , int z ) throws IOException ;
7477
75- int readX (FaweInputStream in ) throws IOException ;
76-
77- int readY (FaweInputStream in ) throws IOException ;
78-
79- int readZ (FaweInputStream in ) throws IOException ;
78+ void read (FaweInputStream in , BlockPositionChange change ) throws IOException ;
8079
8180 }
8281
83- public interface FaweStreamIdDelegate {
82+ interface FaweStreamIdDelegate {
8483
8584 void writeChange (FaweOutputStream out , int from , int to ) throws IOException ;
8685
@@ -138,6 +137,7 @@ public void readCombined(FaweInputStream is, MutableFullBlockChange change) thro
138137 }
139138 if (mode == 1 || mode == 4 ) { // small
140139 posDel = new FaweStreamPositionDelegate () {
140+ final byte [] buffer = new byte [4 ];
141141 int lx ;
142142 int ly ;
143143 int lz ;
@@ -162,23 +162,14 @@ public void write(OutputStream out, int x, int y, int z) throws IOException {
162162 out .write (b4 );
163163 }
164164
165- final byte [] buffer = new byte [4 ];
166-
167165 @ Override
168- public int readX ( FaweInputStream in ) throws IOException {
166+ public void read ( final FaweInputStream in , final BlockPositionChange change ) throws IOException {
169167 in .readFully (buffer );
170- return lx = lx + ((((buffer [1 ] & 0xFF ) | ((MathMan .unpair16x (buffer [3 ])) << 8 )) << 20 ) >> 20 );
168+ change .x = lx = lx + ((((buffer [1 ] & 0xFF ) | ((MathMan .unpair16x (buffer [3 ])) << 8 )) << 20 ) >> 20 );
169+ change .y = (ly = ly + buffer [0 ]) & 0xFF ;
170+ change .z = lz = lz + ((((buffer [2 ] & 0xFF ) | ((MathMan .unpair16y (buffer [3 ])) << 8 )) << 20 ) >> 20 );
171171 }
172172
173- @ Override
174- public int readY (FaweInputStream in ) {
175- return (ly = ly + buffer [0 ]) & 0xFF ;
176- }
177-
178- @ Override
179- public int readZ (FaweInputStream in ) throws IOException {
180- return lz = lz + ((((buffer [2 ] & 0xFF ) | ((MathMan .unpair16y (buffer [3 ])) << 8 )) << 20 ) >> 20 );
181- }
182173 };
183174 } else {
184175 posDel = new FaweStreamPositionDelegate () {
@@ -201,19 +192,11 @@ public void write(OutputStream stream, int x, int y, int z) throws IOException {
201192 }
202193
203194 @ Override
204- public int readX (FaweInputStream is ) throws IOException {
205- is .readFully (buffer );
206- return lx = lx + ((buffer [0 ] & 0xFF ) | (buffer [1 ] << 8 ));
207- }
208-
209- @ Override
210- public int readY (FaweInputStream is ) throws IOException {
211- return ly = ly + ((buffer [4 ] & 0xFF ) | (buffer [5 ]) << 8 );
212- }
213-
214- @ Override
215- public int readZ (FaweInputStream is ) throws IOException {
216- return lz = lz + ((buffer [2 ] & 0xFF ) | (buffer [3 ]) << 8 );
195+ public void read (final FaweInputStream in , final BlockPositionChange change ) throws IOException {
196+ in .readFully (buffer );
197+ change .x = lx = lx + ((buffer [0 ] & 0xFF ) | (buffer [1 ] << 8 ));
198+ change .z = lz = lz + ((buffer [2 ] & 0xFF ) | (buffer [3 ]) << 8 );
199+ change .y = ly = ly + ((buffer [4 ] & 0xFF ) | (buffer [5 ]) << 8 );
217200 }
218201 };
219202 }
@@ -428,9 +411,9 @@ public Iterator<MutableBlockChange> getBlockIterator(final boolean dir) throws I
428411
429412 public MutableBlockChange read () {
430413 try {
431- change . x = posDel .readX (is ) + originX ;
432- change .y = posDel . readY ( is ) ;
433- change .z = posDel . readZ ( is ) + originZ ;
414+ posDel .read (is , change ) ;
415+ change .x += originX ;
416+ change .z += originZ ;
434417 idDel .readCombined (is , change , dir );
435418 return change ;
436419 } catch (EOFException ignored ) {
@@ -545,9 +528,9 @@ public Iterator<MutableFullBlockChange> getFullBlockIterator(BlockBag blockBag,
545528
546529 public MutableFullBlockChange read () {
547530 try {
548- change . x = posDel .readX (is ) + originX ;
549- change .y = posDel . readY ( is ) ;
550- change .z = posDel . readZ ( is ) + originZ ;
531+ posDel .read (is , change ) ;
532+ change .x += originX ;
533+ change .z += originZ ;
551534 idDel .readCombined (is , change );
552535 return change ;
553536 } catch (EOFException ignored ) {
@@ -765,11 +748,9 @@ public SimpleChangeSetSummary summarize(Region region, boolean shallow) {
765748 int amount = (Settings .settings ().HISTORY .BUFFER_SIZE - HEADER_SIZE ) / 9 ;
766749 MutableFullBlockChange change = new MutableFullBlockChange (null , 0 , false );
767750 for (int i = 0 ; i < amount ; i ++) {
768- int x = posDel .readX (fis ) + ox ;
769- int y = posDel .readY (fis );
770- int z = posDel .readZ (fis ) + ox ;
751+ posDel .read (fis , change );
771752 idDel .readCombined (fis , change );
772- summary .add (x , z , change .to );
753+ summary .add (change . x + ox , change . z + oz , change .to );
773754 }
774755 }
775756 } catch (EOFException ignored ) {
0 commit comments