From 8656833f6f44c8b9ac6417b4cbc35976fdd64ab3 Mon Sep 17 00:00:00 2001 From: Meredith Espinosa Date: Wed, 24 Apr 2019 14:37:08 -0700 Subject: [PATCH] fix server crash due to tooltips (closes #4), add config gui for mod menu --- build.gradle | 6 +++- .../cottonmc/epicurean/ConfigManager.java | 30 +++++++++++++++++++ .../epicurean/EpicureanGastronomy.java | 5 ++++ .../cottonmc/epicurean/item/MealItem.java | 1 - src/main/resources/fabric.mod.json | 5 +++- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 8461fe4..7efe3d0 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.8 archivesBaseName = "epicurean-gastronomy" group = "io.github.cottonmc" -version = "2.1.1+1.14" +version = "2.1.2+1.14" minecraft { refmapName = 'mixins.epicurean.refmap.json' @@ -32,6 +32,7 @@ minecraft { repositories { mavenCentral() maven { url 'http://server.bbkr.space:8081/artifactory/libs-snapshot/' } + maven { url = "https://minecraft.curseforge.com/api/maven" } } dependencies { @@ -41,8 +42,11 @@ dependencies { modCompile "net.fabricmc:fabric:0.2.7+build.127" include "net.fabricmc:fabric:0.2.7+build.127" + modCompile "io.github.prospector.modmenu:ModMenu:1.4.1-74" modCompile "io.github.cottonmc:cotton:0.6.0+1.14-SNAPSHOT" include "io.github.cottonmc:cotton:0.6.0+1.14-SNAPSHOT" + modCompile "cloth-config:ClothConfig:0.2.1.14" + include "cloth-config:ClothConfig:0.2.1.14" } processResources { diff --git a/src/main/java/io/github/cottonmc/epicurean/ConfigManager.java b/src/main/java/io/github/cottonmc/epicurean/ConfigManager.java index 987b1bc..069e080 100644 --- a/src/main/java/io/github/cottonmc/epicurean/ConfigManager.java +++ b/src/main/java/io/github/cottonmc/epicurean/ConfigManager.java @@ -4,11 +4,16 @@ import io.github.cottonmc.repackage.blue.endless.jankson.JsonElement; import io.github.cottonmc.repackage.blue.endless.jankson.JsonObject; import io.github.cottonmc.repackage.blue.endless.jankson.impl.SyntaxError; +import me.shedaniel.cloth.api.ConfigScreenBuilder; +import me.shedaniel.cloth.gui.ClothConfigScreen; +import me.shedaniel.cloth.gui.entries.*; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.reflect.Method; public class ConfigManager { private static String configName = "EpicureanGastronomy"; @@ -88,4 +93,29 @@ public static void save(Object obj) { EpicureanGastronomy.LOGGER.warn("Failed to save config file: ", e); } } + + public static void getConfigScreen() { + try { + Class clazz = Class.forName("io.github.prospector.modmenu.api.ModMenuApi"); + Method method = clazz.getMethod("addConfigOverride", String.class, Runnable.class); + method.invoke(null, "epicurean", (Runnable) () -> { + ClothConfigScreen.Builder builder = new ClothConfigScreen.Builder(MinecraftClient.getInstance().currentScreen, "Epicurean Gastronomy Config", null); + builder.addCategories("Primary Features", "Fun Features"); + ConfigScreenBuilder.CategoryBuilder primaryFeatures = builder.getCategory("Primary Features"); + primaryFeatures.addOption(new BooleanListEntry("Hopper Harvesting", EpicureanGastronomy.config.hopperHarvest, "text.cloth-config.reset_value", () -> false, null)); + primaryFeatures.addOption(new BooleanListEntry("Saturation Only", EpicureanGastronomy.config.useSaturationOnly, "text.cloth-config.reset_value", () -> false, null)); + primaryFeatures.addOption(new IntegerListEntry("Natural Regen Speed", EpicureanGastronomy.config.naturalRegenSpeed, "text.cloth-config.reset_value", () -> 15, null)); + primaryFeatures.addOption(new DoubleListEntry("Seasoning Efficiency", EpicureanGastronomy.config.seasoningEfficiency, "text.cloth-config.reset_value", () -> 0.3d, null)); + ConfigScreenBuilder.CategoryBuilder funFeatures = builder.getCategory("Fun Features"); + funFeatures.addOption(new BooleanListEntry("Edible Nuggets", EpicureanGastronomy.config.edibleNuggets, "text.cloth-config.reset_value", () -> false, null)); + funFeatures.addOption(new BooleanListEntry("Omnivore Mode", EpicureanGastronomy.config.omnivoreEnabled, "text.cloth-config.reset_value", () -> false, null)); + funFeatures.addOption(new IntegerSliderEntry("Omnivore Hunger", 0, 20, EpicureanGastronomy.config.omnivoreFoodRestore, "text.cloth-config.reset_value", () -> 2, null)); + funFeatures.addOption(new FloatListEntry("Omnivore Saturation", EpicureanGastronomy.config.omnivoreSaturationRestore, "text.cloth-config.reset_value", () -> 0.25f, null)); + funFeatures.addOption(new DoubleListEntry("Omnivore Item Damage", EpicureanGastronomy.config.omnivoreItemDamage, "text.cloth-config.reset_value", () -> 30d, null)); + MinecraftClient.getInstance().openScreen(builder.build()); + }); + } catch (Exception e) { + EpicureanGastronomy.LOGGER.error("Failed to add config screen to Mod Menu", e); + } + } } diff --git a/src/main/java/io/github/cottonmc/epicurean/EpicureanGastronomy.java b/src/main/java/io/github/cottonmc/epicurean/EpicureanGastronomy.java index 0c846c7..cf71bc5 100644 --- a/src/main/java/io/github/cottonmc/epicurean/EpicureanGastronomy.java +++ b/src/main/java/io/github/cottonmc/epicurean/EpicureanGastronomy.java @@ -10,6 +10,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.resource.ResourceType; @@ -38,6 +39,10 @@ public void onInitialize() { EpicureanRecipes.init(); CropGeneration.registerCrops(); ResourceManagerHelper.get(ResourceType.DATA).registerReloadListener(new IngredientProfiles()); + + if (FabricLoader.getInstance().isModLoaded("modmenu")) { + ConfigManager.getConfigScreen(); + } } } diff --git a/src/main/java/io/github/cottonmc/epicurean/item/MealItem.java b/src/main/java/io/github/cottonmc/epicurean/item/MealItem.java index 5473540..087e49f 100644 --- a/src/main/java/io/github/cottonmc/epicurean/item/MealItem.java +++ b/src/main/java/io/github/cottonmc/epicurean/item/MealItem.java @@ -9,7 +9,6 @@ import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FoodItemSetting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8221119..a8cdc25 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,7 +22,10 @@ }, "mixins": [ "epicurean.common.json", - "epicurean.client.json" + { + "config": "epicurean.client.json", + "environment": "client" + } ], "requires": { "fabricloader": ">=0.4.0",