-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathRadialIcons.java
More file actions
127 lines (106 loc) · 4.35 KB
/
Copy pathRadialIcons.java
File metadata and controls
127 lines (106 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package dev.isxander.controlify.bindings;
import dev.isxander.controlify.api.bind.RadialIcon;
import dev.isxander.controlify.utils.CUtil;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.Identifier;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.Queue;
public final class RadialIcons {
private static final Minecraft minecraft = Minecraft.getInstance();
public static final Identifier EMPTY = CUtil.rl("empty");
private static final Identifier FABRIC_ICON = Identifier.fromNamespaceAndPath("fabric-resource-loader-v0", "icon.png");
private static Map<Identifier, RadialIcon> icons = null;
private static Queue<Runnable> deferredRegistrations = new ArrayDeque<>();
public static Map<Identifier, RadialIcon> getIcons() {
if (icons == null) {
icons = registerIcons();
deferredRegistrations.forEach(Runnable::run);
deferredRegistrations = null;
}
return icons;
}
public static void registerIcon(Identifier location, RadialIcon icon) {
if (icons == null) {
deferredRegistrations.add(() -> registerIcon(location, icon));
return;
}
icons.put(location, icon);
}
public static Identifier getItem(Item item) {
return BuiltInRegistries.ITEM.getKey(item).withPrefix("item/");
}
public static Identifier getEffect(Holder<MobEffect> effect) {
return BuiltInRegistries.MOB_EFFECT.getKey(effect.value()).withPrefix("effect/");
}
private static void addItems(Map<Identifier, RadialIcon> map) {
BuiltInRegistries.ITEM.entrySet().forEach(entry -> {
ResourceKey<Item> key = entry.getKey();
ItemStack stack = entry.getValue().getDefaultInstance();
map.put(key.identifier().withPrefix("item/"), (graphics, x, y, a) -> {
graphics.item(stack, x, y);
});
});
}
private static void addPotionEffects(Map<Identifier, RadialIcon> map) {
BuiltInRegistries.MOB_EFFECT.entrySet().forEach(entry -> {
ResourceKey<MobEffect> key = entry.getKey();
Holder<MobEffect> effect = BuiltInRegistries.MOB_EFFECT.wrapAsHolder(entry.getValue());
//? if >=26.2 {
Identifier sprite = net.minecraft.client.gui.Hud.getMobEffectSprite(effect);
//?} else {
/*Identifier sprite = net.minecraft.client.gui.Gui.getMobEffectSprite(effect);
*///?}
map.put(key.identifier().withPrefix("effect/"), (graphics, x, y, a) -> {
var pose = graphics.pose().pushMatrix();
pose.translate(x, y);
pose.scale(0.88f, 0.88f);
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED,
sprite,
0, 0,
18, 18
);
pose.popMatrix();
});
});
}
private static Map<Identifier, RadialIcon> registerIcons() {
Map<Identifier, RadialIcon> map = new Object2ObjectOpenHashMap<>();
final Identifier modLoaderIcon = getModLoaderIcon();
map.put(EMPTY, (graphics, x, y, tickDelta) -> {});
map.put(modLoaderIcon, (graphics, x, y, tickDelta) -> {
var pose = graphics.pose().pushMatrix();
pose.translate(x, y);
pose.scale(0.5f, 0.5f);
graphics.blit(
RenderPipelines.GUI_TEXTURED,
modLoaderIcon,
0, 0,
0, 0,
32, 32,
32, 32
);
pose.popMatrix();
});
addItems(map);
addPotionEffects(map);
return map;
}
public static @NotNull Identifier getModLoaderIcon() {
//? if fabric {
return FABRIC_ICON;
//?} else {
/*return getItem(net.minecraft.world.item.Items.BOOK);
*///?}
}
}