Skip to content

Commit 4ef4bf8

Browse files
committed
fix: fallback to a vanilla item icon for generated input binding on NeoForge
1 parent 7e2f521 commit 4ef4bf8

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/main/java/dev/isxander/controlify/bindings/ControlifyBindings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public static void registerModdedBindings() {
409409
.name(Component.translatable(keyMapping.getName()))
410410
.description(Component.translatable("controlify.custom_binding.vanilla_description").withStyle(ChatFormatting.GRAY))
411411
.category(/*? if >=1.21.9 {*/ keyMapping.getCategory().label() /*?} else {*/ /*Component.translatable(keyMapping.getCategory()) *//*?}*/)
412-
.radialCandidate(RadialIcons.FABRIC_ICON)
412+
.radialCandidate(RadialIcons.getModLoaderIcon())
413413
.allowedContexts(BindContext.IN_GAME)
414414
.keyEmulation(keyMapping));
415415

src/main/java/dev/isxander/controlify/bindings/RadialIcons.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package dev.isxander.controlify.bindings;
22

33
import dev.isxander.controlify.api.bind.RadialIcon;
4-
import dev.isxander.controlify.utils.render.Blit;
54
import dev.isxander.controlify.utils.CUtil;
5+
import dev.isxander.controlify.utils.render.Blit;
66
import dev.isxander.controlify.utils.render.CGuiPose;
77
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
88
import net.minecraft.client.Minecraft;
99
import net.minecraft.client.gui.Gui;
10-
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
1110
import net.minecraft.core.Holder;
1211
import net.minecraft.core.registries.BuiltInRegistries;
1312
import net.minecraft.resources.ResourceKey;
1413
import net.minecraft.resources.ResourceLocation;
1514
import net.minecraft.world.effect.MobEffect;
1615
import net.minecraft.world.item.Item;
1716
import net.minecraft.world.item.ItemStack;
17+
import org.jetbrains.annotations.NotNull;
1818

1919
import java.util.ArrayDeque;
2020
import java.util.Map;
@@ -24,7 +24,13 @@ public final class RadialIcons {
2424
private static final Minecraft minecraft = Minecraft.getInstance();
2525

2626
public static final ResourceLocation EMPTY = CUtil.rl("empty");
27-
public static final ResourceLocation FABRIC_ICON = ResourceLocation.fromNamespaceAndPath("fabric-resource-loader-v0", "icon.png");
27+
private static final ResourceLocation _FABRIC_ICON = ResourceLocation.fromNamespaceAndPath("fabric-resource-loader-v0", "icon.png");
28+
/**
29+
* @deprecated This icon is not available on NeoForge.
30+
* Use {@link RadialIcons#getModLoaderIcon()} instead.
31+
*/
32+
@Deprecated(forRemoval = true)
33+
public static final ResourceLocation FABRIC_ICON = _FABRIC_ICON;
2834

2935
private static Map<ResourceLocation, RadialIcon> icons = null;
3036
private static Queue<Runnable> deferredRegistrations = new ArrayDeque<>();
@@ -101,18 +107,27 @@ private static void addPotionEffects(Map<ResourceLocation, RadialIcon> map) {
101107

102108
private static Map<ResourceLocation, RadialIcon> registerIcons() {
103109
Map<ResourceLocation, RadialIcon> map = new Object2ObjectOpenHashMap<>();
110+
final ResourceLocation modLoaderIcon = getModLoaderIcon();
104111

105112
map.put(EMPTY, (graphics, x, y, tickDelta) -> {});
106-
map.put(FABRIC_ICON, (graphics, x, y, tickDelta) -> {
113+
map.put(modLoaderIcon, (graphics, x, y, tickDelta) -> {
107114
var pose = CGuiPose.ofPush(graphics);
108115
pose.translate(x, y);
109116
pose.scale(0.5f, 0.5f);
110-
Blit.tex(graphics, FABRIC_ICON, 0, 0, 0, 0, 32, 32, 32, 32);
117+
Blit.tex(graphics, modLoaderIcon, 0, 0, 0, 0, 32, 32, 32, 32);
111118
pose.pop();
112119
});
113120
addItems(map);
114121
addPotionEffects(map);
115122

116123
return map;
117124
}
125+
126+
public static @NotNull ResourceLocation getModLoaderIcon() {
127+
//? if fabric {
128+
return _FABRIC_ICON;
129+
//?} else {
130+
/*return getItem(net.minecraft.world.item.Items.BOOK);
131+
*///?}
132+
}
118133
}

0 commit comments

Comments
 (0)