|
6 | 6 | import java.util.regex.Pattern; |
7 | 7 |
|
8 | 8 | public class NeoForgeClientCommandSourceStackBuildContext extends ClientCommandSourceStackBuildContext { |
9 | | - /** |
10 | | - * A regex pattern for parsing NeoForge version strings. |
11 | | - */ |
12 | | - private static final Pattern NEOFORGE_VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(?:-beta)?"); |
13 | | - /** |
14 | | - * Are click events with client commands supported in this version? |
15 | | - */ |
16 | | - private boolean supportsClickEvents = false; |
17 | 9 |
|
18 | 10 | /** |
19 | 11 | * Constructs a new build context for client commands on NeoForge. |
20 | 12 | */ |
21 | 13 | public NeoForgeClientCommandSourceStackBuildContext() { |
22 | | - try { |
23 | | - if (isMinVersion(new int[]{21, 4, 5})) { |
24 | | - supportsClickEvents = true; |
25 | | - } |
26 | | - } catch (Exception e) { |
27 | | - Constants.LOG.error("Failed to parse NeoForge version", e); |
28 | | - } |
29 | 14 | } |
30 | 15 |
|
31 | 16 | @Override |
32 | 17 | public boolean supportsClientCommandClickEvents() { |
33 | | - return supportsClickEvents; |
34 | | - } |
35 | | - |
36 | | - /** |
37 | | - * Is a minimum version of NeoForge installed? |
38 | | - * @param minVersions The minimum version to check for. (Minecraft minor version, Minecraft patch version, NeoForge patch version) |
39 | | - * @return True if the minimum version is installed, false otherwise. |
40 | | - */ |
41 | | - protected boolean isMinVersion(int[] minVersions) { |
42 | | - var version = FMLLoader.versionInfo().neoForgeVersion(); |
43 | | - var matcher = NEOFORGE_VERSION_PATTERN.matcher(version); |
44 | | - |
45 | | - if (!matcher.matches()) { |
46 | | - throw new IllegalStateException("Failed to parse NeoForge version: " + version); |
47 | | - } |
48 | | - |
49 | | - if (matcher.groupCount() != minVersions.length) { |
50 | | - throw new IllegalStateException("Expected match group count : " + version); |
51 | | - } |
52 | | - |
53 | | - for (int i = 0; i < minVersions.length; i++) { |
54 | | - var minVersion = minVersions[i]; |
55 | | - var foundVersion = Integer.parseInt(matcher.group(i + 1)); |
56 | | - if (foundVersion > minVersion) { |
57 | | - return true; |
58 | | - } else if (foundVersion < minVersion) { |
59 | | - return false; |
60 | | - } |
61 | | - } |
62 | 18 | return true; |
63 | 19 | } |
64 | 20 | } |
0 commit comments