Skip to content

Commit

Permalink
Fix for mods that use legacy default icon path
Browse files Browse the repository at this point in the history
- Fixed icons for mods that were using the default icon path
  • Loading branch information
Prospector committed Feb 2, 2021
1 parent de62369 commit c8d893c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.terraformersmc.modmenu.util.mod;

import com.terraformersmc.modmenu.ModMenu;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
Expand All @@ -22,6 +24,10 @@ public class ModIconHandler {
public NativeImageBackedTexture createIcon(ModContainer iconSource, String iconPath) {
try {
Path path = iconSource.getPath(iconPath);
if (!Files.exists(path)) {
iconSource = FabricLoader.getInstance().getModContainer(ModMenu.MOD_ID).orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Mod Menu!"));
iconPath = "assets/" + ModMenu.MOD_ID + "/unknown_icon.png";
}
NativeImageBackedTexture cachedIcon = getCachedModIcon(path);
if (cachedIcon != null) {
return cachedIcon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,13 @@ public FabricMod(ModContainer modContainer) {
@Override
public @NotNull NativeImageBackedTexture getIcon(ModIconHandler iconHandler, int i) {
String iconSourceId = getId();
String iconPath = metadata.getIconPath(i).orElse(null);
String iconPath = metadata.getIconPath(i).orElse("assets/" + getId() + "/icon.png");
if ("minecraft".equals(getId())) {
iconSourceId = ModMenu.MOD_ID;
iconPath = "assets/" + ModMenu.MOD_ID + "/minecraft_icon.png";
} else if ("java".equals(getId())) {
iconSourceId = ModMenu.MOD_ID;
iconPath = "assets/" + ModMenu.MOD_ID + "/java_icon.png";
} else if (iconPath == null) {
iconSourceId = ModMenu.MOD_ID;
iconPath = "assets/" + ModMenu.MOD_ID + "/unknown_icon.png";
}
final String finalIconSourceId = iconSourceId;
ModContainer iconSource = FabricLoader.getInstance().getModContainer(iconSourceId).orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Fabric mod with id " + finalIconSourceId));
Expand Down

0 comments on commit c8d893c

Please sign in to comment.