Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
11 443
src/client/java/fpspvp/client/FpsConfig.java
package fpspvp.client;
import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.YetAnotherConfigLib;
import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder;
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import java.util.function.Consumer;
import java.util.function.Supplier;
public final class FpsConfig {
private static final Path CONFIG_PATH = Path.of("config", "fpspvp.properties");
private static final FpsConfig INSTANCE = loadFromDisk();
public boolean reducePotionParticles = true;
public boolean reduceCriticalParticles = true;
public boolean reduceExplosionParticles = true;
public boolean reduceSmokeParticles = true;
public boolean reduceOtherParticles;
public boolean shrinkWeapons = true;
public float weaponScale = 0.82F;
public boolean shrinkTotem = true;
public float totemScale = 0.75F;
public boolean hideOffhandShield = true;
public boolean shrinkFireOverlay = true;
public float fireScale = 0.45F;
public boolean reduceHandSwingAnimation;
private FpsConfig() {
}
public static FpsConfig get() {
return INSTANCE;
}
public static Screen createScreen(Screen parent) {
FpsConfig config = get();
return YetAnotherConfigLib.createBuilder()
.title(Text.literal("FPS PvP Optimizer"))
.category(ConfigCategory.createBuilder()
.name(Text.literal("Particles"))
.option(booleanOption("Potion particles", "Hide potion-effect particles without changing the effects.", true,
() -> config.reducePotionParticles, value -> config.reducePotionParticles = value))
.option(booleanOption("Critical-hit particles", "Hide critical-hit and enchanted-hit particles.", true,
() -> config.reduceCriticalParticles, value -> config.reduceCriticalParticles = value))
.option(booleanOption("Explosion particles", "Hide explosion particles.", true,
() -> config.reduceExplosionParticles, value -> config.reduceExplosionParticles = value))
.option(booleanOption("Smoke particles", "Hide smoke and campfire smoke particles.", true,
() -> config.reduceSmokeParticles, value -> config.reduceSmokeParticles = value))
.option(booleanOption("Other particles", "Hide particle types not covered by the other particle settings.", false,
() -> config.reduceOtherParticles, value -> config.reduceOtherParticles = value))
.build())
.category(ConfigCategory.createBuilder()
.name(Text.literal("First Person"))
.option(booleanOption("Smaller swords and axes", "Reduce the first-person size of swords and axes.", true,
() -> config.shrinkWeapons, value -> config.shrinkWeapons = value))
.option(floatOption("Weapon size", "Scale used for first-person swords and axes.", 0.82F, 0.5F, 1.0F,
() -> config.weaponScale, value -> config.weaponScale = value))
.option(booleanOption("Smaller totem", "Reduce the first-person size of the Totem of Undying.", true,
() -> config.shrinkTotem, value -> config.shrinkTotem = value))
.option(floatOption("Totem size", "Scale used for the first-person Totem of Undying.", 0.75F, 0.5F, 1.0F,
() -> config.totemScale, value -> config.totemScale = value))
.option(booleanOption("Hide offhand shield", "Hide only the offhand shield model; the shield remains usable.", true,
() -> config.hideOffhandShield, value -> config.hideOffhandShield = value))
.option(booleanOption("Smaller fire overlay", "Shrink the first-person fire overlay while keeping it visible.", true,
() -> config.shrinkFireOverlay, value -> config.shrinkFireOverlay = value))
.option(floatOption("Fire overlay size", "Scale used for the first-person fire overlay.", 0.45F, 0.1F, 1.0F,
() -> config.fireScale, value -> config.fireScale = value))
.option(booleanOption("Reduce hand-swing animation", "Reduce the displayed swing animation only; it does not change attack timing or reach.", false,
() -> config.reduceHandSwingAnimation, value -> config.reduceHandSwingAnimation = value))
.build())
.build()
.generateScreen(parent);
}
private static Option<Boolean> booleanOption(String name, String description, boolean defaultValue,
Supplier<Boolean> getter, Consumer<Boolean> setter) {
return Option.<Boolean>createBuilder()
.name(Text.literal(name))
.description(OptionDescription.of(Text.literal(description)))
.binding(defaultValue, getter, value -> {
setter.accept(value);
save();
})
.controller(TickBoxControllerBuilder::create)
.build();
}
private static Option<Float> floatOption(String name, String description, float defaultValue, float minimum, float maximum,
Supplier<Float> getter, Consumer<Float> setter) {
return Option.<Float>createBuilder()
.name(Text.literal(name))
.description(OptionDescription.of(Text.literal(description)))
.binding(defaultValue, getter, value -> {
setter.accept(value);
save();
})
.controller(option -> FloatSliderControllerBuilder.create(option)
.range(minimum, maximum)
.step(0.05F))
.build();
}
private static FpsConfig loadFromDisk() {
FpsConfig config = new FpsConfig();
if (!Files.exists(CONFIG_PATH)) {
return config;
}
Properties properties = new Properties();
try (Reader reader = Files.newBufferedReader(CONFIG_PATH)) {
properties.load(reader);
} catch (IOException exception) {
System.err.println("Could not read FPS PvP configuration: " + exception.getMessage());
return config;
}
config.reducePotionParticles = readBoolean(properties, "reducePotionParticles", config.reducePotionParticles);
config.reduceCriticalParticles = readBoolean(properties, "reduceCriticalParticles", config.reduceCriticalParticles);
config.reduceExplosionParticles = readBoolean(properties, "reduceExplosionParticles", config.reduceExplosionParticles);
config.reduceSmokeParticles = readBoolean(properties, "reduceSmokeParticles", config.reduceSmokeParticles);
config.reduceOtherParticles = readBoolean(properties, "reduceOtherParticles", config.reduceOtherParticles);
config.shrinkWeapons = readBoolean(properties, "shrinkWeapons", config.shrinkWeapons);
config.weaponScale = readFloat(properties, "weaponScale", config.weaponScale, 0.5F, 1.0F);
config.shrinkTotem = readBoolean(properties, "shrinkTotem", config.shrinkTotem);
config.totemScale = readFloat(properties, "totemScale", config.totemScale, 0.5F, 1.0F);
config.hideOffhandShield = readBoolean(properties, "hideOffhandShield", config.hideOffhandShield);
config.shrinkFireOverlay = readBoolean(properties, "shrinkFireOverlay", config.shrinkFireOverlay);
config.fireScale = readFloat(properties, "fireScale", config.fireScale, 0.1F, 1.0F);
config.reduceHandSwingAnimation = readBoolean(properties, "reduceHandSwingAnimation", config.reduceHandSwingAnimation);
return config;
}
private static boolean readBoolean(Properties properties, String key, boolean fallback) {
String value = properties.getProperty(key);
return value == null ? fallback : Boolean.parseBoolean(value);
}
private static float readFloat(Properties properties, String key, float fallback, float minimum, float maximum) {
try {
return Math.max(minimum, Math.min(maximum, Float.parseFloat(properties.getProperty(key, Float.toString(fallback)))));
} catch (NumberFormatException exception) {
return fallback;
}
}
private static void save() {
Properties properties = new Properties();
properties.setProperty("reducePotionParticles", Boolean.toString(INSTANCE.reducePotionParticles));
properties.setProperty("reduceCriticalParticles", Boolean.toString(INSTANCE.reduceCriticalParticles));
properties.setProperty("reduceExplosionParticles", Boolean.toString(INSTANCE.reduceExplosionParticles));
properties.setProperty("reduceSmokeParticles", Boolean.toString(INSTANCE.reduceSmokeParticles));
properties.setProperty("reduceOtherParticles", Boolean.toString(INSTANCE.reduceOtherParticles));
properties.setProperty("shrinkWeapons", Boolean.toString(INSTANCE.shrinkWeapons));
properties.setProperty("weaponScale", Float.toString(INSTANCE.weaponScale));
properties.setProperty("shrinkTotem", Boolean.toString(INSTANCE.shrinkTotem));
properties.setProperty("totemScale", Float.toString(INSTANCE.totemScale));
properties.setProperty("hideOffhandShield", Boolean.toString(INSTANCE.hideOffhandShield));
properties.setProperty("shrinkFireOverlay", Boolean.toString(INSTANCE.shrinkFireOverlay));
properties.setProperty("fireScale", Float.toString(INSTANCE.fireScale));
properties.setProperty("reduceHandSwingAnimation", Boolean.toString(INSTANCE.reduceHandSwingAnimation));
try {
Files.createDirectories(CONFIG_PATH.getParent());
try (Writer writer = Files.newBufferedWriter(CONFIG_PATH)) {
properties.store(writer, "FPS PvP Optimizer settings");
}
} catch (IOException exception) {
System.err.println("Could not save FPS PvP configuration: " + exception.getMessage());
}
}
}