-
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.
remove cloth config implementation and dependency, optimize import, r…
…ewrite metadata
- Loading branch information
Showing
9 changed files
with
105 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,35 @@ | ||
package dev.blueon.quickleafdecay; | ||
|
||
import me.shedaniel.autoconfig.ConfigData; | ||
import me.shedaniel.autoconfig.annotation.ConfigEntry; | ||
|
||
import static dev.blueon.quickleafdecay.QuickLeafDecay.NAMESPACE; | ||
|
||
@me.shedaniel.autoconfig.annotation.Config(name = NAMESPACE) | ||
public class Config implements ConfigData { | ||
@ConfigEntry.Gui.Tooltip | ||
public boolean matchLeavesTypes = FeatureControl.Defaults.matchLeavesTypes; | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
public boolean unknownLeavesOnlyMatchSelf = FeatureControl.Defaults.unknownLeavesOnlyMatchSelf; | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
public boolean matchLogsToLeaves = FeatureControl.Defaults.matchLogsToLeaves; | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
public boolean ignorePersistentLeaves = FeatureControl.Defaults.ignorePersistentLeaves; | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
public boolean accelerateLeavesDecay = FeatureControl.Defaults.accelerateLeavesDecay; | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
@ConfigEntry.Gui.CollapsibleObject | ||
public DecayDelay decayDelay = new DecayDelay(); | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
public boolean updateDiagonalLeaves = FeatureControl.Defaults.updateDiagonalLeaves; | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
public boolean doDecayingLeavesEffects = FeatureControl.Defaults.doDecayingLeavesEffects; | ||
|
||
@ConfigEntry.Gui.Tooltip | ||
public boolean fetchTranslationUpdates = FeatureControl.Defaults.fetchTranslationUpdates; | ||
import dev.blueon.quickleafdecay.configloader.ConfigLoader; | ||
|
||
public class Config | ||
{ | ||
public static boolean matchLeavesTypes = true; | ||
public static boolean unknownLeavesOnlyMatchSelf = true; | ||
public static boolean matchLogsToLeaves = true; | ||
public static boolean ignorePersistentLeaves = true; | ||
public static boolean accelerateLeavesDecay = true; | ||
public static int minDecayDelay = 10; | ||
public static int maxDecayDelay = 60; | ||
public static boolean updateDiagonalLeaves = true; | ||
public static boolean doDecayingLeavesEffects = false; | ||
public static boolean fetchTranslationUpdates = true; | ||
|
||
// Saving and loading | ||
|
||
public static void load() | ||
{ | ||
ConfigLoader.load(Config.class, getFileName()); | ||
} | ||
|
||
public static class DecayDelay { | ||
@ConfigEntry.Gui.Tooltip | ||
@ConfigEntry.BoundedDiscrete(max = 100) | ||
public int minimum = FeatureControl.Defaults.minDecayDelay; | ||
public static void save() | ||
{ | ||
ConfigLoader.save(Config.class, getFileName()); | ||
} | ||
|
||
@ConfigEntry.BoundedDiscrete(max = 100) | ||
@ConfigEntry.Gui.Tooltip | ||
public int maximum = FeatureControl.Defaults.maxDecayDelay; | ||
private static String getFileName() | ||
{ | ||
return "quickleafdecay.json"; | ||
} | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/dev/blueon/quickleafdecay/configloader/ConfigException.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,9 @@ | ||
package dev.blueon.quickleafdecay.configloader; | ||
|
||
public class ConfigException extends RuntimeException | ||
{ | ||
public ConfigException(String message, Throwable cause) | ||
{ | ||
super(message, cause); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/dev/blueon/quickleafdecay/configloader/ConfigLoader.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,44 @@ | ||
//borrowed from https://github.com/WerDei/Server-Hats/blob/main/src/main/java/net/werdei/configloader/ConfigLoader.java | ||
package dev.blueon.quickleafdecay.configloader; | ||
|
||
import com.google.gson.GsonBuilder; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
|
||
public abstract class ConfigLoader | ||
{ | ||
private static final GsonBuilder gsonBuilder = new GsonBuilder() | ||
.excludeFieldsWithModifiers(java.lang.reflect.Modifier.TRANSIENT) | ||
.setPrettyPrinting(); | ||
|
||
public static void load(Class<?> configClass, String fileName) | ||
{ | ||
File file = new File(FabricLoader.getInstance().getConfigDir().toFile(), fileName); | ||
try | ||
{ | ||
FileReader reader = new FileReader(file); | ||
gsonBuilder.create().fromJson(reader, configClass); | ||
reader.close(); | ||
} | ||
catch (Exception ignored) {} | ||
|
||
} | ||
|
||
public static void save(Class<?> configClass, String fileName) throws ConfigException | ||
{ | ||
File file = new File(FabricLoader.getInstance().getConfigDir().toFile(), fileName); | ||
try | ||
{ | ||
FileWriter writer = new FileWriter(file); | ||
writer.write(gsonBuilder.create().toJson(configClass.getConstructor().newInstance())); | ||
writer.close(); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new ConfigException("Error creating a temporary instance of class " + configClass.getName(), e); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
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