Skip to content

Commit fcf7f3a

Browse files
committed
Update POI search test
1 parent 33a5420 commit fcf7f3a

File tree

1 file changed

+66
-63
lines changed
  • fabric/src/gametest/java/net/caffeinemc/mods/lithium/fabric/gametest/mixin/ai/poi

1 file changed

+66
-63
lines changed

fabric/src/gametest/java/net/caffeinemc/mods/lithium/fabric/gametest/mixin/ai/poi/POI_Search.java

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.fabricmc.fabric.api.gametest.v1.GameTest;
88
import net.minecraft.core.BlockPos;
99
import net.minecraft.core.Holder;
10+
import net.minecraft.core.Vec3i;
1011
import net.minecraft.gametest.framework.GameTestHelper;
1112
import net.minecraft.server.level.ServerLevel;
1213
import net.minecraft.util.RandomSource;
@@ -19,7 +20,9 @@
1920
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
2021
import net.minecraft.world.level.border.WorldBorder;
2122

23+
import java.io.File;
2224
import java.lang.reflect.Method;
25+
import java.util.Arrays;
2326
import java.util.Comparator;
2427
import java.util.List;
2528
import 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

Comments
 (0)