From 812a400259eb0a086365b2d314f08b81024f7bf8 Mon Sep 17 00:00:00 2001 From: Zepalesque <60141811+Zepalesque@users.noreply.github.com> Date: Thu, 26 Sep 2024 19:01:56 -0400 Subject: [PATCH] feat: testing --- .../zenith/config/ZConfigIcons.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/net/zepalesque/zenith/config/ZConfigIcons.java 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); + } +}