aboutsummaryrefslogtreecommitdiff
path: root/forge/src/main
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-07-31 22:45:17 +0800
committershedaniel <daniel@shedaniel.me>2022-07-31 22:45:17 +0800
commit0b4e0878df5d670c49567d5fb90d6cfbdaa05bad (patch)
treede96df0be757717cf6a5003fbb92de198301c856 /forge/src/main
parenta4ae82d568c029d8c0034a6a8802e61ae6521ae8 (diff)
downloadRoughlyEnoughItems-0b4e0878df5d670c49567d5fb90d6cfbdaa05bad.tar.gz
RoughlyEnoughItems-0b4e0878df5d670c49567d5fb90d6cfbdaa05bad.tar.bz2
RoughlyEnoughItems-0b4e0878df5d670c49567d5fb90d6cfbdaa05bad.zip
Support 1.19.1, Fix #1041
Diffstat (limited to 'forge/src/main')
-rw-r--r--forge/src/main/java/me/shedaniel/rei/impl/client/forge/CommandSenderImpl.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CommandSenderImpl.java b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CommandSenderImpl.java
new file mode 100644
index 000000000..83253fc9c
--- /dev/null
+++ b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CommandSenderImpl.java
@@ -0,0 +1,60 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.forge;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.player.LocalPlayer;
+import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class CommandSenderImpl {
+ public static void sendCommand(String command) {
+ LocalPlayer player = Minecraft.getInstance().player;
+ if (player == null) return;
+ Method method = null;
+ try {
+ // 1.19
+ method = ObfuscationReflectionHelper.findMethod(LocalPlayer.class, "m_234156_", String.class);
+ } catch (ObfuscationReflectionHelper.UnableToFindMethodException ignored) {
+ }
+ if (method == null) {
+ try {
+ // 1.19.1
+ method = ObfuscationReflectionHelper.findMethod(LocalPlayer.class, "m_242614_", String.class);
+ } catch (ObfuscationReflectionHelper.UnableToFindMethodException ignored) {
+ }
+ }
+ if (method == null) {
+ throw new RuntimeException("Unable to find method");
+ }
+
+ try {
+ method.invoke(player, command);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}