blob: d4e6a0dff41ebfc1dd15ed3dab455603066bd08f (
plain)
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
|
package de.hysky.skyblocker.skyblock.item;
import de.hysky.skyblocker.skyblock.itemlist.ItemRegistry;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import org.lwjgl.glfw.GLFW;
import java.util.concurrent.CompletableFuture;
public class WikiLookup {
public static KeyBinding wikiLookup;
static final MinecraftClient client = MinecraftClient.getInstance();
static String id;
public static void init() {
wikiLookup = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.wikiLookup",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_F4,
"key.categories.skyblocker"
));
}
public static String getSkyblockId(Slot slot) {
//Grabbing the skyblock NBT data
ItemUtils.getItemIdOptional(slot.getStack()).ifPresent(newId -> id = newId);
return id;
}
public static void openWiki(Slot slot) {
if (Utils.isOnSkyblock()) {
id = getSkyblockId(slot);
try {
String wikiLink = ItemRegistry.getWikiLink(id);
CompletableFuture.runAsync(() -> Util.getOperatingSystem().open(wikiLink));
} catch (IndexOutOfBoundsException | IllegalStateException e) {
e.printStackTrace();
if (client.player != null)
client.player.sendMessage(Text.of("Error while retrieving wiki article..."), false);
}
}
}
}
|