equivalent-exchange-3/src/main/java/com/pahimar/ee3/array/AlchemyArrayRegistry.java

67 lines
2.1 KiB
Java
Raw Normal View History

package com.pahimar.ee3.array;
2023-01-03 17:47:36 +01:00
import java.util.SortedSet;
import java.util.TreeSet;
import com.google.common.collect.ImmutableSortedSet;
2015-05-07 19:45:06 +02:00
import com.pahimar.ee3.api.array.AlchemyArray;
import com.pahimar.ee3.util.LoaderHelper;
import com.pahimar.ee3.util.LogHelper;
import cpw.mods.fml.common.Loader;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
2023-01-03 17:47:36 +01:00
public class AlchemyArrayRegistry {
public static final Marker ALCHEMY_ARRAY_MARKER
= MarkerManager.getMarker("EE3_ALCHEMY_ARRAY", LogHelper.MOD_MARKER);
private static AlchemyArrayRegistry alchemyArrayRegistry = null;
private SortedSet<AlchemyArray> registeredAlchemyArrays;
2023-01-03 17:47:36 +01:00
private AlchemyArrayRegistry() {}
2023-01-03 17:47:36 +01:00
public static AlchemyArrayRegistry getInstance() {
if (alchemyArrayRegistry == null) {
alchemyArrayRegistry = new AlchemyArrayRegistry();
alchemyArrayRegistry.init();
}
return alchemyArrayRegistry;
}
2023-01-03 17:47:36 +01:00
private void init() {
registeredAlchemyArrays = new TreeSet<AlchemyArray>();
}
2023-01-03 17:47:36 +01:00
public AlchemyArray getAlchemyArray(int index) {
if (registeredAlchemyArrays != null) {
AlchemyArray[] alchemyArrays = new AlchemyArray[0];
alchemyArrays = registeredAlchemyArrays.toArray(alchemyArrays);
2023-01-03 17:47:36 +01:00
if (index < alchemyArrays.length) {
return alchemyArrays[index];
}
}
return null;
}
2023-01-03 17:47:36 +01:00
public SortedSet<AlchemyArray> getRegisteredAlchemyArrays() {
return ImmutableSortedSet.copyOf(registeredAlchemyArrays);
}
2023-01-03 17:47:36 +01:00
public boolean registerAlchemyArray(AlchemyArray alchemyArray) {
if (!registeredAlchemyArrays.contains(alchemyArray)) {
LogHelper.trace(
ALCHEMY_ARRAY_MARKER,
"[{}]: Mod with ID '{}' added alchemy array {}",
LoaderHelper.getLoaderState(),
Loader.instance().activeModContainer().getModId(),
alchemyArray
);
return registeredAlchemyArrays.add(alchemyArray);
}
return false;
}
}