From 47d3ed39ff78df96c43db83aa1d55fbd5b4ee948 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Dec 2024 19:48:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=93=81=E7=A0=A7=E9=94=A4?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../screen/inventory/AnvilHammerScreen.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AnvilHammerScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AnvilHammerScreen.java index 8319c41bb..87b0ebfd7 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AnvilHammerScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AnvilHammerScreen.java @@ -8,6 +8,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; +import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.hammer.IHasHammerEffect; import dev.dubhe.anvilcraft.api.input.IMouseHandlerExtension; import dev.dubhe.anvilcraft.client.init.ModRenderTypes; @@ -31,7 +32,9 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Objects; @ParametersAreNonnullByDefault public class AnvilHammerScreen extends Screen implements IHasHammerEffect { @@ -41,7 +44,11 @@ public class AnvilHammerScreen extends Screen implements IHasHammerEffect { public static final int CLOSING_ANIMATION_T = 150; //ms public static final float ZOOM = 13.5f; public static final int IGNORE_CURSOR_MOVE_LENGTH = 15; - + private static final String[] ALL_GETNAME_METHODS = { + "getName", + "method_11901", + "m_6940_" + }; private static final MethodHandle PROPERTY_TOSTRING; private static final int RING_COLOR = 0x88000000; @@ -59,16 +66,21 @@ public class AnvilHammerScreen extends Screen implements IHasHammerEffect { String.class, Comparable.class ); - try { - PROPERTY_TOSTRING = MethodHandles.lookup() - .findVirtual( - Property.class, - "getName", - mt - ); - } catch (NoSuchMethodException | IllegalAccessException e) { - throw new RuntimeException(e); - } + PROPERTY_TOSTRING = Arrays.stream(ALL_GETNAME_METHODS) + .map(it -> { + try { + return MethodHandles.lookup() + .findVirtual( + Property.class, + it, + mt + ); + } catch (Exception e) { + return null; + } + }).filter(Objects::nonNull) + .findFirst() + .orElseThrow(); } private final Minecraft minecraft = Minecraft.getInstance();