add support for new dependencyResolutionManagement (#400)
* move repo declartions - Move repository declartions in MavenConfiguration.java to LoomRepositoryPlugin.java * move repo declartions - Move repository declartions in MinecraftMappedProvider.java to LoomRepositoryPlugin.java * move repo declartions - Move repository declarations in MinecraftProcessedProvider.java to LoomRepositoryPlugin.java * do not add repositories if dependencyResolutionManagement is used * Simplify the change on LoomGradlePlugin - this is the suggestion from liach * change name to follow fabric naming convension - change getProjectUUID to getProjectUuid - change PROJECT_MAPPED_CLASSIFIER to projectMappedClassifier * remove MavenConfiguration.java - the file currently do nothing. * clean-up for all `instanceof` clause * add DependencyResolutionManagementTest * code cleanup * Update src/test/resources/projects/dependencyResolutionManagement/projmap/src/main/resources/modid.accesswidener * change project uuid to project full name Co-authored-by: modmuss50 <modmuss50@gmail.com>dev/0.11
parent
de665ab498
commit
e955ebb8c5
|
@ -31,6 +31,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.PluginAware;
|
||||
|
||||
import net.fabricmc.loom.configuration.CompileConfiguration;
|
||||
import net.fabricmc.loom.configuration.FabricApiExtension;
|
||||
|
@ -40,12 +41,20 @@ import net.fabricmc.loom.configuration.providers.mappings.MappingsCache;
|
|||
import net.fabricmc.loom.decompilers.DecompilerConfiguration;
|
||||
import net.fabricmc.loom.task.LoomTasks;
|
||||
|
||||
public class LoomGradlePlugin implements Plugin<Project> {
|
||||
public class LoomGradlePlugin implements Plugin<PluginAware> {
|
||||
public static boolean refreshDeps;
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
@Override
|
||||
public void apply(PluginAware target) {
|
||||
target.getPlugins().apply(LoomRepositoryPlugin.class);
|
||||
|
||||
if (target instanceof Project project) {
|
||||
apply(project);
|
||||
}
|
||||
}
|
||||
|
||||
public void apply(Project project) {
|
||||
project.getLogger().lifecycle("Fabric Loom: " + LoomGradlePlugin.class.getPackage().getImplementationVersion());
|
||||
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.dsl.RepositoryHandler;
|
||||
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
|
||||
import org.gradle.api.initialization.Settings;
|
||||
import org.gradle.api.invocation.Gradle;
|
||||
import org.gradle.api.plugins.PluginAware;
|
||||
|
||||
public class LoomRepositoryPlugin implements Plugin<PluginAware> {
|
||||
@Override
|
||||
public void apply(PluginAware target) {
|
||||
RepositoryHandler repositories = null;
|
||||
|
||||
if (target instanceof Settings settings) {
|
||||
repositories = settings.getDependencyResolutionManagement().getRepositories();
|
||||
|
||||
// leave a marker so projects don't try to override these
|
||||
settings.getGradle().getPluginManager().apply(LoomRepositoryPlugin.class);
|
||||
} else if (target instanceof Project project) {
|
||||
if (project.getGradle().getPlugins().hasPlugin(LoomRepositoryPlugin.class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
repositories = project.getRepositories();
|
||||
} else if (target instanceof Gradle) {
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
|
||||
}
|
||||
|
||||
Cache cache = new Cache(target);
|
||||
|
||||
// MavenConfiguration.java
|
||||
repositories.flatDir(repo -> {
|
||||
repo.setName("UserLocalCacheFiles");
|
||||
repo.dir(cache.getRootBuildCache());
|
||||
});
|
||||
repositories.maven(repo -> {
|
||||
repo.setName("UserLocalRemappedMods");
|
||||
repo.setUrl(cache.getRemappedModCache());
|
||||
});
|
||||
repositories.maven(repo -> {
|
||||
repo.setName("Fabric");
|
||||
repo.setUrl("https://maven.fabricmc.net/");
|
||||
});
|
||||
repositories.maven(repo -> {
|
||||
repo.setName("Mojang");
|
||||
repo.setUrl("https://libraries.minecraft.net/");
|
||||
});
|
||||
repositories.mavenCentral();
|
||||
|
||||
// MinecraftMappedProvider.java
|
||||
repositories.ivy(repo -> {
|
||||
repo.setUrl(cache.getUserCache());
|
||||
repo.patternLayout(layout -> {
|
||||
layout.artifact("[revision]/[artifact]-[revision](.[ext])");
|
||||
});
|
||||
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
|
||||
});
|
||||
|
||||
// MinecraftProcessedProvider.java
|
||||
repositories.ivy(repo -> {
|
||||
repo.setUrl(cache.getRootPersistentCache());
|
||||
repo.patternLayout(layout -> {
|
||||
layout.artifact("[revision]/[artifact]-[revision](.[ext])");
|
||||
});
|
||||
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
final class Cache {
|
||||
private PluginAware target;
|
||||
|
||||
Cache(PluginAware target) {
|
||||
if (target instanceof Project || target instanceof Settings) {
|
||||
this.target = target;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
File getUserCache() {
|
||||
File gradleUserHomeDir = null;
|
||||
|
||||
if (target instanceof Settings settings) {
|
||||
gradleUserHomeDir = settings.getGradle().getGradleUserHomeDir();
|
||||
} else if (target instanceof Project project) {
|
||||
gradleUserHomeDir = project.getGradle().getGradleUserHomeDir();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
|
||||
}
|
||||
|
||||
File userCache = new File(gradleUserHomeDir, "caches" + File.separator + "fabric-loom");
|
||||
|
||||
if (!userCache.exists()) {
|
||||
userCache.mkdirs();
|
||||
}
|
||||
|
||||
return userCache;
|
||||
}
|
||||
|
||||
public File getRootPersistentCache() {
|
||||
File rootDir = null;
|
||||
|
||||
if (target instanceof Settings settings) {
|
||||
rootDir = settings.getRootDir();
|
||||
} else if (target instanceof Project project) {
|
||||
rootDir = project.getRootDir();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
|
||||
}
|
||||
|
||||
File persistentCache = new File(rootDir, ".gradle" + File.separator + "loom-cache");
|
||||
|
||||
if (!persistentCache.exists()) {
|
||||
persistentCache.mkdirs();
|
||||
}
|
||||
|
||||
return persistentCache;
|
||||
}
|
||||
|
||||
public File getRootBuildCache() {
|
||||
File rootDir = null;
|
||||
|
||||
if (target instanceof Settings settings) {
|
||||
rootDir = settings.getRootDir();
|
||||
} else if (target instanceof Project project) {
|
||||
rootDir = project.getRootDir();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
|
||||
}
|
||||
|
||||
File buildCache = new File(rootDir, "build" + File.separator + "loom-cache");
|
||||
|
||||
if (!buildCache.exists()) {
|
||||
buildCache.mkdirs();
|
||||
}
|
||||
|
||||
return buildCache;
|
||||
}
|
||||
|
||||
public File getRemappedModCache() {
|
||||
File remappedModCache = new File(getRootPersistentCache(), "remapped_mods");
|
||||
|
||||
if (!remappedModCache.exists()) {
|
||||
remappedModCache.mkdir();
|
||||
}
|
||||
|
||||
return remappedModCache;
|
||||
}
|
||||
|
||||
public File getNestedModCache() {
|
||||
File nestedModCache = new File(getRootPersistentCache(), "nested_mods");
|
||||
|
||||
if (!nestedModCache.exists()) {
|
||||
nestedModCache.mkdir();
|
||||
}
|
||||
|
||||
return nestedModCache;
|
||||
}
|
||||
|
||||
public File getNativesJarStore() {
|
||||
File natives = new File(getUserCache(), "natives/jars");
|
||||
|
||||
if (!natives.exists()) {
|
||||
natives.mkdirs();
|
||||
}
|
||||
|
||||
return natives;
|
||||
}
|
||||
}
|
|
@ -107,8 +107,6 @@ public final class CompileConfiguration {
|
|||
p.afterEvaluate(project -> {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
|
||||
MavenConfiguration.setup(project);
|
||||
|
||||
LoomDependencyManager dependencyManager = new LoomDependencyManager();
|
||||
extension.setDependencyManager(dependencyManager);
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ import net.fabricmc.loom.configuration.mods.ModProcessor;
|
|||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
import net.fabricmc.loom.LoomRepositoryPlugin;
|
||||
|
||||
public class LoomDependencyManager {
|
||||
private static class ProviderList {
|
||||
|
@ -193,7 +194,9 @@ public class LoomDependencyManager {
|
|||
|
||||
project.getLogger().debug("Loom adding " + name + " from installer JSON");
|
||||
|
||||
if (jsonElement.getAsJsonObject().has("url")) {
|
||||
// If user choose to use dependencyResolutionManagement, then they should declare
|
||||
// these repositories manually in the settings file.
|
||||
if (jsonElement.getAsJsonObject().has("url") && !project.getGradle().getPlugins().hasPlugin(LoomRepositoryPlugin.class)) {
|
||||
String url = jsonElement.getAsJsonObject().get("url").getAsString();
|
||||
long count = project.getRepositories().stream().filter(artifactRepository -> artifactRepository instanceof MavenArtifactRepository)
|
||||
.map(artifactRepository -> (MavenArtifactRepository) artifactRepository)
|
||||
|
|
|
@ -37,7 +37,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvid
|
|||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public class MinecraftProcessedProvider extends MinecraftMappedProvider {
|
||||
public static final String PROJECT_MAPPED_CLASSIFIER = "projectmapped";
|
||||
public final String projectMappedClassifier;
|
||||
|
||||
private File projectMappedJar;
|
||||
|
||||
|
@ -46,6 +46,8 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
|
|||
public MinecraftProcessedProvider(Project project, JarProcessorManager jarProcessorManager) {
|
||||
super(project);
|
||||
this.jarProcessorManager = jarProcessorManager;
|
||||
this.projectMappedClassifier = "project-" + project.getPath().replace(':', '@')
|
||||
+ "-mapped";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,14 +65,12 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
|
|||
jarProcessorManager.process(projectMappedJar);
|
||||
}
|
||||
|
||||
getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER)));
|
||||
|
||||
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
|
||||
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER)));
|
||||
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(projectMappedClassifier)));
|
||||
}
|
||||
|
||||
private void invalidateJars() {
|
||||
File dir = getJarDirectory(getExtension().getUserCache(), PROJECT_MAPPED_CLASSIFIER);
|
||||
File dir = getJarDirectory(getExtension().getUserCache(), projectMappedClassifier);
|
||||
|
||||
if (dir.exists()) {
|
||||
getProject().getLogger().warn("Invalidating project jars");
|
||||
|
@ -87,7 +87,7 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
|
|||
public void initFiles(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) {
|
||||
super.initFiles(minecraftProvider, mappingsProvider);
|
||||
|
||||
projectMappedJar = new File(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER), "minecraft-" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER) + ".jar");
|
||||
projectMappedJar = new File(getJarDirectory(getExtension().getRootProjectPersistentCache(), projectMappedClassifier), "minecraft-" + getJarVersionString(projectMappedClassifier) + ".jar");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -144,8 +144,6 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
|||
}
|
||||
|
||||
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
|
||||
getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getUserCache(), "mapped")));
|
||||
|
||||
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
|
||||
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString("mapped")));
|
||||
}
|
||||
|
|
|
@ -22,36 +22,31 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.configuration;
|
||||
package net.fabricmc.loom.test.integration
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import net.fabricmc.loom.test.util.ProjectTestTrait
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
|
||||
|
||||
public class MavenConfiguration {
|
||||
public static void setup(Project project) {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
class DependencyResolutionManagementTest extends Specification implements ProjectTestTrait {
|
||||
@Override
|
||||
String name() {
|
||||
"dependencyResolutionManagement"
|
||||
}
|
||||
|
||||
project.getRepositories().flatDir(repo -> {
|
||||
repo.setName("UserLocalCacheFiles");
|
||||
repo.dir(extension.getRootProjectBuildCache());
|
||||
});
|
||||
@Unroll
|
||||
def "build (gradle #gradle)"() {
|
||||
when:
|
||||
def result = create("build", gradle)
|
||||
then:
|
||||
result.task(":basic:build").outcome == SUCCESS
|
||||
result.task(":projmap:build").outcome == SUCCESS
|
||||
|
||||
project.getRepositories().maven(repo -> {
|
||||
repo.setName("UserLocalRemappedMods");
|
||||
repo.setUrl(extension.getRemappedModCache());
|
||||
});
|
||||
|
||||
project.getRepositories().maven(repo -> {
|
||||
repo.setName("Fabric");
|
||||
repo.setUrl("https://maven.fabricmc.net/");
|
||||
});
|
||||
|
||||
project.getRepositories().maven(repo -> {
|
||||
repo.setName("Mojang");
|
||||
repo.setUrl("https://libraries.minecraft.net/");
|
||||
});
|
||||
|
||||
project.getRepositories().mavenCentral();
|
||||
}
|
||||
where:
|
||||
gradle | _
|
||||
DEFAULT_GRADLE | _
|
||||
PRE_RELEASE_GRADLE | _
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
plugins {
|
||||
id 'fabric-loom'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
// Add repositories to retrieve artifacts from in here.
|
||||
// You should only use this when depending on other mods because
|
||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||
// for more information about repositories.
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// To change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||
// You may need to force-disable transitiveness on them.
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
// If Javadoc is generated, this must be specified in that task too.
|
||||
it.options.encoding = "UTF-8"
|
||||
|
||||
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
|
||||
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
|
||||
// We'll use that if it's available, but otherwise we'll use the older option.
|
||||
def targetVersion = 8
|
||||
if (JavaVersion.current().isJava9Compatible()) {
|
||||
it.options.release = targetVersion
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this line, sources will not be generated.
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}"}
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||
repositories {
|
||||
// Add repositories to publish to here.
|
||||
// Notice: This block does NOT have the same function as the block in the top level.
|
||||
// The repositories here will be used for publishing your artifact, not for
|
||||
// retrieving dependencies.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version=1.16.5
|
||||
yarn_mappings=1.16.5+build.6
|
||||
loader_version=0.11.3
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
maven_group = com.example
|
||||
archives_base_name = fabric-example-mod
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.32.5+1.16
|
|
@ -0,0 +1,14 @@
|
|||
package net.fabricmc.example;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
public class ExampleMod implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
System.out.println("Hello Fabric world!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package net.fabricmc.example.mixin;
|
||||
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(TitleScreen.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "init()V")
|
||||
private void init(CallbackInfo info) {
|
||||
System.out.println("This line is printed by an example mod mixin!");
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 453 B |
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "modid",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "Example Mod",
|
||||
"description": "This is an example description! Tell everyone what your mod is about!",
|
||||
"authors": [
|
||||
"Me!"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/modid/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.fabricmc.example.ExampleMod"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"modid.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "net.fabricmc.example.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
plugins {
|
||||
id 'fabric-loom'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
// Add repositories to retrieve artifacts from in here.
|
||||
// You should only use this when depending on other mods because
|
||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||
// for more information about repositories.
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// To change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||
// You may need to force-disable transitiveness on them.
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
// If Javadoc is generated, this must be specified in that task too.
|
||||
it.options.encoding = "UTF-8"
|
||||
|
||||
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
|
||||
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
|
||||
// We'll use that if it's available, but otherwise we'll use the older option.
|
||||
def targetVersion = 8
|
||||
if (JavaVersion.current().isJava9Compatible()) {
|
||||
it.options.release = targetVersion
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this line, sources will not be generated.
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}"}
|
||||
}
|
||||
}
|
||||
|
||||
minecraft {
|
||||
accessWidener = file("src/main/resources/modid.accesswidener")
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||
repositories {
|
||||
// Add repositories to publish to here.
|
||||
// Notice: This block does NOT have the same function as the block in the top level.
|
||||
// The repositories here will be used for publishing your artifact, not for
|
||||
// retrieving dependencies.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version=1.16.5
|
||||
yarn_mappings=1.16.5+build.6
|
||||
loader_version=0.11.3
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
maven_group = com.example
|
||||
archives_base_name = fabric-example-mod
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.32.5+1.16
|
|
@ -0,0 +1,14 @@
|
|||
package net.fabricmc.example;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
public class ExampleMod implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
System.out.println("Hello Fabric world!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package net.fabricmc.example.mixin;
|
||||
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(TitleScreen.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "init()V")
|
||||
private void init(CallbackInfo info) {
|
||||
System.out.println("This line is printed by an example mod mixin!");
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 453 B |
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "modid",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "Example Mod",
|
||||
"description": "This is an example description! Tell everyone what your mod is about!",
|
||||
"authors": [
|
||||
"Me!"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/modid/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.fabricmc.example.ExampleMod"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"modid.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
},
|
||||
"accessWidener" : "modid.accesswidener"
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
accessWidener v1 named
|
||||
extendable class net/minecraft/fluid/FluidState
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "net.fabricmc.example.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
pluginManagement {
|
||||
plugins {
|
||||
id 'fabric-loom'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'fabric-loom'
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
||||
include 'basic'
|
||||
include 'projmap'
|
Loading…
Reference in New Issue