mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 12:59:41 +00:00
* remove direct guava predicates from BlockStateMachine * cleanup blockstatebasic * fix a large number of e.printStacktrace calls, narrow ComputerIntegration exception signature * fix simple todos, remove invalid todos, unify some duplicate rendering code * use a generic method to get around unchecked warning * remove some redundant uses of hasCapability * experimental OptionalCapability class. not in use yet * nullable checks/annotations & remove duplicate field controlType in factory TE * Inline various redundant variables * Remove unused list * Cleanup BlockStateGenerator * Replace string constants with pointers to the proper mod id constant * As 9.7.5 breaks backwards compat API wise for the DynamicNetwork this is as good a time as any to remove this deprecated method * Use two argument constructor instead of appending a ':' inbetween * Convert other BlockState type classes to using suppliers for tile entity creation
43 lines
1.3 KiB
Java
43 lines
1.3 KiB
Java
package mekanism.common.util;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraftforge.fml.common.Loader;
|
|
import net.minecraftforge.fml.common.ModContainer;
|
|
import org.apache.commons.lang3.text.WordUtils;
|
|
|
|
public final class ItemRegistryUtils {
|
|
|
|
private static final Map<String, String> modIDMap = new HashMap<>();
|
|
|
|
private static void populateMap() {
|
|
for (Map.Entry<String, ModContainer> entry : Loader.instance().getIndexedModList().entrySet()) {
|
|
modIDMap.put(entry.getKey().toLowerCase(Locale.ROOT), entry.getValue().getName());
|
|
}
|
|
}
|
|
|
|
/* Mod ID lookup thanks to JEI */
|
|
public static String getMod(ItemStack stack) {
|
|
if (stack.isEmpty()) {
|
|
return "null";
|
|
}
|
|
|
|
if (modIDMap.isEmpty()) {
|
|
populateMap();
|
|
}
|
|
|
|
ResourceLocation itemResourceLocation = Item.REGISTRY.getNameForObject(stack.getItem());
|
|
|
|
if (itemResourceLocation == null) {
|
|
return "null";
|
|
}
|
|
|
|
String modId = itemResourceLocation.getNamespace();
|
|
String lowercaseModId = modId.toLowerCase(Locale.ENGLISH);
|
|
return modIDMap.computeIfAbsent(lowercaseModId, k -> WordUtils.capitalize(modId));
|
|
}
|
|
} |