From 4dfba61426c75316a6a576d74e589bb0857c9b36 Mon Sep 17 00:00:00 2001 From: C-H716 <1536152356@qq.com> Date: Mon, 20 Oct 2025 23:29:14 +0800 Subject: [PATCH] =?UTF-8?q?guideme=E9=AB=98=E7=89=88=E6=9C=AC=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E7=A7=BB=E6=A4=8Dmixin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mixin/guideme/ItemLinkCompilerMixin.java | 89 +++++++++++++++++++ .../mixin/guideme/MdxAttrsMixin.java | 61 +++++++++++++ .../resources/extendedae_plus.mixins.json | 4 +- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/extendedae_plus/mixin/guideme/ItemLinkCompilerMixin.java create mode 100644 src/main/java/com/extendedae_plus/mixin/guideme/MdxAttrsMixin.java diff --git a/src/main/java/com/extendedae_plus/mixin/guideme/ItemLinkCompilerMixin.java b/src/main/java/com/extendedae_plus/mixin/guideme/ItemLinkCompilerMixin.java new file mode 100644 index 0000000..3fae21f --- /dev/null +++ b/src/main/java/com/extendedae_plus/mixin/guideme/ItemLinkCompilerMixin.java @@ -0,0 +1,89 @@ +package com.extendedae_plus.mixin.guideme; + +import guideme.compiler.PageCompiler; +import guideme.compiler.tags.ItemLinkCompiler; +import guideme.compiler.tags.MdxAttrs; +import guideme.document.LytErrorSink; +import guideme.document.flow.LytFlowLink; +import guideme.document.flow.LytFlowParent; +import guideme.document.flow.LytTooltipSpan; +import guideme.document.interaction.ItemTooltip; +import guideme.indices.ItemIndex; +import guideme.libs.mdast.mdx.model.MdxJsxElementFields; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import org.apache.commons.lang3.tuple.Pair; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static guideme.compiler.tags.MdxAttrs.getRequiredItemAndId; + +/** + * This class contains code back-ported from GuideMe version 20.1.14. + *
+ * Original Copyright (c) Gimpansor and the GuideMe contributors. + * Original source: GuideME + *
+ * This back-ported code is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0) + * as per the terms of the original work. + *
+ * Modifications (if any) are made solely for the purpose of compatibility with earlier versions
+ * and are also licensed under LGPL-3.0.
+ */
+@Mixin(value = ItemLinkCompiler.class, remap = false)
+public abstract class ItemLinkCompilerMixin {
+ @Inject(method = "compile", at = @At("HEAD"), cancellable = true)
+ private void onCompile(PageCompiler compiler, LytFlowParent parent, MdxJsxElementFields el, CallbackInfo ci) {
+ System.out.println("加载guideme.compiler.tags.ItemLinkCompilerMixin.onCompile");
+ var itemAndId = this.getRequiredItemStackAndId(compiler, parent, el);
+ if (itemAndId == null) {
+ ci.cancel();
+ return;
+ }
+
+ var id = itemAndId.getLeft();
+ var stack = itemAndId.getRight();
+ var linksTo = compiler.getIndex(ItemIndex.class).get(id);
+
+ if (linksTo == null && id.getNamespace().equals(compiler.getPageId().getNamespace())) {
+ parent.append(compiler.createErrorFlowContent("No page found for item " + id, el));
+ ci.cancel();
+ return;
+ }
+
+ if (linksTo == null || (linksTo.anchor() == null && compiler.getPageId().equals(linksTo.pageId()))) {
+ var span = new LytTooltipSpan();
+ span.modifyStyle(style -> style.italic(true));
+ span.appendComponent(stack.getHoverName());
+ span.setTooltip(new ItemTooltip(stack));
+ parent.append(span);
+ } else {
+ var link = new LytFlowLink();
+ link.setClickCallback(screen -> screen.navigateTo(linksTo));
+ link.appendComponent(stack.getHoverName());
+ link.setTooltip(new ItemTooltip(stack));
+ parent.append(link);
+ }
+
+ ci.cancel(); // 阻止原逻辑执行
+ }
+
+ @Unique
+ public Pair
+ * Original Copyright (c) Gimpansor and the GuideMe contributors.
+ * Original source: GuideME
+ *
+ * This back-ported code is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0)
+ * as per the terms of the original work.
+ *
+ * Modifications (if any) are made solely for the purpose of compatibility with earlier versions
+ * and are also licensed under LGPL-3.0.
+ */
+@Mixin(value = MdxAttrs.class, remap = false)
+public abstract class MdxAttrsMixin {
+
+ @Inject(method = "getRequiredItemStack", at = @At("HEAD"), cancellable = true)
+ private static void onGetRequiredItemStack(PageCompiler compiler, LytErrorSink errorSink, MdxJsxElementFields el, CallbackInfoReturnable