2021-07-21 17:26:28 +08:00
|
|
|
package com.gtnewhorizon.structurelib;
|
|
|
|
|
|
2022-08-08 17:40:12 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Map;
|
2023-01-30 12:52:27 +00:00
|
|
|
|
2021-07-21 17:26:28 +08:00
|
|
|
import net.minecraftforge.common.config.ConfigCategory;
|
|
|
|
|
import net.minecraftforge.common.config.Configuration;
|
|
|
|
|
import net.minecraftforge.common.config.Property;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
2023-01-30 12:52:27 +00:00
|
|
|
|
2021-07-21 17:26:28 +08:00
|
|
|
public enum ConfigurationHandler {
|
2023-01-30 12:52:27 +00:00
|
|
|
|
2021-07-21 17:26:28 +08:00
|
|
|
INSTANCE;
|
|
|
|
|
|
|
|
|
|
private Configuration config;
|
|
|
|
|
private int maxCoexistingHologram;
|
|
|
|
|
private boolean removeCollidingHologram;
|
2022-09-02 16:44:12 +08:00
|
|
|
private int hintLifespan;
|
|
|
|
|
private int hintTransparency;
|
2022-08-23 18:56:47 +08:00
|
|
|
private int autoPlaceBudget;
|
|
|
|
|
private int autoPlaceInterval;
|
2021-07-21 17:26:28 +08:00
|
|
|
|
|
|
|
|
ConfigurationHandler() {
|
|
|
|
|
FMLCommonHandler.instance().bus().register(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void init(File f) {
|
|
|
|
|
config = new Configuration(f, ConfigurationVersion.latest().getVersionMarker());
|
|
|
|
|
ConfigurationVersion.migrateToLatest(config);
|
|
|
|
|
loadConfig();
|
|
|
|
|
setLanguageKeys();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setLanguageKeys() {
|
|
|
|
|
for (String categoryName : config.getCategoryNames()) {
|
|
|
|
|
ConfigCategory category = config.getCategory(categoryName);
|
|
|
|
|
category.setLanguageKey("structurelib.config." + categoryName);
|
|
|
|
|
for (Map.Entry<String, Property> entry : category.entrySet()) {
|
|
|
|
|
entry.getValue().setLanguageKey(String.format("%s.%s", category.getLanguagekey(), entry.getKey()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadConfig() {
|
2022-08-08 17:40:12 +08:00
|
|
|
maxCoexistingHologram = config.getInt(
|
|
|
|
|
"maxCoexisting",
|
|
|
|
|
"client.hologram",
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
100,
|
|
|
|
|
"An attempt will be made to prune old holograms when a new hologram is about to be projected");
|
|
|
|
|
removeCollidingHologram = config.getBoolean(
|
|
|
|
|
"removeColliding",
|
|
|
|
|
"client.hologram",
|
|
|
|
|
true,
|
|
|
|
|
"An attempt will be made to remove an existing hologram if it collides with a new hologram.");
|
2022-09-02 16:44:12 +08:00
|
|
|
hintLifespan = config
|
|
|
|
|
.getInt("hintLifespan", "client.hologram", 400, 1, 20000, "Ticks before a hologram disappears.");
|
|
|
|
|
hintTransparency = config.getInt(
|
|
|
|
|
"hintTransparency",
|
|
|
|
|
"client.hologram",
|
|
|
|
|
192,
|
|
|
|
|
1,
|
|
|
|
|
255,
|
|
|
|
|
"Alpha value of hologram particles. Higher the value, the more \"ghostly\" the hologram will appear to be.");
|
2022-08-23 18:56:47 +08:00
|
|
|
autoPlaceBudget = config.getInt(
|
|
|
|
|
"autoPlaceBudget",
|
|
|
|
|
"common.hologram",
|
|
|
|
|
25,
|
|
|
|
|
1,
|
|
|
|
|
200,
|
|
|
|
|
"Max number of elements can be placed in one round of auto place.\n"
|
|
|
|
|
+ "As expected, server side settings will overrides client settings.\n"
|
|
|
|
|
+ "Certain larger multi might increase these values beyond this configured value.");
|
|
|
|
|
autoPlaceInterval = config.getInt(
|
|
|
|
|
"autoPlaceInterval",
|
|
|
|
|
"common.hologram",
|
|
|
|
|
300,
|
|
|
|
|
0,
|
|
|
|
|
20000,
|
2022-09-06 16:34:46 +08:00
|
|
|
"Unit: millisecond. Minimal interval between two auto place round.\n"
|
2022-08-23 18:56:47 +08:00
|
|
|
+ "As expected, server side settings will overrides client settings.\n"
|
|
|
|
|
+ "Note this relates to the wall clock, not in game ticks.\n"
|
|
|
|
|
+ "Value smaller than default is likely to be perceived as no minimal interval whatsoever.");
|
2021-07-21 17:26:28 +08:00
|
|
|
|
|
|
|
|
if (config.hasChanged()) {
|
|
|
|
|
config.save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onConfigChange(ConfigChangedEvent.PostConfigChangedEvent e) {
|
|
|
|
|
if (e.modID.equals(StructureLibAPI.MOD_ID)) {
|
|
|
|
|
loadConfig();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMaxCoexistingHologram() {
|
|
|
|
|
return maxCoexistingHologram;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isRemoveCollidingHologram() {
|
|
|
|
|
return removeCollidingHologram;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 16:44:12 +08:00
|
|
|
public int getHintLifespan() {
|
|
|
|
|
return hintLifespan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getHintTransparency() {
|
|
|
|
|
return hintTransparency;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-23 18:56:47 +08:00
|
|
|
public int getAutoPlaceBudget() {
|
|
|
|
|
return autoPlaceBudget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getAutoPlaceInterval() {
|
|
|
|
|
return autoPlaceInterval;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 17:26:28 +08:00
|
|
|
Configuration getConfig() {
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
}
|