From 93e149be136af5ec73f548a9fb9280720270e012 Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Sat, 21 Oct 2023 14:05:13 +0300 Subject: [PATCH] Add ModMenu "integration" --- build.gradle | 12 +++++++++--- gradle.properties | 3 ++- .../a71/new_soviet/config/ModMenuCompat.java | 19 +++++++++++++++++++ .../java/su/a71/new_soviet/NewSoviet.java | 3 ++- .../a71/new_soviet/{ => config}/Config.java | 16 ++++++++++++---- .../su/a71/new_soviet/items/DiceItem.java | 2 +- .../assets/new_soviet/lang/ru_ru.json | 2 +- src/main/resources/fabric.mod.json | 3 +++ 8 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 src/client/java/su/a71/new_soviet/config/ModMenuCompat.java rename src/main/java/su/a71/new_soviet/{ => config}/Config.java (75%) diff --git a/build.gradle b/build.gradle index e71499c..d9ef57a 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,10 @@ base { } repositories { + maven { + name = 'ModMenu' + url = 'https://maven.terraformersmc.com/releases/' + } } loom { @@ -54,6 +58,7 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // Fabric API. + modApi "com.terraformersmc:modmenu:${modmenu_version}" // ModMenu } processResources { @@ -97,15 +102,16 @@ modrinth { token = System.getenv(modrinth_token) // DO NOT REVEAL THE TOKEN!!! projectId = mod_id versionNumber = mod_version - versionType = "beta" // `release`, `beta`, `alpha` + versionType = "beta" // release/beta/alpha uploadFile = remapJar gameVersions = ["1.20.1"] loaders = ["fabric"] dependencies { - // scope.type + required.project "fabric-api" + + // scope.type "name" // The scope can be `required`, `optional`, `incompatible`, or `embedded` // The type can either be `project` or `version` - required.project "fabric-api" // Creates a new required dependency on Fabric API // optional.version "sodium", "mc1.19.3-0.4.8" // Creates a new optional dependency on this specific version of Sodium } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index ae18aef..c17c378 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,8 +13,9 @@ mod_version=0.2 maven_group=su.a71 mod_id=new_soviet -# Dependencies (Fabric API) +# Dependencies fabric_version=0.90.0+1.20.1 +modmenu_version=7.2.2 # Modrinth publishing modrinth_token=tokenhere \ No newline at end of file diff --git a/src/client/java/su/a71/new_soviet/config/ModMenuCompat.java b/src/client/java/su/a71/new_soviet/config/ModMenuCompat.java new file mode 100644 index 0000000..88d5485 --- /dev/null +++ b/src/client/java/su/a71/new_soviet/config/ModMenuCompat.java @@ -0,0 +1,19 @@ +package su.a71.new_soviet.config; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +public class ModMenuCompat implements ModMenuApi{ + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return screen -> new Screen(Text.of("")) { + @Override + protected void init() { + Config.openConfigFile(); + this.client.setScreen(screen); + } + }; + } +} \ No newline at end of file diff --git a/src/main/java/su/a71/new_soviet/NewSoviet.java b/src/main/java/su/a71/new_soviet/NewSoviet.java index 568f1c8..a4a674e 100644 --- a/src/main/java/su/a71/new_soviet/NewSoviet.java +++ b/src/main/java/su/a71/new_soviet/NewSoviet.java @@ -3,10 +3,11 @@ package su.a71.new_soviet; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.fabricmc.api.ModInitializer; - import net.minecraft.util.math.random.Random; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import su.a71.new_soviet.config.Config; import su.a71.new_soviet.registration.NSE_Blocks; import su.a71.new_soviet.registration.NSE_Custom; import su.a71.new_soviet.registration.NSE_Items; diff --git a/src/main/java/su/a71/new_soviet/Config.java b/src/main/java/su/a71/new_soviet/config/Config.java similarity index 75% rename from src/main/java/su/a71/new_soviet/Config.java rename to src/main/java/su/a71/new_soviet/config/Config.java index ae29013..cb00d78 100644 --- a/src/main/java/su/a71/new_soviet/Config.java +++ b/src/main/java/su/a71/new_soviet/config/Config.java @@ -1,4 +1,7 @@ -package su.a71.new_soviet; +package su.a71.new_soviet.config; + +import net.minecraft.util.Util; +import su.a71.new_soviet.NewSoviet; import java.io.*; @@ -22,8 +25,8 @@ public class Config { private static void generateDefault() { INSTANCE = new Config(); - NewSoviet.LOG.info("Generated config file at config/new_soviet.json"); - File file = new File("config/new_soviet.json"); + NewSoviet.LOG.info("Generated config file at config/" + NewSoviet.MOD_ID + ".json"); + File file = new File("config/" + NewSoviet.MOD_ID + ".json"); if(!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { NewSoviet.LOG.error("Error making dir, using default config"); INSTANCE = new Config(); @@ -40,7 +43,7 @@ public class Config { public static void load() { // Generate config if it doesn't exist - File file = new File("config/new_soviet.json"); + File file = new File("config/" + NewSoviet.MOD_ID + ".json"); if(!file.exists()) { generateDefault(); } @@ -59,4 +62,9 @@ public class Config { INSTANCE = new Config(); } } + + public static void openConfigFile() { + String configPath = "config/" + NewSoviet.MOD_ID + ".json"; + Util.getOperatingSystem().open(new File(configPath)); + } } diff --git a/src/main/java/su/a71/new_soviet/items/DiceItem.java b/src/main/java/su/a71/new_soviet/items/DiceItem.java index 60fa342..c7ac541 100644 --- a/src/main/java/su/a71/new_soviet/items/DiceItem.java +++ b/src/main/java/su/a71/new_soviet/items/DiceItem.java @@ -14,7 +14,7 @@ import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; import java.util.List; -import su.a71.new_soviet.Config; +import su.a71.new_soviet.config.Config; import su.a71.new_soviet.NewSoviet; import su.a71.new_soviet.registration.NSE_Sounds; import su.a71.new_soviet.registration.NSE_Stats; diff --git a/src/main/resources/assets/new_soviet/lang/ru_ru.json b/src/main/resources/assets/new_soviet/lang/ru_ru.json index 8157f89..ea645d4 100644 --- a/src/main/resources/assets/new_soviet/lang/ru_ru.json +++ b/src/main/resources/assets/new_soviet/lang/ru_ru.json @@ -477,5 +477,5 @@ "advancement.new_soviet.sickle_kill.name": "Боевой колхозник", "advancement.new_soviet.sickle_kill.desc": "Убейте кого-то серпом", - "modmenu.descriptionTranslation.modmenu": "Мод для minecraft который вернёт вас в старые добрые времена\nNSE добавляет строительные блоки, мебель, предметы и много всего другого в стиле СССР" + "modmenu.descriptionTranslation.new_soviet": "Мод для minecraft который вернёт вас в старые добрые времена\nNSE добавляет строительные блоки, мебель, предметы и много всего другого в стиле СССР" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ef7d6a2..f75d39f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,6 +23,9 @@ ], "fabric-datagen": [ "su.a71.new_soviet.DataGeneration" + ], + "modmenu": [ + "su.a71.new_soviet.config.ModMenuCompat" ] }, "depends": {