2020import java .io .FileReader ;
2121import java .util .ArrayList ;
2222import java .util .HashMap ;
23+ import java .util .LinkedHashSet ;
2324import java .util .List ;
2425import java .util .Map ;
26+ import java .util .Set ;
2527
2628public final class LootSearchUtil
2729{
@@ -30,6 +32,10 @@ private LootSearchUtil()
3032
3133 public static File getSeedmapperLootDir ()
3234 {
35+ File located = tryLocateSeedmapperLootDir ();
36+ if (located != null )
37+ return located ;
38+
3339 try
3440 {
3541 if (WurstClient .MC != null && WurstClient .MC .gameDirectory != null )
@@ -54,6 +60,88 @@ public static File getSeedmapperLootDir()
5460 return new File (new File (user , ".minecraft" ), "seedmapper/loot" );
5561 }
5662
63+ private static File tryLocateSeedmapperLootDir ()
64+ {
65+ Set <File > searchRoots = new LinkedHashSet <>();
66+ try
67+ {
68+ if (WurstClient .MC != null && WurstClient .MC .gameDirectory != null )
69+ addRootAndParents (searchRoots , WurstClient .MC .gameDirectory , 4 );
70+ }catch (Throwable ignored )
71+ {}
72+
73+ String user = System .getProperty ("user.home" );
74+ if (user != null && !user .isBlank ())
75+ {
76+ File home = new File (user );
77+ addRootAndParents (searchRoots , home , 0 );
78+ addRootAndParents (searchRoots , new File (home , ".minecraft" ), 0 );
79+ }
80+
81+ String appdata = System .getenv ("APPDATA" );
82+ if (appdata != null && !appdata .isBlank ())
83+ addRootAndParents (searchRoots , new File (appdata , ".minecraft" ), 0 );
84+
85+ for (File root : searchRoots )
86+ {
87+ File resolved = resolveSeedmapperLoot (root );
88+ if (resolved != null )
89+ return resolved ;
90+ }
91+
92+ // No matches under known roots.
93+ return null ;
94+ }
95+
96+ private static void addRootAndParents (Set <File > set , File start ,
97+ int maxDepth )
98+ {
99+ File current = start ;
100+ for (int depth = 0 ; current != null && depth <= maxDepth ; depth ++)
101+ {
102+ set .add (current );
103+ current = current .getParentFile ();
104+ }
105+ }
106+
107+ private static File resolveSeedmapperLoot (File root )
108+ {
109+ if (root == null || !root .exists () || !root .isDirectory ())
110+ return null ;
111+
112+ if (root .getName ().equalsIgnoreCase ("loot" ))
113+ return root ;
114+
115+ if (root .getName ().equalsIgnoreCase ("seedmapper" ))
116+ {
117+ File loot = new File (root , "loot" );
118+ if (loot .exists () && loot .isDirectory ())
119+ return loot ;
120+ }
121+
122+ String [] folderNames = {"seedmapper" , "SeedMapper" , "Seedmapper" };
123+ for (String folder : folderNames )
124+ {
125+ File loot = new File (new File (root , folder ), "loot" );
126+ if (loot .exists () && loot .isDirectory ())
127+ return loot ;
128+ }
129+
130+ File [] matches = root .listFiles (file -> file .isDirectory ()
131+ && file .getName ().equalsIgnoreCase ("seedmapper" ));
132+ if (matches != null )
133+ {
134+ for (File match : matches )
135+ {
136+ File loot = new File (match , "loot" );
137+ if (loot .exists () && loot .isDirectory ())
138+ return loot ;
139+ }
140+ }
141+
142+ return null ;
143+ }
144+
57145 public static File findFileForServer (String serverIp )
58146 {
59147 if (serverIp == null )
0 commit comments