Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular refactor of codebase #749

Draft
wants to merge 3 commits into
base: 1.21
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added api/build.gradle
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.terraformersmc.modmenu.api;

import com.terraformersmc.modmenu.ModMenu;
import com.terraformersmc.modmenu.gui.ModsScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

Expand All @@ -18,7 +16,7 @@ public interface ModMenuApi {
* @return A "Mods" Screen
*/
static Screen createModsScreen(Screen previous) {
return new ModsScreen(previous);
return ModMenuApiImpl.getGuiProvider().createModsScreen(previous);
}

/**
Expand All @@ -28,7 +26,7 @@ static Screen createModsScreen(Screen previous) {
* @return The text that would be displayed on a Mods button
*/
static Text createModsButtonText() {
return ModMenu.createModsButtonText(true);
return ModMenuApiImpl.getGuiProvider().createModsButtonText();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.terraformersmc.modmenu.api;

import net.fabricmc.loader.api.FabricLoader;

class ModMenuApiImpl {
static ModMenuGuiProvider guiProvider = null;
static ModMenuUpdateHandlerPreferenceProvider updateHandlerPreferenceProvider = null;

static ModMenuGuiProvider getGuiProvider() {
if (guiProvider == null) {
var entrypoints = FabricLoader.getInstance().getEntrypoints("modmenu-gui", ModMenuGuiProvider.class);
if (!entrypoints.isEmpty()) {
guiProvider = entrypoints.getFirst();
}
}
if (guiProvider == null) {
throw new RuntimeException("Mod Menu's GUI is not installed, download here: https://modrinth.com/mod/modmenu");
}
return guiProvider;
}

static ModMenuUpdateHandlerPreferenceProvider getUpdateHandlerPreferenceProvider() {
if (updateHandlerPreferenceProvider == null) {
var entrypoints = FabricLoader.getInstance()
.getEntrypoints("modmenu-update-preferences", ModMenuUpdateHandlerPreferenceProvider.class);
if (!entrypoints.isEmpty()) {
updateHandlerPreferenceProvider = entrypoints.getFirst();
}
}
if (updateHandlerPreferenceProvider == null) {
throw new RuntimeException("Mod Menu's GUI is not installed, download here: https://modrinth.com/mod/modmenu");
}
return updateHandlerPreferenceProvider;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.terraformersmc.modmenu.api;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

/**
* This is used to provide your own Mods screens much like Mod Menu's GUI module does.
* Most mods should not use this API.
* To use it, implement this as a "modmenu-gui" entrypoint to your mod.
*/
public interface ModMenuGuiProvider {

/**
* Used for creating a {@link Screen} instance of the Mod Menu
* "Mods" screen
*
* @param previous The screen before opening
* @return A "Mods" Screen
*/
Screen createModsScreen(Screen previous);

/**
* Used for creating a {@link Text} just like what would appear
* on a Mod Menu Mods button
*
* @return The text that would be displayed on a Mods button
*/
Text createModsButtonText();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.terraformersmc.modmenu.api;

/**
* This is used to provide a user's preferences for the updates API in Mod Menu.
* To use it, implement this as a "modmenu-update-preferences" entrypoint to your mod.
*/
public interface ModMenuUpdateHandlerPreferenceProvider {
/**
* Used for your GUI provider to indicate a user's update channel preferences to users of Mod Menu API
*
* @return The update channel the user prefers
*/
UpdateChannel getUpdateChannelPreference();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.terraformersmc.modmenu.api;

import com.terraformersmc.modmenu.config.ModMenuConfig;

/**
* Supported update channels, in ascending order by stability.
*/
Expand All @@ -12,6 +10,6 @@ public enum UpdateChannel {
* @return the user's preferred update channel.
*/
public static UpdateChannel getUserPreference() {
return ModMenuConfig.UPDATE_CHANNEL.getValue();
return ModMenuApiImpl.getUpdateHandlerPreferenceProvider().getUpdateChannelPreference();
}
}
14 changes: 14 additions & 0 deletions api/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"schemaVersion": 1,
"id": "modmenu-api",
"name": "Mod Menu API",
"version": "$version",
"environment": "client",
"license": "MIT",
"icon": "assets/modmenu/icon.png",
"depends": {
"fabricloader": ">=0.15.10",
"minecraft": ">=1.21"
},
"description": "The API used for defining config screens or update checkers."
Prospector marked this conversation as resolved.
Show resolved Hide resolved
}
86 changes: 62 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,75 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'java'
id 'idea'
id 'eclipse'
id 'maven-publish'
id 'fabric-loom' version '1.6.+'
}

apply from: 'https://raw.githubusercontent.com/TerraformersMC/GradleScripts/2.7/ferry.gradle'
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'fabric-loom'

dependencies {
minecraft "com.mojang:minecraft:$project.minecraft_version"
mappings "net.fabricmc:yarn:$project.yarn_mappings:v2"
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

mod "fabric-loader", "net.fabricmc:fabric-loader:$project.loader_version"
repositories {
maven {
name = 'Nucleoid'
url = 'https://maven.nucleoid.xyz/'
}
}

includeMod "fabric-api", fabricApi.module("fabric-api-base", project.fabric_version)
includeMod "fabric-api", fabricApi.module("fabric-resource-loader-v0", project.fabric_version)
includeMod "fabric-api", fabricApi.module("fabric-screen-api-v1", project.fabric_version)
includeMod "fabric-api", fabricApi.module("fabric-key-binding-api-v1", project.fabric_version)
includeMod "fabric-api", fabricApi.module("fabric-lifecycle-events-v1", project.fabric_version)
ext {
mod = { String localOverrideKey, Object dep ->
File file = file("../.${localOverrideKey}-local");
if (file.exists()) {
dependencies.implementation(dep)
} else {
dependencies.modImplementation(dep)
}
}

includeMod "text-placeholder-api", "eu.pb4:placeholder-api:${project.text_placeholder_api_version}"
includeMod = { String localOverrideKey, Object dep ->
mod(localOverrideKey, dep)
dependencies.include(dep)
}
}

compileOnly "org.quiltmc:quilt-loader:$project.quilt_loader_version"
}
dependencies {
minecraft "com.mojang:minecraft:$project.minecraft_version"
mappings "net.fabricmc:yarn:$project.yarn_mappings:v2"

mod "fabric-loader", "net.fabricmc:fabric-loader:$project.loader_version"
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.encoding = "UTF-8"
}

java {
withSourcesJar()

repositories {
maven {
name = 'TerraformersMC'
url = 'https://maven.terraformersmc.com/'
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
maven {
name = 'Quilt'
url = 'https://maven.quiltmc.org/repository/release'

jar {
from "LICENSE"
}
maven {
name = 'Nucleoid'
url = 'https://maven.nucleoid.xyz/'
}

dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "eu.pb4:placeholder-api:${project.text_placeholder_api_version}"

afterEvaluate {
subprojects.each {
implementation project(path: ":${it.path}", configuration: "namedElements")
}
}
}
Loading
Loading