-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a27256
commit ecfeb3a
Showing
12 changed files
with
161 additions
and
33 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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.nssg.blockmixer.config; | ||
|
||
public class Config { | ||
private String settingMixMode; | ||
|
||
public String getSettingMixMode() { | ||
return settingMixMode; | ||
} | ||
public void setSettingMixMode(String settingMixMode) { | ||
this.settingMixMode = settingMixMode; | ||
} | ||
} |
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,59 @@ | ||
package com.nssg.blockmixer.config; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.stream.Collectors; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.nssg.blockmixer.BlockMixer; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
public class JsonManager { | ||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); | ||
private static final Path configPath = FabricLoader.getInstance().getConfigDir().resolve(BlockMixer.MOD_ID + ".json"); | ||
|
||
public static Config configJSON; | ||
|
||
public static void Load() throws IOException { | ||
Config config = new Config(); | ||
|
||
try (BufferedReader reader = new BufferedReader(new FileReader(configPath.toString()))) { | ||
String configString = reader.lines().collect(Collectors.joining()); | ||
reader.close(); | ||
configJSON = GSON.fromJson(configString, Config.class); | ||
System.out.println(configJSON.getSettingMixMode()); | ||
} | ||
|
||
catch (IOException e) { | ||
SetDefaults(config); | ||
Files.createFile(configPath); | ||
BufferedWriter writer = new BufferedWriter(new FileWriter(configPath.toFile())); | ||
String configString = GSON.toJson(config); | ||
writer.write(configString); | ||
writer.close(); | ||
} | ||
} | ||
|
||
public static void SetDefaults(Config config) { | ||
config.setSettingMixMode("Default"); | ||
} | ||
|
||
public static void RewriteConfig() { | ||
try { | ||
BufferedWriter writer = new BufferedWriter(new FileWriter(configPath.toFile())); | ||
String configString = GSON.toJson(configJSON); | ||
writer.write(configString); | ||
writer.close(); | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/nssg/blockmixer/config/ModMenuIntegration.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,41 @@ | ||
package com.nssg.blockmixer.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 net.minecraft.text.TranslatableText; | ||
|
||
public class ModMenuIntegration implements ModMenuApi{ | ||
|
||
public String[] modeList = {"Default", "Non-repeating", "Non-repeating [2]"}; | ||
|
||
@Override | ||
public ConfigScreenFactory<?> getModConfigScreenFactory() { | ||
return parent -> { | ||
ConfigBuilder builder = ConfigBuilder | ||
.create() | ||
.setParentScreen(null) | ||
.setTitle(new TranslatableText("title.blockmixer.config")); | ||
|
||
builder.setSavingRunnable(() -> { | ||
JsonManager.RewriteConfig(); | ||
}); | ||
|
||
ConfigEntryBuilder entryBuilder = builder.entryBuilder(); | ||
|
||
ConfigCategory general = builder | ||
.getOrCreateCategory(new TranslatableText("category.blockmixer.general")) | ||
|
||
.addEntry(entryBuilder.startSelector(new TranslatableText("option.blockmixer.mixmode"), modeList, JsonManager.configJSON.getSettingMixMode()) | ||
.setDefaultValue("Default") | ||
.setTooltip(new TranslatableText("option.blockmixer.mixmode.tooltip")) | ||
.setSaveConsumer(newValue -> JsonManager.configJSON.setSettingMixMode(newValue)) | ||
.build()); | ||
|
||
return builder.build(); | ||
}; | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
src/main/java/com/nssg/blockmixer/util/ModCommandRegister.java
This file was deleted.
Oops, something went wrong.
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,7 +1,13 @@ | ||
{ | ||
"key.blockmixer.addslot": "Add/remove hotbar slot", | ||
|
||
"commands.blockmixer.addslot": "Added slot %d", | ||
"commands.blockmixer.alreadyaddedslot": "is already added!", | ||
"commands.blockmixer.clearslot": "BlockMixer now is empty", | ||
"commands.blockmixer.removeslot": "Slot %d removed" | ||
"commands.blockmixer.removeslot": "Slot %d removed", | ||
|
||
"title.blockmixer.config": "BlockMixer options", | ||
"category.blockmixer.general": "Main settings", | ||
"option.blockmixer.mixmode": "Mix Mode", | ||
"option.blockmixer.mixmode.tooltip": "Default: random selection of slots\nNon-repeating: slot cannot be repeated twice in a row\nNon-repeating [2]: the slot cannot be repeated three times in a row" | ||
} |
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