11package folk .sisby .surveyor ;
22
3- import com .google .common .collect .Multimap ;
43import folk .sisby .surveyor .config .NetworkMode ;
54import folk .sisby .surveyor .config .SurveyorConfig ;
65import folk .sisby .surveyor .landmark .component .LandmarkComponentTypes ;
6+ import folk .sisby .surveyor .structure .StructureStartSummary ;
77import folk .sisby .surveyor .structure .WorldStructures ;
88import folk .sisby .surveyor .terrain .WorldTerrain ;
9- import folk .sisby .surveyor .util .MapUtil ;
109import folk .sisby .surveyor .util .RaycastUtil ;
1110import it .unimi .dsi .fastutil .longs .LongSet ;
1211import net .fabricmc .api .ModInitializer ;
2221import net .minecraft .server .network .ServerPlayerEntity ;
2322import net .minecraft .server .world .ServerWorld ;
2423import net .minecraft .structure .StructurePiece ;
25- import net .minecraft .structure .StructureStart ;
2624import net .minecraft .text .Text ;
2725import net .minecraft .util .Formatting ;
2826import net .minecraft .util .Identifier ;
4139import java .io .File ;
4240import java .util .Map ;
4341import java .util .UUID ;
44- import java .util .stream .Collectors ;
4542
4643public class Surveyor implements ModInitializer {
4744 public static final String ID = "surveyor" ;
@@ -65,29 +62,26 @@ public static void checkStructureExploration(ServerWorld world, ServerPlayerEnti
6562 SurveyorExploration exploration = SurveyorExploration .of (player );
6663 Map <Structure , LongSet > structureReferences = world .getChunk (pos .getX () >> 4 , pos .getZ () >> 4 , ChunkStatus .STRUCTURE_REFERENCES ).getStructureReferences ();
6764 if (!structureReferences .isEmpty ()) {
68- Multimap < RegistryKey < Structure >, ChunkPos > unexploredStructures = MapUtil . asMultiMap ( structureReferences .entrySet (). stream (). collect ( Collectors . toMap (
69- e -> structureRegistry .getKey (e . getKey ()) .orElseThrow (),
70- e -> e . getValue (). longStream (). mapToObj ( ChunkPos :: new ). toList ()
71- )) );
72- unexploredStructures . entries (). removeIf ( e -> exploration .exploredStructure (world .getRegistryKey (), e . getKey (), e . getValue ())) ;
73- unexploredStructures . entries (). removeIf ( e -> ! structures .contains ( e . getKey (), e . getValue ()) );
74- unexploredStructures . forEach (( structureKey , startPos ) -> {
75- Structure structure = structureRegistry . get ( structureKey );
76- StructureStart start = world . getChunk ( startPos . x , startPos . z , ChunkStatus . STRUCTURE_STARTS ). getStructureStart ( structure );
77- boolean found = false ;
78- if ( start != null && start . hasChildren () && start . getBoundingBox (). contains ( pos )) {
79- for ( StructurePiece piece : start . getChildren () ) {
80- if ( piece . getBoundingBox (). expand ( 2 ). contains ( pos )) {
81- exploration . addStructure ( world . getRegistryKey (), structureKey , start . getPos ());
82- found = true ;
83- break ;
65+ for ( Structure structure : structureReferences .keySet ()) {
66+ RegistryKey < Structure > structureKey = structureRegistry .getKey (structure ) .orElseThrow ();
67+ for ( Long longPos : structureReferences . get ( structure )) {
68+ ChunkPos startPos = new ChunkPos ( longPos );
69+ if ( exploration .exploredStructure (world .getRegistryKey (), structureKey , startPos )) continue ;
70+ StructureStartSummary start = structures .get ( structureKey , startPos );
71+ if ( start == null ) continue ;
72+ if ( start . getBoundingBox (). expand ( 2 ). contains ( pos )) {
73+ for ( StructurePiece piece : start . getChildren ()) {
74+ if ( piece . getBoundingBox (). expand ( 2 ). contains ( pos )) {
75+ exploration . addStructure ( world . getRegistryKey (), structureKey , startPos );
76+ if ( CONFIG . discoveryMessages ) {
77+ player . sendMessageToClient ( Text . literal ( "Discovered " ). append ( Text . literal ( WordUtils . capitalize ( structureKey . getValue (). getPath (). replace ( "_" , " " ))). formatted ( Formatting . GREEN )). append ( Text . literal ( " at " )). append ( Text . literal ( "[%s,%s]" . formatted ( startPos . x << 4 , startPos . z << 4 )). formatted ( Formatting . GOLD )). formatted ( Formatting . GRAY ), true );
78+ }
79+ break ;
80+ }
8481 }
8582 }
8683 }
87- if (found && CONFIG .discoveryMessages ) {
88- player .sendMessageToClient (Text .literal ("Discovered " ).append (Text .literal (WordUtils .capitalize (structureKey .getValue ().getPath ().replace ("_" , " " ))).formatted (Formatting .GREEN )).append (Text .literal (" at " )).append (Text .literal ("[%s,%s]" .formatted (startPos .x << 4 , startPos .z << 4 )).formatted (Formatting .GOLD )).formatted (Formatting .GRAY ), true );
89- }
90- });
84+ }
9185 }
9286 }
9387
0 commit comments