diff --git a/src/main/java/net/zepalesque/zenith/config/ZConfigIcons.java b/src/main/java/net/zepalesque/zenith/config/ZConfigIcons.java new file mode 100644 index 0000000..bdc1d35 --- /dev/null +++ b/src/main/java/net/zepalesque/zenith/config/ZConfigIcons.java @@ -0,0 +1,41 @@ +package net.zepalesque.zenith.config; + +import com.google.common.collect.ImmutableMap; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.fml.loading.FMLConfig; +import net.neoforged.neoforge.common.ModConfigSpec; +import net.zepalesque.zenith.Zenith; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +public class ZConfigIcons { + + private static Map, ResourceLocation> ICONS = new HashMap<>(); + private static boolean frozen = false; + + public static ModConfigSpec.ConfigValue register(ModConfigSpec.ConfigValue value, ResourceLocation iconLoc) { + ICONS.put(value, iconLoc); + return value; + } + + public static Map, ResourceLocation> freeze() { + if (frozen) { + Zenith.LOGGER.warn("Attempted to freeze config icon map, but it has already been frozen!"); + return ICONS; + } else { + ImmutableMap, ResourceLocation> immutable = ImmutableMap.copyOf(ICONS); + Map, ResourceLocation> old = ICONS; + ICONS = immutable; + old.clear(); + frozen = true; + return immutable; + } + } + + @Nullable + public static ResourceLocation iconFor(ModConfigSpec.ConfigValue value) { + return ICONS.get(value); + } +}