2828import net .ornithemc .meta .utils .MinecraftLauncherMeta ;
2929import net .ornithemc .meta .utils .MavenPomParser ;
3030import net .ornithemc .meta .utils .MavenMetadataParser ;
31+ import net .ornithemc .meta .utils .MavenMetadataParser .StableVersionIdentifier ;
3132import net .ornithemc .meta .utils .VersionManifest ;
3233import net .ornithemc .meta .web .LibraryUpgradesV3 ;
3334import net .ornithemc .meta .web .LibraryUpgradesV3 .LibraryUpgrade ;
3940import java .util .*;
4041import java .util .function .Function ;
4142import java .util .function .Predicate ;
43+ import java .util .regex .Pattern ;
4244import java .util .stream .Collectors ;
4345
4446@ JsonIgnoreProperties ({"manifest" })
@@ -60,6 +62,9 @@ public class VersionDatabase {
6062 public static final MavenMetadataParser OSL_METADATA_PARSER = new MavenMetadataParser (ORNITHE_MAVEN_URL , "net.ornithemc" , "osl" );
6163 public static final MavenPomParser OSL_POM_PARSER = new MavenPomParser (ORNITHE_MAVEN_URL , "net.ornithemc" , "osl" );
6264
65+ private static final Pattern INVALID_FABRIC_LOADER_VERSIONS_GEN2 = Pattern .compile ("^(?:0\\ .(?:\\ d|1[0-6])\\ ..+|0\\ .17\\ .[0-2])" );
66+ private static final Pattern INVALID_QUILT_LOADER_VERSIONS_GEN2 = Pattern .compile ("^(?:0\\ .(?:\\ d|1\\ d|2[0-8])\\ ..+|0\\ .29\\ .[0-2])" );
67+
6368 public static ConfigV3 config ;
6469
6570 private static final String modifyForIntermediaryGeneration (String s , int generation ) {
@@ -82,6 +87,34 @@ public static final MavenMetadataParser oslModuleMetadataParser(String module) {
8287 return new MavenMetadataParser (ORNITHE_MAVEN_URL , "net.ornithemc.osl" , module );
8388 }
8489
90+ public static Pattern invalidLoaderVersionsPattern (LoaderType loaderType ) {
91+ switch (loaderType ) {
92+ case FABRIC :
93+ return INVALID_FABRIC_LOADER_VERSIONS_GEN2 ;
94+ case QUILT :
95+ return INVALID_QUILT_LOADER_VERSIONS_GEN2 ;
96+ default :
97+ throw new IllegalStateException ("no invalid loader versions pattern for loader type " + loaderType .getName ());
98+ }
99+ }
100+
101+ public static StableVersionIdentifier filterLoaderVersions (int generation , LoaderType loaderType ) {
102+ return versions -> {
103+ boolean foundStableVersion = false ;
104+
105+ for (Iterator <? extends BaseVersion > it = versions .iterator (); it .hasNext (); ) {
106+ BaseVersion version = it .next ();
107+
108+ if (generation >= 2 && invalidLoaderVersionsPattern (loaderType ).matcher (version .getVersion ()).matches ()) {
109+ it .remove ();
110+ } else if (!foundStableVersion && isPublicLoaderVersion (loaderType , version )) {
111+ foundStableVersion = true ;
112+ version .setStable (true );
113+ }
114+ }
115+ };
116+ }
117+
85118 private static List <String > oslModules () {
86119 List <String > modules = new ArrayList <>();
87120
@@ -123,7 +156,7 @@ private static List<String> oslModules() {
123156 private final Int2ObjectMap <List <BaseVersion >> game ;
124157 private final Int2ObjectMap <List <MavenVersion >> intermediary ;
125158 private final Int2ObjectMap <List <MavenBuildGameVersion >> feather ;
126- private final Map <LoaderType , List <MavenBuildVersion >> loader ;
159+ private final Int2ObjectMap < Map <LoaderType , List <MavenBuildVersion > >> loader ;
127160 private final Map <String , List <MavenVersion >> oslDependencies ;
128161 private final Map <String , List <MavenVersion >> oslModules ;
129162
@@ -139,7 +172,7 @@ private VersionDatabase() {
139172 this .game = new Int2ObjectOpenHashMap <>();
140173 this .intermediary = new Int2ObjectOpenHashMap <>();
141174 this .feather = new Int2ObjectOpenHashMap <>();
142- this .loader = new EnumMap <>(LoaderType . class );
175+ this .loader = new Int2ObjectOpenHashMap <>();
143176 this .oslDependencies = new HashMap <>();
144177 this .oslModules = new HashMap <>();
145178 }
@@ -151,27 +184,13 @@ public static VersionDatabase generate() throws Exception {
151184 for (int generation = 1 ; generation <= config .latestIntermediaryGeneration ; generation ++) {
152185 database .intermediary .put (generation , intermediaryMetadataParser (generation ).getVersions (MavenVersion ::new ));
153186 database .feather .put (generation , featherMetadataParser (generation ).getVersions (MavenBuildGameVersion ::new ));
187+ database .loader .put (generation , new EnumMap <>(LoaderType .class ));
188+ database .loader .get (generation ).put (LoaderType .FABRIC , FABRIC_LOADER_METADATA_PARSER .getVersions (MavenBuildVersion ::new , filterLoaderVersions (generation , LoaderType .FABRIC )));
189+ database .loader .get (generation ).put (LoaderType .QUILT , QUILT_LOADER_METADATA_PARSER .getVersions (MavenBuildVersion ::new , filterLoaderVersions (generation , LoaderType .QUILT )));
154190 }
155191 database .raven = RAVEN_METADATA_PARSER .getVersions (MavenBuildGameVersion ::new );
156192 database .sparrow = SPARROW_METADATA_PARSER .getVersions (MavenBuildGameVersion ::new );
157193 database .nests = NESTS_METADATA_PARSER .getVersions (MavenBuildGameVersion ::new );
158- database .loader .put (LoaderType .FABRIC , FABRIC_LOADER_METADATA_PARSER .getVersions (MavenBuildVersion ::new , list -> {
159- for (BaseVersion version : list ) {
160- if (isPublicLoaderVersion (version )) {
161- version .setStable (true );
162- break ;
163- }
164- }
165- }));
166- database .loader .put (LoaderType .QUILT , QUILT_LOADER_METADATA_PARSER .getVersions (MavenBuildVersion ::new , list -> {
167- for (BaseVersion version : list ) {
168- // Quilt publishes beta versions of their loader, filter those out
169- if (isPublicLoaderVersion (version ) && !version .getVersion ().contains ("-" )) {
170- version .setStable (true );
171- break ;
172- }
173- }
174- }));
175194 database .installer = INSTALLER_METADATA_PARSER .getVersions (MavenUrlVersion ::new );
176195 database .osl = OSL_METADATA_PARSER .getVersions (MavenVersion ::new );
177196 for (MavenVersion version : database .osl ) {
@@ -188,8 +207,9 @@ public static VersionDatabase generate() throws Exception {
188207 return database ;
189208 }
190209
191- private static boolean isPublicLoaderVersion (BaseVersion version ) {
192- return true ;
210+ private static boolean isPublicLoaderVersion (LoaderType type , BaseVersion version ) {
211+ // Quilt publishes beta versions of their loader, filter those out
212+ return !(type == LoaderType .QUILT && version .getVersion ().contains ("-" ));
193213 }
194214
195215 private void loadMcData () throws IOException {
@@ -297,8 +317,8 @@ public List<MavenBuildGameVersion> getFeather(int generation) {
297317 return feather .get (generation );
298318 }
299319
300- public List <MavenBuildVersion > getLoader (LoaderType type ) {
301- return loader .get (type ).stream ().filter (VersionDatabase :: isPublicLoaderVersion ).collect (Collectors .toList ());
320+ public List <MavenBuildVersion > getLoader (int generation , LoaderType type ) {
321+ return loader .get (generation ). get ( type ).stream ().filter (v -> isPublicLoaderVersion ( type , v ) ).collect (Collectors .toList ());
302322 }
303323
304324 public List <MavenVersion > getOslDependencies (String version ) {
@@ -309,7 +329,7 @@ public List<MavenVersion> getOslModule(String module) {
309329 return oslModules .get (module );
310330 }
311331
312- public List <MavenBuildVersion > getAllLoader (LoaderType type ) {
313- return Collections .unmodifiableList (loader .get (type ));
332+ public List <MavenBuildVersion > getAllLoader (int generation , LoaderType type ) {
333+ return Collections .unmodifiableList (loader .get (generation ). get ( type ));
314334 }
315335}
0 commit comments