Skip to content

Commit

Permalink
Added a config screen and the ability to toggle the caffeine levels d…
Browse files Browse the repository at this point in the history
…isplay
  • Loading branch information
pluto7073 committed Feb 29, 2024
1 parent 252b3f1 commit 1f9e1e9
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 13 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion src/main/java/ml/pluto7073/plutoscoffee/Client.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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"));
}

}
55 changes: 55 additions & 0 deletions src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
@@ -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();
};
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/assets/plutoscoffee/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 0 additions & 4 deletions src/main/resources/assets/plutoscoffee/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 18 additions & 5 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -25,19 +33,24 @@
],
"client": [
"ml.pluto7073.plutoscoffee.Client"
],
"modmenu": [
"ml.pluto7073.plutoscoffee.config.CoffeeModMenuApiImpl"
]
},
"mixins": [
"plutoscoffee.mixins.json"
],

"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": "*"
}
}
2 changes: 1 addition & 1 deletion src/main/resources/resourcepacks/dark_gui/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -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"
}
}
Binary file added src/main/resources/resourcepacks/dark_gui/pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f9e1e9

Please sign in to comment.