-
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.
- Loading branch information
1 parent
97d1254
commit 812a400
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/java/net/zepalesque/zenith/config/ZConfigIcons.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,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<ModConfigSpec.ConfigValue<?>, ResourceLocation> ICONS = new HashMap<>(); | ||
private static boolean frozen = false; | ||
|
||
public static <T> ModConfigSpec.ConfigValue<T> register(ModConfigSpec.ConfigValue<T> value, ResourceLocation iconLoc) { | ||
ICONS.put(value, iconLoc); | ||
return value; | ||
} | ||
|
||
public static Map<ModConfigSpec.ConfigValue<?>, ResourceLocation> freeze() { | ||
if (frozen) { | ||
Zenith.LOGGER.warn("Attempted to freeze config icon map, but it has already been frozen!"); | ||
return ICONS; | ||
} else { | ||
ImmutableMap<ModConfigSpec.ConfigValue<?>, ResourceLocation> immutable = ImmutableMap.copyOf(ICONS); | ||
Map<ModConfigSpec.ConfigValue<?>, ResourceLocation> old = ICONS; | ||
ICONS = immutable; | ||
old.clear(); | ||
frozen = true; | ||
return immutable; | ||
} | ||
} | ||
|
||
@Nullable | ||
public static ResourceLocation iconFor(ModConfigSpec.ConfigValue<?> value) { | ||
return ICONS.get(value); | ||
} | ||
} |