Skip to content

Commit

Permalink
Attempting to become compatible with jitpack #2
Browse files Browse the repository at this point in the history
  • Loading branch information
MehradN committed Jul 2, 2023
1 parent 6085fb2 commit 6b845e6
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 96 deletions.
129 changes: 64 additions & 65 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,109 +1,108 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}

version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
archivesName = project.archives_base_name
}

loom {
splitEnvironmentSourceSets()

mods {
"mehrad-config" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
splitEnvironmentSourceSets()

mods {
"mehrad-config" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
}

sourceSets {
testmod {
compileClasspath += main.compileClasspath
compileClasspath += client.compileClasspath
runtimeClasspath += main.runtimeClasspath
runtimeClasspath += client.runtimeClasspath
}
testmod {
compileClasspath += main.compileClasspath
compileClasspath += client.compileClasspath
runtimeClasspath += main.runtimeClasspath
runtimeClasspath += client.runtimeClasspath
}
}

loom {
runs {
testmod {
client()
name = "TestMod Client"
source sourceSets.testmod
}
}
runs {
testmod {
client()
name = "TestMod Client"
source sourceSets.testmod
}
}
}

repositories {
maven {
name 'ParchmentMC'
url 'https://maven.parchmentmc.org'
}
maven {
url 'https://maven.terraformersmc.com/releases'
}
maven {
name 'ParchmentMC'
url 'https://maven.parchmentmc.org'
}
maven { url 'https://maven.terraformersmc.com/releases' }
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${project.parchment_version}@zip")
}
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${project.parchment_version}@zip")
}

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modCompileOnly ("com.terraformersmc:modmenu:${project.modmenu_version}") { transitive false }
modLocalRuntime ("com.terraformersmc:modmenu:${project.modmenu_version}") { transitive false }

testmodImplementation sourceSets.main.output
testmodImplementation sourceSets.client.output
testmodImplementation sourceSets.main.output
testmodImplementation sourceSets.client.output
}

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

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

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 17
}

java {
withSourcesJar()
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

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

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

// 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.
}
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// 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.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,15 @@

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import ir.mehradn.mehradconfig.MehradConfig;
import ir.mehradn.mehradconfig.gui.ConfigScreenBuilder;
import ir.mehradn.mehradconfig.gui.screen.MehradConfigScreen;
import net.minecraft.client.gui.screens.Screen;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

/**
* This is the entrypoint used by ModMenu to create the config buttons. Use the {@link #register} to register your configs.
*/
public class ModMenuEntrypoint implements ModMenuApi {
private static final Map<String, ConfigScreenLoader> screenBuilders = new HashMap<>();

/**
* Registers a config constructor and a config screen builder to build screens for ModMenu. The screen will be created by
* {@link ConfigScreenBuilder#buildAndLoad}.
*
* @param modId the mod id of your mod
* @param configConstructor a constructor for the type of the config to load, modify and save
* @param configScreenBuilder the config screen builder to build the screen with
*/
public static void register(String modId, Supplier<MehradConfig> configConstructor, ConfigScreenBuilder configScreenBuilder) {
screenBuilders.put(modId, new ConfigScreenLoader(configConstructor, configScreenBuilder));
}

@Override
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
Map<String, ConfigScreenFactory<?>> factories = new HashMap<>();
for (Map.Entry<String, ConfigScreenLoader> entry : screenBuilders.entrySet())
for (Map.Entry<String, ModMenuSupport.ConfigScreenLoader> entry : ModMenuSupport.screenBuilders.entrySet())
factories.put(entry.getKey(), (parent) -> entry.getValue().build(parent));
return factories;
}

private record ConfigScreenLoader(Supplier<MehradConfig> configConstructor, ConfigScreenBuilder configScreenBuilder) {
MehradConfigScreen build(Screen parentScreen) {
return this.configScreenBuilder.buildAndLoad(this.configConstructor, parentScreen);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ir.mehradn.mehradconfig.entrypoint;

import ir.mehradn.mehradconfig.MehradConfig;
import ir.mehradn.mehradconfig.gui.ConfigScreenBuilder;
import ir.mehradn.mehradconfig.gui.screen.MehradConfigScreen;
import net.minecraft.client.gui.screens.Screen;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

/**
* This class is used for registering your configs for ModMenu.
* @see #register
*/
public class ModMenuSupport {
static final Map<String, ConfigScreenLoader> screenBuilders = new HashMap<>();

/**
* Registers a config constructor and a config screen builder to build screens for ModMenu. The screen will be created by
* {@link ConfigScreenBuilder#buildAndLoad}.
*
* @param modId the mod id of your mod
* @param configConstructor a constructor for the type of the config to load, modify and save
* @param configScreenBuilder the config screen builder to build the screen with
*/
public static void register(String modId, Supplier<MehradConfig> configConstructor, ConfigScreenBuilder configScreenBuilder) {
screenBuilders.put(modId, new ConfigScreenLoader(configConstructor, configScreenBuilder));
}

record ConfigScreenLoader(Supplier<MehradConfig> configConstructor, ConfigScreenBuilder configScreenBuilder) {
MehradConfigScreen build(Screen parentScreen) {
return this.configScreenBuilder.buildAndLoad(this.configConstructor, parentScreen);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ir.mehradn.mehradconfigtest;

import ir.mehradn.mehradconfig.entrypoint.ModMenuEntrypoint;
import ir.mehradn.mehradconfig.entrypoint.ModMenuSupport;
import ir.mehradn.mehradconfig.gui.ConfigScreenBuilder;
import ir.mehradn.mehradconfigtest.config.TestConfig;
import net.fabricmc.api.ModInitializer;
Expand All @@ -25,6 +25,6 @@ public void onInitialize() {
//.setOnSave((minecraft, thisScreen, parentScreen) -> { LOGGER.info("SAVED!"); minecraft.setScreen(parentScreen); })
//.setOnCancel((minecraft, thisScreen, parentScreen) -> { LOGGER.info("CANCELED!"); minecraft.setScreen(parentScreen); })
;
ModMenuEntrypoint.register(MOD_ID, TestConfig::new, builder);
ModMenuSupport.register(MOD_ID, TestConfig::new, builder);
}
}

0 comments on commit 6b845e6

Please sign in to comment.