-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M1 Fix (Use LegacyFabric LWJGL + Gambac) (#2)
* Fix * Update LegacyRepositoryHandler.java * Update LWJGL2LibraryProcessor.java * Delete dead code * Readd babric maven, filter legacyfabric one to just lwjgl * Add gambac * Yeet unused imports
- Loading branch information
1 parent
37478b6
commit 850ad94
Showing
8 changed files
with
221 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package babric; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.provider.Property; | ||
|
||
public class BabricExtension { | ||
public final Property<Boolean> disableM1Fixes; | ||
|
||
public BabricExtension(Project project) { | ||
disableM1Fixes = project.getObjects().property(Boolean.class).convention(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package babric; | ||
|
||
public class Constants { | ||
public static final String MAVEN = "https://maven.glass-launcher.net/babric/"; | ||
public static final String LEGACYFABRIC_MAVEN = "https://repo.legacyfabric.net/repository/legacyfabric/"; | ||
public static final String BABRIC_MAVEN = "https://maven.glass-launcher.net/babric/"; | ||
public static final String MODRINTH_MAVEN = "https://api.modrinth.com/maven/"; | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/babric/processor/GambacLibraryProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
Swiped from https://github.com/Legacy-Fabric/legacy-looming/blob/dev/1.7/src/main/java/net/legacyfabric/legacylooming/providers/LWJGL2LibraryProcessor.java with permission. | ||
**/ | ||
|
||
package babric.processor; | ||
|
||
import babric.BabricExtension; | ||
import net.fabricmc.loom.api.LoomGradleExtensionAPI; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.Library; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryContext; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryProcessor; | ||
import net.fabricmc.loom.util.Platform; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.dsl.RepositoryHandler; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
|
||
public class GambacLibraryProcessor extends LibraryProcessor { | ||
public static final String VERSION = "1.1.0"; | ||
private boolean applied = false; | ||
private final LoomGradleExtensionAPI loom; | ||
private final Project project; | ||
private final BabricExtension babricExtension; | ||
|
||
public GambacLibraryProcessor(Platform platform, LibraryContext context, LoomGradleExtensionAPI loom, Project project, BabricExtension babricExtension) { | ||
super(platform, context); | ||
this.loom = loom; | ||
this.project = project; | ||
this.babricExtension = babricExtension; | ||
} | ||
|
||
@Override | ||
public ApplicationResult getApplicationResult() { | ||
if (babricExtension.disableM1Fixes.get()) { | ||
return ApplicationResult.DONT_APPLY; | ||
} | ||
if (!loom.getMinecraftVersion().get().equals("b1.7.3")) { | ||
|
||
project.getLogger().warn("M1 fix being ignored. Unsupported minecraft version."); | ||
return ApplicationResult.DONT_APPLY; | ||
} | ||
|
||
return ApplicationResult.MUST_APPLY; | ||
} | ||
|
||
@Override | ||
public Predicate<Library> apply(Consumer<Library> dependencyConsumer) { | ||
if (!applied) { | ||
applied = true; | ||
|
||
dependencyConsumer.accept(Library.fromMaven("maven.modrinth:gambac:" + VERSION, Library.Target.LOCAL_MOD)); | ||
} | ||
|
||
return ALLOW_ALL; | ||
} | ||
|
||
@Override | ||
public void applyRepositories(RepositoryHandler repositories) { | ||
repositories.exclusiveContent(repository -> { | ||
repository.forRepositories(repositories.findByName("Modrinth")); | ||
repository.filter(filter -> { | ||
filter.includeModule("maven.modrinth", "gambac"); // Allow only gambac, don't let folk rely on this adding MR for them. | ||
}); | ||
}); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/babric/processor/LWJGL2LibraryProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
Swiped from https://github.com/Legacy-Fabric/legacy-looming/blob/dev/1.7/src/main/java/net/legacyfabric/legacylooming/providers/LWJGL2LibraryProcessor.java with permission. | ||
**/ | ||
|
||
package babric.processor; | ||
|
||
import net.fabricmc.loom.configuration.providers.minecraft.library.Library; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryContext; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryProcessor; | ||
import net.fabricmc.loom.util.Platform; | ||
import org.gradle.api.artifacts.dsl.RepositoryHandler; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
|
||
public class LWJGL2LibraryProcessor extends LibraryProcessor { | ||
public static final String VERSION = "2.9.4+legacyfabric.8"; | ||
private boolean applied = false; | ||
public LWJGL2LibraryProcessor(Platform platform, LibraryContext context) { | ||
super(platform, context); | ||
} | ||
|
||
@Override | ||
public ApplicationResult getApplicationResult() { | ||
if (!context.usesLWJGL3()) { | ||
|
||
return ApplicationResult.MUST_APPLY; | ||
} | ||
|
||
return ApplicationResult.DONT_APPLY; | ||
} | ||
|
||
@Override | ||
public Predicate<Library> apply(Consumer<Library> dependencyConsumer) { | ||
return library -> { | ||
if (!applied) { | ||
applied = true; | ||
final Library[] libs = new Library[]{ | ||
Library.fromMaven("org.lwjgl.lwjgl:lwjgl-platform:" + VERSION + ":" + getNativeClassifier(), Library.Target.NATIVES), | ||
Library.fromMaven("org.lwjgl.lwjgl:lwjgl_util:" + VERSION, Library.Target.COMPILE), | ||
Library.fromMaven("org.lwjgl.lwjgl:lwjgl:" + VERSION, Library.Target.COMPILE) | ||
}; | ||
|
||
for (Library lib : libs) { | ||
dependencyConsumer.accept(lib); | ||
} | ||
} | ||
|
||
return !library.group().equals("org.lwjgl.lwjgl"); | ||
}; | ||
} | ||
|
||
@Override | ||
public void applyRepositories(RepositoryHandler repositories) { | ||
repositories.exclusiveContent(repository -> { | ||
repository.forRepositories(repositories.findByName("Legacy Fabric")); | ||
repository.filter(filter -> { | ||
filter.includeGroup("org.lwjgl.lwjgl"); | ||
}); | ||
}); | ||
} | ||
|
||
public static String getNativeClassifier() { | ||
switch (Platform.CURRENT.getOperatingSystem()) { | ||
case MAC_OS -> { | ||
return "natives-osx"; | ||
} | ||
case LINUX -> { | ||
return "natives-linux"; | ||
} | ||
default -> { | ||
return "natives-windows"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters