diff --git a/src/main/java/dev/micle/totemofreviving/config/Config.java b/src/main/java/dev/micle/totemofreviving/config/Config.java index d1fbb38..9348169 100644 --- a/src/main/java/dev/micle/totemofreviving/config/Config.java +++ b/src/main/java/dev/micle/totemofreviving/config/Config.java @@ -1,42 +1,21 @@ package dev.micle.totemofreviving.config; +import dev.micle.totemofreviving.item.StrawTotemItem; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.config.ModConfig; -import java.util.HashMap; - public final class Config { public static void init() { - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Common.spec); - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Client.spec); - ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Server.spec); + ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Server.SPEC); } - public static final class Common { - static ForgeConfigSpec spec = null; + public static final class Server { + private static final ForgeConfigSpec SPEC; - Common() { - ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); - spec = builder.build(); - } - } - - public static final class Client { - static ForgeConfigSpec spec = null; + private static final TotemConfig STRAW_TOTEM_CONFIG; - Client() { - ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); - spec = builder.build(); - } - } - - public final class Server { - static ForgeConfigSpec spec; - - public static final HashMap TOTEM_CONFIGS = new HashMap<>(); - - Server() { + static { ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); /* Straw Totem @@ -53,53 +32,57 @@ public final class Config { Glowstone Totem Netherite Totem */ - TOTEM_CONFIGS.put("Straw Totem", new TotemConfig("Straw Totem", builder, - true, -1, 3, 1, false, 3)); - TOTEM_CONFIGS.put("Iron Totem", new TotemConfig("Iron Totem", builder, - true, -1, 6, 0.75, false, 10)); - TOTEM_CONFIGS.put("Diamond Totem", new TotemConfig("Diamond Totem", builder, - true, -1, 0, 0.5, false, 50)); - - spec = builder.build(); + STRAW_TOTEM_CONFIG = new TotemConfig(builder, StrawTotemItem.getName(), + true, -1, 3, 1, false, 3); + + SPEC = builder.build(); } - public class TotemConfig { - public final String NAME; - public final ForgeConfigSpec.BooleanValue IS_ENABLED; - public final ForgeConfigSpec.IntValue CHARGE_COST; - public final ForgeConfigSpec.IntValue CHARGE_COST_LIMIT; - public final ForgeConfigSpec.DoubleValue CHARGE_COST_MULTIPLIER; - public final ForgeConfigSpec.BooleanValue CAN_REVIVE_MORE_EXPENSIVE_TARGETS; - public final ForgeConfigSpec.IntValue DURABILITY; - - TotemConfig(String totemName, ForgeConfigSpec.Builder builder, boolean isEnabled, int chargeCost, int chargeCostLimit, - double chargeCostMultiplier, boolean canReviveMoreExpensiveTargets, int durability) { - NAME = totemName; - builder.push(NAME); - IS_ENABLED = builder - .comment("Is the " + NAME + " enabled?") - .define("isEnabled", isEnabled); - CHARGE_COST = builder - .comment("The charge cost to revive a player.\n" + - "-1 means the cost is dynamic (follows the amount of deaths the target has)\n" + - "Higher values set the charge cost to static, meaning that this will be the amount of charges needed to revive someone.") - .defineInRange("chargeCost", chargeCost, -1, Integer.MAX_VALUE); - CHARGE_COST_LIMIT = builder - .comment("The max amount of charge this totem can hold at once.\n" + - "0 means unlimited. Only works with dynamic cost.") - .defineInRange("chargeCostLimit", chargeCostLimit, 0, Integer.MAX_VALUE); - CHARGE_COST_MULTIPLIER = builder - .comment("Charge cost multiplier. 0.5 means the charge cost will be 50% of the original cost. Only works with dynamic cost.") - .defineInRange("chargeCostMultiplier", chargeCostMultiplier, 0.01, Integer.MAX_VALUE); - CAN_REVIVE_MORE_EXPENSIVE_TARGETS = builder - .comment("Is the totem able to revive targets that cost more than the totems max charge?\n" + - "This only applies if the totem is fully charged. (dynamic wont work if limit is 0)") - .define("canReviveMoreExpensiveTargets", canReviveMoreExpensiveTargets); - DURABILITY = builder - .comment("The durability of the totem. 0 means unbreakable.") - .defineInRange("durability", durability, 0, Integer.MAX_VALUE); - builder.pop(); - } + public static TotemConfig getStrawTotemConfig() { return STRAW_TOTEM_CONFIG; } + } + + public static class TotemConfig { + private final ForgeConfigSpec.BooleanValue IS_ENABLED; + private final ForgeConfigSpec.IntValue CHARGE_COST; + private final ForgeConfigSpec.IntValue CHARGE_COST_LIMIT; + private final ForgeConfigSpec.DoubleValue CHARGE_COST_MULTIPLIER; + private final ForgeConfigSpec.BooleanValue CAN_REVIVE_MORE_EXPENSIVE_TARGETS; + private final ForgeConfigSpec.IntValue DURABILITY; + + TotemConfig(ForgeConfigSpec.Builder builder, String name, boolean isEnabled, int chargeCost, + int chargeCostLimit, double chargeCostMultiplier, boolean canReviveMoreExpensiveTargets, + int durability) { + builder.push(name); + IS_ENABLED = builder + .comment("Is the " + name + " enabled?") + .define("isEnabled", isEnabled); + CHARGE_COST = builder + .comment("The charge cost to revive a player.\n" + + "-1 means the cost is dynamic (follows the amount of deaths the target has)\n" + + "Higher values set the charge cost to static, meaning that this will be the amount of charges needed to revive someone.") + .defineInRange("chargeCost", chargeCost, -1, Integer.MAX_VALUE); + CHARGE_COST_LIMIT = builder + .comment("The max amount of charge this totem can hold at once.\n" + + "0 means unlimited. Only works with dynamic cost.") + .defineInRange("chargeCostLimit", chargeCostLimit, 0, Integer.MAX_VALUE); + CHARGE_COST_MULTIPLIER = builder + .comment("Charge cost multiplier. 0.5 means the charge cost will be 50% of the original cost. Only works with dynamic cost.") + .defineInRange("chargeCostMultiplier", chargeCostMultiplier, 0.01, Integer.MAX_VALUE); + CAN_REVIVE_MORE_EXPENSIVE_TARGETS = builder + .comment("Is the totem able to revive targets that cost more than the totems max charge?\n" + + "This only applies if the totem is fully charged. (dynamic wont work if limit is 0)") + .define("canReviveMoreExpensiveTargets", canReviveMoreExpensiveTargets); + DURABILITY = builder + .comment("The durability of the totem. 0 means unbreakable.") + .defineInRange("durability", durability, 0, Integer.MAX_VALUE); + builder.pop(); } + + public boolean getIsEnabled() { return IS_ENABLED.get(); } + public int getChargeCost() { return CHARGE_COST.get(); } + public int getChargeCostLimit() { return CHARGE_COST_LIMIT.get(); } + public double getChargeCostMultiplier() { return CHARGE_COST_MULTIPLIER.get(); } + public boolean getCanReviveMoreExpensiveTargets() { return CAN_REVIVE_MORE_EXPENSIVE_TARGETS.get(); } + public int getDurability() { return DURABILITY.get(); } } }