From 1f9e1e919d452e27bf1e73864308326c20a53ad2 Mon Sep 17 00:00:00 2001 From: pluto7073 <20planetpluto05@gmail.com> Date: Wed, 28 Feb 2024 20:43:56 -0500 Subject: [PATCH] Added a config screen and the ability to toggle the caffeine levels display --- build.gradle | 6 ++ gradle.properties | 2 + .../ml/pluto7073/plutoscoffee/Client.java | 10 +++- .../plutoscoffee/config/CoffeeConfig.java | 55 ++++++++++++++++++ .../config/CoffeeModMenuApiImpl.java | 39 +++++++++++++ .../mixins/client/InGameHudMixin.java | 10 +++- .../assets/plutoscoffee/lang/en_us.json | 6 +- .../assets/plutoscoffee/lang/fr_fr.json | 4 -- src/main/resources/fabric.mod.json | 23 ++++++-- .../resourcepacks/dark_gui/pack.mcmeta | 2 +- .../resources/resourcepacks/dark_gui/pack.png | Bin 0 -> 680 bytes 11 files changed, 144 insertions(+), 13 deletions(-) create mode 100644 src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java create mode 100644 src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java create mode 100644 src/main/resources/resourcepacks/dark_gui/pack.png diff --git a/build.gradle b/build.gradle index 69c9b31..2f35017 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,8 @@ repositories { // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. + maven { url "https://maven.shedaniel.me/" } + maven { url "https://maven.terraformersmc.com/releases/" } } loom { @@ -37,6 +39,10 @@ dependencies { // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" + + // Cloth Config & ModMenu + modApi "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}" + modApi "com.terraformersmc:modmenu:${project.modmenu_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index 120af06..bb80d01 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,3 +15,5 @@ archives_base_name = PlutosCoffeeMod-Fabric # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api fabric_version=0.91.6+1.20.2 +cloth_version=12.0.119 +modmenu_version=8.0.0-beta.2 diff --git a/src/main/java/ml/pluto7073/plutoscoffee/Client.java b/src/main/java/ml/pluto7073/plutoscoffee/Client.java index 6c3e8ad..0d21dc5 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/Client.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/Client.java @@ -1,5 +1,6 @@ package ml.pluto7073.plutoscoffee; +import ml.pluto7073.plutoscoffee.config.CoffeeConfig; import ml.pluto7073.plutoscoffee.registry.ModBlocks; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; @@ -9,19 +10,26 @@ import net.fabricmc.fabric.api.resource.ResourcePackActivationType; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.render.RenderLayer; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import java.io.File; + @Environment(EnvType.CLIENT) public class Client implements ClientModInitializer { + public static CoffeeConfig CONFIG; + public void onInitializeClient() { FabricLoader.getInstance().getModContainer(PlutosCoffee.MOD_ID).ifPresent(container -> - ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(PlutosCoffee.MOD_ID, "dark_gui"), container, ResourcePackActivationType.NORMAL)); + ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(PlutosCoffee.MOD_ID, "dark_gui"), container, Text.translatable("pack.plutoscoffee.dark_gui"), ResourcePackActivationType.NORMAL)); BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_CROP, RenderLayer.getCutout()); BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_BREWER, RenderLayer.getCutout()); BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_GRINDR, RenderLayer.getCutout()); BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.ESPRESSO_MACHINE, RenderLayer.getCutout()); + + CONFIG = new CoffeeConfig(new File("config/plutoscoffee.properties")); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java b/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java new file mode 100644 index 0000000..48bc777 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java @@ -0,0 +1,55 @@ +package ml.pluto7073.plutoscoffee.config; + +import ml.pluto7073.plutoscoffee.PlutosCoffee; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; + +public class CoffeeConfig { + + private final Properties properties; + + public CoffeeConfig(File configFile) { + properties = new Properties(); + loadDefaults(); + + if (!configFile.exists()) return; + try { + properties.load(new FileReader(configFile)); + } catch (IOException e) { + PlutosCoffee.logger.error("Failed to load mod config", e); + } + } + + private void loadDefaults() { + properties.put("shouldShowCoffeeBar", "true"); + } + + public void save(File configFile) { + if (!configFile.exists()) { + try { + configFile.createNewFile(); + } catch (IOException e) { + PlutosCoffee.logger.error("Failed to create config file", e); + } + } + + try (FileWriter writer = new FileWriter(configFile)) { + properties.store(writer, "Pluto's Coffee Mod Config"); + } catch (IOException e) { + PlutosCoffee.logger.error("Failed to save mod config", e); + } + } + + public boolean shouldShowCoffeeBar() { + return Boolean.parseBoolean((String) properties.get("shouldShowCoffeeBar")); + } + + public void setShouldShowCoffeeBar(boolean state) { + properties.put("shouldShowCoffeeBar", String.valueOf(state)); + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java b/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java new file mode 100644 index 0000000..1a33a5a --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java @@ -0,0 +1,39 @@ +package ml.pluto7073.plutoscoffee.config; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import me.shedaniel.clothconfig2.api.ConfigBuilder; +import me.shedaniel.clothconfig2.api.ConfigCategory; +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; +import ml.pluto7073.plutoscoffee.Client; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +import java.io.File; + +public class CoffeeModMenuApiImpl implements ModMenuApi { + + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return (parent) -> { + ConfigBuilder builder = ConfigBuilder.create() + .setParentScreen(parent) + .setTitle(Text.translatable("title.plutoscoffee.config")) + .setSavingRunnable(() -> Client.CONFIG.save(new File("config/plutoscoffee.properties"))) + .setDefaultBackgroundTexture(new Identifier("minecraft:textures/gui/options_background.png")); + + ConfigCategory category = builder.getOrCreateCategory(Text.translatable("title.plutoscoffee.config")); + + ConfigEntryBuilder entryBuilder = builder.entryBuilder(); + + category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("config.plutoscoffee.shouldShowCoffeeBar"), Client.CONFIG.shouldShowCoffeeBar()) + .setDefaultValue(true) + .setTooltip(Text.translatable("config.plutoscoffee.shouldShowCoffeeBar.tooltip")) + .setSaveConsumer(newVal -> Client.CONFIG.setShouldShowCoffeeBar(newVal)) + .build()); + + return builder.build(); + }; + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java index 95e202b..b52dbc8 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java @@ -1,9 +1,11 @@ package ml.pluto7073.plutoscoffee.mixins.client; +import ml.pluto7073.plutoscoffee.Client; import ml.pluto7073.plutoscoffee.PlutosCoffee; import ml.pluto7073.plutoscoffee.Utils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; @@ -41,6 +43,7 @@ public abstract class InGameHudMixin { @Inject(at = @At("TAIL"), method = "renderStatusBars") public void plutoscoffee_renderCaffeineContentDisplay(DrawContext context, CallbackInfo ci) { + if (!Client.CONFIG.shouldShowCoffeeBar()) return; PlayerEntity playerEntity = this.getCameraPlayer(); if (playerEntity == null) return; this.client.getProfiler().push("caffeineDisplay"); @@ -56,9 +59,14 @@ public void plutoscoffee_renderCaffeineContentDisplay(DrawContext context, Callb } LivingEntity ridden = this.getRiddenEntity(); + + if (FabricLoader.getInstance().isModLoaded("dehydration") && !playerEntity.isCreative() && ridden == null) { + baseYValue -= 10; + } + if (ridden != null) { if (ridden.getHealth() > 0){ - int height = Utils.calculateHealthBarHeightPixels((int) ridden.getHealth(), 10, 9); + int height = Utils.calculateHealthBarHeightPixels((int) ridden.getHealth(), 10, 10); baseYValue -= height; } } diff --git a/src/main/resources/assets/plutoscoffee/lang/en_us.json b/src/main/resources/assets/plutoscoffee/lang/en_us.json index d5ddc8e..ac38d8b 100644 --- a/src/main/resources/assets/plutoscoffee/lang/en_us.json +++ b/src/main/resources/assets/plutoscoffee/lang/en_us.json @@ -53,5 +53,9 @@ "stat.plutoscoffee.interact_with_coffee_brewer": "Interactions with Coffee Brewer", "stat.plutoscoffee.interact_with_coffee_workstation": "Interactions with Coffee Workstation", "death.attack.caffeine_overdose": "%1$s drank too much caffeine", - "effect.plutoscoffee.caffeine_overdose": "Caffeine Overdose" + "effect.plutoscoffee.caffeine_overdose": "Caffeine Overdose", + "title.plutoscoffee.config": "Pluto's Coffee Mod Settings", + "config.plutoscoffee.shouldShowCoffeeBar": "Show Current Caffeine Levels", + "config.plutoscoffee.shouldShowCoffeeBar.tooltip": "Whether or not to show the current amount of caffeine in your system above the hunger bar", + "pack.plutoscoffee.dark_gui": "Dark GUI" } diff --git a/src/main/resources/assets/plutoscoffee/lang/fr_fr.json b/src/main/resources/assets/plutoscoffee/lang/fr_fr.json index 6a7850d..4de35c5 100644 --- a/src/main/resources/assets/plutoscoffee/lang/fr_fr.json +++ b/src/main/resources/assets/plutoscoffee/lang/fr_fr.json @@ -24,10 +24,6 @@ "coffee_type.plutoscoffee.light_roast": "Light Roast", "coffee_type.plutoscoffee.medium_roast": "Medium Roast", "coffee_type.plutoscoffee.dark_roast": "Dark Roast", - "coffee_addition.plutoscoffee.milk": "Milk", - "coffee_addition.plutoscoffee.caramel": "Caramel", - "coffee_addition.plutoscoffee.sugar": "Sugar", - "coffee_addition.plutoscoffee.mocha_syrup": "Mocha Syrup", "container.coffee_workstation": "Coffee Workstation", "container.coffee_brewer": "Coffee Brewer", "itemGroup.plutoscoffee.pc_group": "Objets de PlutosCoffeeMod", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d97239a..c460e69 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -10,9 +10,17 @@ ], "contact": { "homepage": "https://modrinth.com/mod/plutos-coffee-mod", - "sources": "https://github.com/pluto7073/PlutosCoffeeMod-Fabric", "issues": "https://github.com/pluto7073/PlutosCoffeeMod-Fabric/issues", - "wiki": "https://github.com/pluto7073/PlutosCoffeeMod-Fabric/wiki" + "sources": "https://github.com/pluto7073/PlutosCoffeeMod-Fabric" + }, + + "custom": { + "modmenu": { + "links": { + "modmenu.wiki": "https://github.com/pluto7073/PlutosCoffeeMod-Fabric/wiki" + }, + "update_checker": true + } }, "license": "MIT", @@ -25,6 +33,9 @@ ], "client": [ "ml.pluto7073.plutoscoffee.Client" + ], + "modmenu": [ + "ml.pluto7073.plutoscoffee.config.CoffeeModMenuApiImpl" ] }, "mixins": [ @@ -32,12 +43,14 @@ ], "depends": { - "fabricloader": ">=0.15.3", + "fabricloader": ">=0.15.7", "fabric": "*", "minecraft": "~1.20.2", - "java": ">=17" + "java": ">=17", + "cloth-config": ">=12.0.119" }, "suggests": { - "flamingo": "*" + "flamingo": "*", + "modmenu": "*" } } diff --git a/src/main/resources/resourcepacks/dark_gui/pack.mcmeta b/src/main/resources/resourcepacks/dark_gui/pack.mcmeta index 09886f3..c8bfce4 100644 --- a/src/main/resources/resourcepacks/dark_gui/pack.mcmeta +++ b/src/main/resources/resourcepacks/dark_gui/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "pack_format": 15, + "pack_format": 18, "description": "Makes the GUI for Pluto's Coffee Mod be in Dark Mode, similar to Vanilla Tweaks Dark Mode" } } \ No newline at end of file diff --git a/src/main/resources/resourcepacks/dark_gui/pack.png b/src/main/resources/resourcepacks/dark_gui/pack.png new file mode 100644 index 0000000000000000000000000000000000000000..a5c13da8edfc55a13dc98863ed1ba78ca57a448c GIT binary patch literal 680 zcmV;Z0$2TsP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0zFAYK~y+TZBtE; z5=J>J>b5#xx|&@Foku_@Bo3qZ!^ z6OQZP`Ii_EUv?dKi;Sz)>OTp@d_IS4Wc=xz4xmjElNTBAX_Vl>i>^bamI002wvp}Q zB7feybyd^j%&_@wxS#SB?mvCMZ5`uypvYVboV+A<&VZB0nV8LHvQF6?#Y8UHWP)?{ zndgC8t>cu(W6xX3e~e>{WDW)c39{fKFBG-fyHcrCWLFj^b^7Lc9{vD*fG