Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do a better job of getting an item's mod name
- Loading branch information
Showing
8 changed files
with
108 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
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,35 @@ | ||
package mezz.jei; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.EnumChatFormatting; | ||
|
||
import net.minecraftforge.event.entity.player.ItemTooltipEvent; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
|
||
import mezz.jei.api.JEIManager; | ||
import mezz.jei.config.Config; | ||
|
||
public class TooltipEventHandler { | ||
@SubscribeEvent | ||
public void onToolTip(@Nonnull ItemTooltipEvent event) { | ||
if (!Config.tooltipModNameEnabled) { | ||
return; | ||
} | ||
|
||
ItemStack itemStack = event.itemStack; | ||
if (itemStack == null) { | ||
return; | ||
} | ||
|
||
Item item = itemStack.getItem(); | ||
if (item == null) { | ||
return; | ||
} | ||
|
||
String modName = JEIManager.itemRegistry.getModNameForItem(item); | ||
event.toolTip.add(EnumChatFormatting.BLUE + modName); | ||
} | ||
} |
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
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
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
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,38 @@ | ||
package mezz.jei.util; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.lang3.text.WordUtils; | ||
|
||
import net.minecraft.item.Item; | ||
|
||
import net.minecraftforge.fml.common.Loader; | ||
import net.minecraftforge.fml.common.ModContainer; | ||
import net.minecraftforge.fml.common.registry.GameRegistry; | ||
|
||
public class ModList { | ||
|
||
private final Map<String, String> modNamesForIds = new HashMap<>(); | ||
|
||
public ModList() { | ||
Map<String,ModContainer> modMap = Loader.instance().getIndexedModList(); | ||
for (Map.Entry<String, ModContainer> modEntry : modMap.entrySet()) { | ||
String lowercaseId = modEntry.getKey().toLowerCase(Locale.ENGLISH); | ||
String modName = modEntry.getValue().getName(); | ||
modNamesForIds.put(lowercaseId, modName); | ||
} | ||
} | ||
|
||
@Nonnull | ||
public String getModNameForItemStack(@Nonnull Item item) { | ||
String modId = GameRegistry.findUniqueIdentifierFor(item).modId; | ||
String modName = modNamesForIds.get(modId.toLowerCase(Locale.ENGLISH)); | ||
if (modName == null) { | ||
modName = WordUtils.capitalize(modId); | ||
} | ||
return modName; | ||
} | ||
} |