77import net .fabricmc .fabric .api .gametest .v1 .GameTest ;
88import net .minecraft .core .BlockPos ;
99import net .minecraft .core .Holder ;
10+ import net .minecraft .core .Vec3i ;
1011import net .minecraft .gametest .framework .GameTestHelper ;
1112import net .minecraft .server .level .ServerLevel ;
1213import net .minecraft .util .RandomSource ;
1920import net .minecraft .world .level .block .state .properties .BlockStateProperties ;
2021import net .minecraft .world .level .border .WorldBorder ;
2122
23+ import java .io .File ;
2224import java .lang .reflect .Method ;
25+ import java .util .Arrays ;
2326import java .util .Comparator ;
2427import java .util .List ;
2528import java .util .Optional ;
@@ -115,66 +118,66 @@ public void test(GameTestHelper context, BlockPos center, RandomSource randomSou
115118 }
116119
117120
118- // // Print to file if it does not exist yet, otherwise compare with existing file.
119- // File outputFile = new File("poi_search_output/" + context.getLevel().getSeed() + "_" + center.getX() + "_" + center.getY() + "_" + center.getZ() + ".txt");
120- // File newOutputFile = outputFile.exists() ? new File("poi_search_output/" + context.getLevel().getSeed() + "_" + center.getX() + "_" + center.getY() + "_" + center.getZ() + "_new.txt") : outputFile;
121- //
122- // StringBuilder sb = new StringBuilder();
123- // sb.append("countInRange:").append(countInRange).append("\n");
124- // sb.append("getInSquare: ");
125- // sb.append(Arrays.toString(inSquarePositions.toArray()));
126- // sb.append("\n");
127- // sb.append("getInRange: ");
128- // sb.append(Arrays.toString(inRangePositions.toArray()));
129- // sb.append("\n");
130- // sb.append("getInChunk: ");
131- // sb.append(Arrays.toString(inChunkPositions.toArray()));
132- // sb.append("\n");
133- // sb.append("findAll: ");
134- // sb.append(Arrays.toString(allPositions.toArray()));
135- // sb.append("\n");
136- // sb.append("findAllWithType: ");
137- // sb.append(Arrays.toString(allWithTypePositions.toArray()));
138- // sb.append("\n");
139- // sb.append("findAllClosestFirstWithType: ");
140- // sb.append(Arrays.toString(allClosestFirstWithTypePositions.toArray()));
141- // sb.append("\n");
142- // sb.append("find :").append(firstOfAll .map(Vec3i::toString).orElse("empty")).append("\n");
143- // sb.append("findClosest :").append(findClosest .map(Vec3i::toString).orElse("empty")).append("\n");
144- // sb.append("findClosestWithType :").append(findClosestWithType .map(Vec3i::toString).orElse("empty")).append("\n");
145- // sb.append("findClosest2 :").append(findClosest2 .map(Vec3i::toString).orElse("empty")).append("\n");
146- // sb.append("getRandom :").append(getRandom .map(Vec3i::toString).orElse("empty")).append("\n");
147- //
148- // if (!outputFile.exists()) {
149- // outputFile.getParentFile().mkdirs();
150- // try (java.io.FileWriter writer = new java.io.FileWriter(newOutputFile)) {
151- // writer.write(sb.toString());
152- // } catch (Exception e) {
153- // throw new RuntimeException(e);
154- // }
155- // } else {
156- // String existingContent;
157- // try (java.io.FileReader reader = new java.io.FileReader(outputFile);
158- // java.io.BufferedReader br = new java.io.BufferedReader(reader)) {
159- // StringBuilder existingSb = new StringBuilder();
160- // String line;
161- // while ((line = br.readLine()) != null) {
162- // existingSb.append(line).append("\n");
163- // }
164- // existingContent = existingSb.toString();
165- // } catch (Exception e) {
166- // throw new RuntimeException(e);
167- // }
168- //
169- // if (!existingContent.equals(sb.toString())) {
170- // try (java.io.FileWriter writer = new java.io.FileWriter(newOutputFile)) {
171- // writer.write(sb.toString());
172- // } catch (Exception e) {
173- // throw new RuntimeException(e);
174- // }
175- // throw new AssertionError("POI search results differ from expected output. See " + newOutputFile.getAbsolutePath());
176- // }
177- // }
121+ // Print to file if it does not exist yet, otherwise compare with existing file.
122+ File outputFile = new File ("poi_search_output/" + context .getLevel ().getSeed () + "_" + center .getX () + "_" + center .getY () + "_" + center .getZ () + ".txt" );
123+ File newOutputFile = outputFile .exists () ? new File ("poi_search_output/" + context .getLevel ().getSeed () + "_" + center .getX () + "_" + center .getY () + "_" + center .getZ () + "_new.txt" ) : outputFile ;
124+
125+ StringBuilder sb = new StringBuilder ();
126+ sb .append ("countInRange:" ).append (countInRange ).append ("\n " );
127+ sb .append ("getInSquare: " );
128+ sb .append (Arrays .toString (inSquarePositions .toArray ()));
129+ sb .append ("\n " );
130+ sb .append ("getInRange: " );
131+ sb .append (Arrays .toString (inRangePositions .toArray ()));
132+ sb .append ("\n " );
133+ sb .append ("getInChunk: " );
134+ sb .append (Arrays .toString (inChunkPositions .toArray ()));
135+ sb .append ("\n " );
136+ sb .append ("findAll: " );
137+ sb .append (Arrays .toString (allPositions .toArray ()));
138+ sb .append ("\n " );
139+ sb .append ("findAllWithType: " );
140+ sb .append (Arrays .toString (allWithTypePositions .toArray ()));
141+ sb .append ("\n " );
142+ sb .append ("findAllClosestFirstWithType: " );
143+ sb .append (Arrays .toString (allClosestFirstWithTypePositions .toArray ()));
144+ sb .append ("\n " );
145+ sb .append ("closestPortalPosition :" ).append (closestPortalPosition .map (Vec3i ::toString ).orElse ("empty" )).append ("\n " );
146+ sb .append ("find :" ).append (firstOfAll .map (Vec3i ::toString ).orElse ("empty" )).append ("\n " );
147+ sb .append ("findClosest :" ).append (findClosest .map (Vec3i ::toString ).orElse ("empty" )).append ("\n " );
148+ sb .append ("findClosestWithType :" ).append (findClosestWithType .map (Vec3i ::toString ).orElse ("empty" )).append ("\n " );
149+ sb .append ("findClosest2 :" ).append (findClosest2 .map (Vec3i ::toString ).orElse ("empty" )).append ("\n " );
150+
151+ if (!outputFile .exists ()) {
152+ outputFile .getParentFile ().mkdirs ();
153+ try (java .io .FileWriter writer = new java .io .FileWriter (newOutputFile )) {
154+ writer .write (sb .toString ());
155+ } catch (Exception e ) {
156+ throw new RuntimeException (e );
157+ }
158+ } else {
159+ String existingContent ;
160+ try (java .io .FileReader reader = new java .io .FileReader (outputFile );
161+ java .io .BufferedReader br = new java .io .BufferedReader (reader )) {
162+ StringBuilder existingSb = new StringBuilder ();
163+ String line ;
164+ while ((line = br .readLine ()) != null ) {
165+ existingSb .append (line ).append ("\n " );
166+ }
167+ existingContent = existingSb .toString ();
168+ } catch (Exception e ) {
169+ throw new RuntimeException (e );
170+ }
171+
172+ if (!existingContent .equals (sb .toString ())) {
173+ try (java .io .FileWriter writer = new java .io .FileWriter (newOutputFile )) {
174+ writer .write (sb .toString ());
175+ } catch (Exception e ) {
176+ throw new RuntimeException (e );
177+ }
178+ throw new AssertionError ("POI search results differ from expected output. See " + newOutputFile .getAbsolutePath ());
179+ }
180+ }
178181
179182 context .succeed ();
180183 }
@@ -184,7 +187,7 @@ public void invokeTestMethod(GameTestHelper context, Method method) throws Refle
184187 ServerLevel level = context .getLevel ();
185188 RandomSource random = RandomSource .create (level .getSeed ()); //TODO avoid hardcoding seed
186189
187- for (int i = 0 ; i < 100 ; i ++) {
190+ for (int i = 0 ; i < 10 ; i ++) {
188191
189192 int x = random .nextInt (60000000 ) - 30000000 ;
190193 int z = random .nextInt (60000000 ) - 30000000 ;
@@ -193,11 +196,11 @@ public void invokeTestMethod(GameTestHelper context, Method method) throws Refle
193196 int chosen = random .nextInt (20 );
194197 double randomPct = chosen == 19 ? 0.0 : 1.0 / Math .pow (2 , chosen );
195198
196- int radius = 128 ;
199+ int radius = 130 ;
197200
198201 long poiCount = 0 ;
199202
200- System .out .println ("Placing POIs for iteration " + (i + 1 ) + "/100 : around (" + x + ", " + y + ", " + z + ") with randomPct=" + randomPct + " and radius=" + radius );
203+ System .out .println ("Placing POIs for iteration " + (i + 1 ) + "/10 : around (" + x + ", " + y + ", " + z + ") with randomPct=" + randomPct + " and radius=" + radius );
201204 for (BlockPos blockPos : BlockPos .betweenClosed (x - radius , y - radius , z - radius , x + radius , y + radius , z + radius )) {
202205 if (random .nextFloat () < randomPct && level .isInWorldBounds (blockPos )) {
203206 poiCount ++;
0 commit comments