44import java .util .Collections ;
55import java .util .List ;
66import java .util .Optional ;
7+ import java .util .function .IntConsumer ;
78import java .util .function .IntFunction ;
89
910import net .minecraft .item .ItemStack ;
@@ -231,6 +232,20 @@ public static List<Detection> detect(UniverseRegistry registry, GalacticCoord lo
231232 public static int characterise (UniverseRegistry registry , Detection hit , CrystalMemory memory ,
232233 long observedTick , IntFunction <String > nameOf ,
233234 boolean wholeSystem ) {
235+ return characterise (registry , hit , memory , observedTick , nameOf , wholeSystem , null );
236+ }
237+
238+ /**
239+ * The same, telling {@code named} the dimension of every body this look actually made out.
240+ *
241+ * <p>The callback is a fact about the OBSERVATION - "this look named that world" - and nothing
242+ * more; what a caller does with it belongs to the caller. It fires only for a body that has a
243+ * dimension: an unrealized body has no world to fly to, and an address that names no body
244+ * (unresolvable, obscured, or positions-only) reports nothing at all.</p>
245+ */
246+ public static int characterise (UniverseRegistry registry , Detection hit , CrystalMemory memory ,
247+ long observedTick , IntFunction <String > nameOf ,
248+ boolean wholeSystem , IntConsumer named ) {
234249 if (registry == null || hit == null || memory == null ) {
235250 return 0 ;
236251 }
@@ -244,6 +259,9 @@ public static int characterise(UniverseRegistry registry, Detection hit, Crystal
244259 if (memory .record (entryFor (body , observedTick , nameOf ))) {
245260 written ++;
246261 }
262+ if (named != null && body .dimId () != Constants .INVALID_PLANET ) {
263+ named .accept (body .dimId ());
264+ }
247265 }
248266 }
249267 if (!namedSomething ) {
@@ -269,12 +287,20 @@ public static int resolveBatch(UniverseRegistry registry, RegionScan scan, int f
269287 public static int resolveBatch (UniverseRegistry registry , RegionScan scan , int from , int count ,
270288 ItemStack crystal , long observedTick , IntFunction <String > nameOf ,
271289 GalacticCoord observer , boolean wholeSystem ) {
290+ return resolveBatch (registry , scan , from , count , crystal , observedTick , nameOf , observer ,
291+ wholeSystem , null );
292+ }
293+
294+ /** The same, reporting every body the batch named to {@code named}. */
295+ public static int resolveBatch (UniverseRegistry registry , RegionScan scan , int from , int count ,
296+ ItemStack crystal , long observedTick , IntFunction <String > nameOf ,
297+ GalacticCoord observer , boolean wholeSystem , IntConsumer named ) {
272298 if (!ItemMemoryCrystal .isCrystal (crystal )) {
273299 return 0 ;
274300 }
275301 CrystalMemory memory = ItemMemoryCrystal .memoryOf (crystal );
276302 int written = resolveBatch (registry , scan , from , count , memory , observedTick , nameOf ,
277- observer , wholeSystem );
303+ observer , wholeSystem , named );
278304 if (written > 0 ) {
279305 ItemMemoryCrystal .writeMemory (crystal , memory );
280306 }
@@ -294,14 +320,22 @@ public static int resolveBatch(UniverseRegistry registry, RegionScan scan, int f
294320 public static int resolveBatch (UniverseRegistry registry , RegionScan scan , int from , int count ,
295321 CrystalMemory memory , long observedTick , IntFunction <String > nameOf ,
296322 GalacticCoord observer , boolean wholeSystem ) {
323+ return resolveBatch (registry , scan , from , count , memory , observedTick , nameOf , observer ,
324+ wholeSystem , null );
325+ }
326+
327+ /** The same, reporting every body the batch named to {@code named}. */
328+ public static int resolveBatch (UniverseRegistry registry , RegionScan scan , int from , int count ,
329+ CrystalMemory memory , long observedTick , IntFunction <String > nameOf ,
330+ GalacticCoord observer , boolean wholeSystem , IntConsumer named ) {
297331 if (registry == null || scan == null || memory == null ) {
298332 return 0 ;
299333 }
300334 double limit = limitMagnitude ();
301335 int written = 0 ;
302336 for (int index = from ; index < from + count && index < scan .totalCells (); index ++) {
303337 written += resolveLook (registry , scan .cellAt (index ), memory , observedTick , nameOf ,
304- observer , limit , wholeSystem );
338+ observer , limit , wholeSystem , named );
305339 }
306340 return written ;
307341 }
@@ -320,9 +354,18 @@ public static int resolveLook(UniverseRegistry registry, GalacticCoord look, Cry
320354 long observedTick , IntFunction <String > nameOf ,
321355 GalacticCoord observer , double limitMagnitude ,
322356 boolean wholeSystem ) {
357+ return resolveLook (registry , look , memory , observedTick , nameOf , observer , limitMagnitude ,
358+ wholeSystem , null );
359+ }
360+
361+ /** The same, reporting every body this look named to {@code named}. */
362+ public static int resolveLook (UniverseRegistry registry , GalacticCoord look , CrystalMemory memory ,
363+ long observedTick , IntFunction <String > nameOf ,
364+ GalacticCoord observer , double limitMagnitude ,
365+ boolean wholeSystem , IntConsumer named ) {
323366 int written = 0 ;
324367 for (Detection hit : detect (registry , look , observer , limitMagnitude )) {
325- written += characterise (registry , hit , memory , observedTick , nameOf , wholeSystem );
368+ written += characterise (registry , hit , memory , observedTick , nameOf , wholeSystem , named );
326369 }
327370 return written ;
328371 }
0 commit comments