plugins {
	id "fabric-loom" version "1.8.+"
	id "maven-publish"
}

base.archivesName = archives_base_name
group = project.maven_group

// Formats the mod version to include the Minecraft version and build number (if present)
// example: 1.0.0+1.18.2-build.100
String buildNumber = System.getenv("GITHUB_RUN_NUMBER")
version = "$mod_version+$minecraft_version" + (buildNumber != null ? "-build.$buildNumber" : "")

repositories {
	maven { url = "https://maven.parchmentmc.org" } // Parchment mappings

	maven { url = "https://mvn.devos.one/releases" } // Porting Lib releases
	maven { url = "https://mvn.devos.one/snapshots" } // Create and several dependencies
	maven { url = "https://maven.tterrag.com/" } // Flywheel
	maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes
	maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven" } // Forge Config API Port

	maven { // Fabric ASM for Porting Lib
		url = "https://jitpack.io/"
		content { includeGroupAndSubgroups("com.github") }
	}

	maven { url = "https://maven.shedaniel.me" } // Cloth Config, REI
	maven { url = "https://maven.blamejared.com" } // JEI

	maven { url = "https://maven.terraformersmc.com/releases" } // Mod Menu, EMI
}

configurations.configureEach {
	resolutionStrategy {
		// make sure the desired version of loader is used. Sometimes old versions are pulled in transitively.
		force("net.fabricmc:fabric-loader:$fabric_loader_version")
	}
}

dependencies {
	// Setup
	minecraft("com.mojang:minecraft:$minecraft_version")
	mappings(loom.layered {
		it.officialMojangMappings { nameSyntheticMembers = false }
		it.parchment("org.parchmentmc.data:parchment-$minecraft_version:$parchment_version@zip")
	})
	modImplementation("net.fabricmc:fabric-loader:$fabric_loader_version")

	// dependencies
	modImplementation("net.fabricmc.fabric-api:fabric-api:$fabric_api_version")

	// Create - dependencies are added transitively
	modImplementation("com.simibubi.create:create-fabric-$minecraft_version:$create_version")

	// Development QOL
	modLocalRuntime("com.terraformersmc:modmenu:$modmenu_version")

	// Recipe Viewers - Create Fabric supports JEI, REI, and EMI.
	// See root gradle.properties to choose which to use at runtime.
	switch (recipe_viewer.toLowerCase(Locale.ROOT)) {
		case "jei": modLocalRuntime("mezz.jei:jei-$minecraft_version-fabric:$jei_version"); break
		case "rei": modLocalRuntime("me.shedaniel:RoughlyEnoughItems-fabric:$rei_version"); break
		case "emi": modLocalRuntime("dev.emi:emi-fabric:$emi_version"); break
		case "disabled": break
		default: println("Unknown recipe viewer specified: $recipe_viewer. Must be JEI, REI, EMI, or disabled.")
	}
	// if you would like to add integration with them, uncomment them here.
//    modCompileOnly("mezz.jei:jei-$minecraft_version-fabric:$jei_fabric_version")
//    modCompileOnly("mezz.jei:jei-$minecraft_version-common:$jei_fabric_version")
//    modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$rei_version")
//    modCompileOnly("me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:$rei_version")
//    modCompileOnly("dev.emi:emi:$emi_version")
}

processResources {
	// require dependencies to be the version compiled against or newer
	Map<String, Object> properties = [
			"version": version,
			"fabric_loader_version": fabric_loader_version,
			"fabric_api_version": fabric_api_version,
			"create_version": create_version,
			"minecraft_version": minecraft_version
	]

	inputs.properties(properties)

	filesMatching("fabric.mod.json") {
		expand properties
	}
}

java {
	withSourcesJar()
}

jar {
	from("LICENSE") {
		rename { "${it}_${project.archivesBaseName}" }
	}
}
