plugins {
	id 'fabric-loom' version '1.10-SNAPSHOT'
	id 'maven-publish'
}

repositories {
	maven {
		url 'https://masa.dy.fi/maven'
	}
}

base {
	archivesName = project.archives_base_name
}

version = project.minecraft_version+'-'+project.mod_version
group = project.maven_group

fabricApi {
	configureTests {
		createSourceSet = true
		modId = "carpet-extra-gametest"
		enableClientGameTests = false
	}
}

tasks.named('runGameTest', JavaExec).configure {
	jvmArgs += [
		"-Dfabric-api.gametest.report-file=${project.buildDir}/junit.xml",
		"-Dmixin.debug.countInjections=true"
	]
}

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}"
	modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"

	// for gametests
	modGametestImplementation fabricApi.module("fabric-resource-loader-v0", project.fabric_api_version)
	modGametestImplementation fabricApi.module("fabric-networking-api-v1", project.fabric_api_version)
	modGametestImplementation fabricApi.module("fabric-registry-sync-v0", project.fabric_api_version)
	modGametestImplementation fabricApi.module("fabric-api-base", project.fabric_api_version)
	modGametestImplementation fabricApi.module("fabric-gametest-api-v1", project.fabric_api_version)
}

processResources {
	inputs.property "version", project.version

	filesMatching("fabric.mod.json") {
		expand "version": project.mod_version
	}
}

// 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
tasks.withType(JavaCompile).configureEach {
	options.encoding = "UTF-8"

	it.options.release = 21
}

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()

	sourceCompatibility = JavaVersion.VERSION_21
	targetCompatibility = JavaVersion.VERSION_21
}

jar {
	from "LICENSE"
}

// configure the maven publication
publishing {
	publications {
		mavenJava(MavenPublication) {
			from components.java
		}
	}

	// select the repositories you want to publish to
	repositories {
		// uncomment to publish to the local maven
		// mavenLocal()
	}
}
