-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a config screen and the ability to toggle the caffeine levels d…
…isplay
- Loading branch information
Showing
11 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.