From ea17e4612de08be8b00a299dc27096cace8d61ce Mon Sep 17 00:00:00 2001
From: theabab2333 <2047477146@qq.com>
Date: Thu, 25 Dec 2025 21:40:31 +0800
Subject: [PATCH 1/2] =?UTF-8?q?feat(compiler):=20=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E6=B8=90=E5=8F=98=E8=89=B2=E6=A0=87=E7=AD=BE=E7=BC=96=E8=AF=91?=
=?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 实现了 GradientColourTagCompiler 类处理渐变色标签
- 在 ColorUtil 中添加 calculateGradientColor 方法计算渐变颜色
- 更新 AnvilCraftGuideME.java 注册新的渐变色标签编译器
- 修改 ModInfoTagCompiler 和 NeoColorTagCompiler 代码优化
- 更新 README.md 和 guidebook/dev.md 文档说明新功能
---
README.md | 14 ++-
gradle/libs.versions.toml | 2 +-
guidebook/dev.md | 11 +-
guidebook/index.md | 2 +-
.../anvilcraft/guideme/AnvilCraftGuideME.java | 2 +
.../tag/GradientColourTagCompiler.java | 101 ++++++++++++++++++
.../compiler/tag/ModInfoTagCompiler.java | 2 +
.../compiler/tag/NeoColorTagCompiler.java | 6 +-
.../guide/compiler/util/ColorUtil.java | 22 ++++
9 files changed, 149 insertions(+), 13 deletions(-)
create mode 100644 src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/GradientColourTagCompiler.java
diff --git a/README.md b/README.md
index 8e86a76..606d676 100644
--- a/README.md
+++ b/README.md
@@ -10,9 +10,16 @@
- NeoColor: 可以提供十六进制颜色值以灵活自定义文本颜色
- ItemEntity: 方便在场景中显示物品实体(由于技术原因,物品实体不会转)
- Key: 提供某个功能的id以显示这个功能绑定的按键
+- Colour: 渐变色,提供2种颜色让文本渐变(非动态),也可以设置文本的样式
+ - 粗细(bold)
+ - 斜体(italic)
+ - 下划线(underlined)
+ - 删除线(strikethrough)
+ - 阴影(dropShadow)
- WIP: 咕咕咕
-部分文本抄自[AnvilCraft-Patchouli](https://github.com/Anvil-Dev/AnvilCraft-Patchouli)和[Xekr's TODO](https://github.com/Anvil-Dev/AnvilCraft/issues?q=is%3Aissue%20state%3Aopen%20author%3AXeKr%20label%3A%22%F0%9F%93%8B%EF%B8%8F%20TODO%22)
+部分文本抄自[AnvilCraft-Patchouli](https://github.com/Anvil-Dev/AnvilCraft-Patchouli)
+和[Xekr's TODO](https://github.com/Anvil-Dev/AnvilCraft/issues?q=is%3Aissue%20state%3Aopen%20author%3AXeKr%20label%3A%22%F0%9F%93%8B%EF%B8%8F%20TODO%22)
## 使用许可
@@ -20,9 +27,10 @@
## 使用方法
-下载对应版本[GuideME](https://github.com/AppliedEnergistics/GuideME)、[AnvilCraft](https://github.com/Anvil-Dev/AnvilCraft)和此 `mod` 放入 `mods` 文件夹,启动游戏即可
+下载对应版本[GuideME](https://github.com/AppliedEnergistics/GuideME)、[AnvilCraft](https://github.com/Anvil-Dev/AnvilCraft)和此 `mod` 放入
+`mods` 文件夹,启动游戏即可
## 主要维护者
-[@theabab2333](https://github.com/theabab23333)
+[@theabab2333](https://github.com/theabab23333)
[@Gugle](https://github.com/Gu-ZT)
\ No newline at end of file
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 3fd695b..f978d2e 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -3,7 +3,7 @@ minecraft = "1.21.1"
neoForge = "21.1.152"
registrate = "MC1.21-1.3.0+62"
anvillib = "1.4.0+build.172"
-anvilcraft = "1.5.0+hotfix.1562"
+anvilcraft = "1.5.0+hotfix.1563"
curios = "9.0.15+1.21.1"
jei = "19.21.0.247"
jade = "15.3.4+neoforge"
diff --git a/guidebook/dev.md b/guidebook/dev.md
index 6578be9..bc87fc5 100644
--- a/guidebook/dev.md
+++ b/guidebook/dev.md
@@ -27,14 +27,15 @@ navigation:
## 模组加载情况:
-
-
-
-
+
+
+
+
## 添加的功能:
- ModInfo: **提供modid以查看当前当前模组加载情况** (可以添加url跳转至外部链接)
- NeoColor: **提供十六进制颜色值以灵活自定义文本颜色** ~~("我吐了怎么guideme本体只能填那几个注册好的颜色啊")~~
- ItemEntity: **方便在场景中显示物品实体**~~(由于技术原因,物品实体不会转)~~
- - Key: **提供某个功能的id以显示这个功能绑定的按键**
\ No newline at end of file
+ - Key: **提供某个功能的id以显示这个功能绑定的按键**
+- Colour: 渐变色,提供2种颜色让文本渐变(非动态)
\ No newline at end of file
diff --git a/guidebook/index.md b/guidebook/index.md
index cbe22f7..ce03c30 100644
--- a/guidebook/index.md
+++ b/guidebook/index.md
@@ -1,7 +1,7 @@
---
navigation:
title: "介绍"
- icon: "anvilcraft_guideme:guideme_book"
+ icon: "anvilcraft:guide_book"
position: 0
---
diff --git a/src/main/java/dev/anvilcraft/guideme/AnvilCraftGuideME.java b/src/main/java/dev/anvilcraft/guideme/AnvilCraftGuideME.java
index d1c9627..3fbe9c7 100644
--- a/src/main/java/dev/anvilcraft/guideme/AnvilCraftGuideME.java
+++ b/src/main/java/dev/anvilcraft/guideme/AnvilCraftGuideME.java
@@ -3,6 +3,7 @@
import com.mojang.logging.LogUtils;
import com.tterrag.registrate.Registrate;
import dev.anvilcraft.guideme.data.ModDatagen;
+import dev.anvilcraft.guideme.guide.compiler.tag.GradientColourTagCompiler;
import dev.anvilcraft.guideme.guide.compiler.tag.KeyMapTagCompiler;
import dev.anvilcraft.guideme.guide.compiler.tag.ModInfoTagCompiler;
import dev.anvilcraft.guideme.guide.compiler.tag.NeoColorTagCompiler;
@@ -37,6 +38,7 @@ private void guide() {
.folder("ac_guidebook")
.extension(SceneElementTagCompiler.EXTENSION_POINT, new ItemEntityShapeCompiler())
.extension(TagCompiler.EXTENSION_POINT, new NeoColorTagCompiler())
+ .extension(TagCompiler.EXTENSION_POINT, new GradientColourTagCompiler())
.extension(TagCompiler.EXTENSION_POINT, new ModInfoTagCompiler())
.extension(TagCompiler.EXTENSION_POINT, new KeyMapTagCompiler())
.build();
diff --git a/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/GradientColourTagCompiler.java b/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/GradientColourTagCompiler.java
new file mode 100644
index 0000000..064f93e
--- /dev/null
+++ b/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/GradientColourTagCompiler.java
@@ -0,0 +1,101 @@
+package dev.anvilcraft.guideme.guide.compiler.tag;
+
+import dev.anvilcraft.guideme.guide.compiler.util.ColorUtil;
+import guideme.color.ColorValue;
+import guideme.compiler.PageCompiler;
+import guideme.compiler.tags.FlowTagCompiler;
+import guideme.compiler.tags.MdxAttrs;
+import guideme.document.flow.LytFlowParent;
+import guideme.document.flow.LytFlowSpan;
+import guideme.libs.mdast.mdx.model.MdxJsxElementFields;
+import guideme.libs.mdast.model.MdAstNode;
+import guideme.style.TextStyle;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class GradientColourTagCompiler extends FlowTagCompiler {
+ @Override
+ public Set getTagNames() {
+ return Set.of("Colour", "GradientColour", "BetterColor");
+ }
+
+ @Override
+ protected void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElementFields el) {
+ String string1 = MdxAttrs.getString(compiler, parent, el, "firstColor", null);
+ String string2 = MdxAttrs.getString(compiler, parent, el, "lastColor", null);
+ if (string1 == null) {
+ parent.appendError(compiler, "Missing 'firstColor' attribute", el);
+ return;
+ } else if (string2 == null) {
+ parent.appendError(compiler, "Missing 'lastColor' attribute", el);
+ return;
+ }
+
+ ColorValue firstColor;
+ ColorValue lastColor;
+
+ try {
+ firstColor = new ColorUtil(string1);
+ lastColor = new ColorUtil(string2);
+ } catch (IllegalArgumentException e) {
+ parent.appendError(compiler, "Unknown color: '" + string1 + "||" + string2 + "'", el);
+ return;
+ }
+
+ List strings = new ArrayList<>();
+ List spans = new ArrayList<>();
+ List colorValues = new ArrayList<>();
+
+ boolean bold = MdxAttrs.getBoolean(compiler, parent, el, "bold", false);
+ boolean italic = MdxAttrs.getBoolean(compiler, parent, el, "italic", false);
+ boolean underlined = MdxAttrs.getBoolean(compiler, parent, el, "underlined", false);
+ boolean strikethrough = MdxAttrs.getBoolean(compiler, parent, el, "strikethrough", false);
+ boolean obfuscated = MdxAttrs.getBoolean(compiler, parent, el, "obfuscated", false);
+ boolean dropShadow = MdxAttrs.getBoolean(compiler, parent, el, "dropShadow", false);
+
+ if (el.children() != null) {
+ for (var child : el.children()) {
+ if (child instanceof MdAstNode node) {
+ String text = node.toText();
+ for (int i = 0; i < text.length(); i++) {
+ strings.add(String.valueOf(text.charAt(i)));
+ }
+ }
+ }
+ }
+
+ int stringSize = strings.size();
+ if (stringSize > 0) {
+ for (int i = 0; i < stringSize; i++) {
+ float ratio = stringSize > 1 ? (float) i / (stringSize - 1) : 0.0f;
+ String gradientColor = ColorUtil.calculateGradientColor(firstColor, lastColor, ratio);
+ colorValues.add(new ColorUtil(gradientColor));
+ }
+
+ for (String string : strings) {
+ LytFlowSpan span = new LytFlowSpan();
+ span.appendText(string);
+ spans.add(span);
+ }
+
+ int spanSize = spans.size();
+ for (int i = 0; i < spanSize; i++) {
+ var span = spans.get(i);
+ span.setStyle(
+ TextStyle.builder()
+ .color(colorValues.get(i))
+ .bold(bold)
+ .italic(italic)
+ .underlined(underlined)
+ .strikethrough(strikethrough)
+ .obfuscated(obfuscated)
+ .dropShadow(dropShadow)
+ .build()
+ );
+ parent.append(span);
+ }
+ }
+ }
+}
diff --git a/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/ModInfoTagCompiler.java b/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/ModInfoTagCompiler.java
index b85c5bb..0f5e2fd 100644
--- a/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/ModInfoTagCompiler.java
+++ b/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/ModInfoTagCompiler.java
@@ -33,11 +33,13 @@ protected void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElemen
parent.appendError(compiler, "Missing 'id' attribute", el);
return;
}
+
LytFlowLink link = new LytFlowLink();
String modName = IntegrationUtil.getName(id);
String modVersion = IntegrationUtil.getVersion(id);
String url = el.getAttributeString("url", null);
String nameAndVersion;
+
if (modName != null && modVersion != null) {
nameAndVersion = modName + " " + modVersion;
link.appendText(Component.translatable("gui.ac_guideme.loaded", nameAndVersion).getString());
diff --git a/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/NeoColorTagCompiler.java b/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/NeoColorTagCompiler.java
index 263eb68..e2c371f 100644
--- a/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/NeoColorTagCompiler.java
+++ b/src/main/java/dev/anvilcraft/guideme/guide/compiler/tag/NeoColorTagCompiler.java
@@ -30,17 +30,17 @@ protected void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElemen
return;
}
- ColorValue firstColor;
+ ColorValue colorValue;
try {
- firstColor = new ColorUtil(string);
+ colorValue = new ColorUtil(string);
} catch (IllegalArgumentException e) {
parent.appendError(compiler, "Unknown color: '" + string + "'", el);
return;
}
LytFlowSpan span = new LytFlowSpan();
- span.setStyle(TextStyle.builder().color(firstColor).build());
+ span.setStyle(TextStyle.builder().color(colorValue).build());
parent.append(span);
compiler.compileFlowContext(el.children(), span);
}
diff --git a/src/main/java/dev/anvilcraft/guideme/guide/compiler/util/ColorUtil.java b/src/main/java/dev/anvilcraft/guideme/guide/compiler/util/ColorUtil.java
index 746deb9..cebdb67 100644
--- a/src/main/java/dev/anvilcraft/guideme/guide/compiler/util/ColorUtil.java
+++ b/src/main/java/dev/anvilcraft/guideme/guide/compiler/util/ColorUtil.java
@@ -74,6 +74,28 @@ public static int argb(int a, int r, int g, int b) {
return FastColor.ARGB32.color(a, r, g, b);
}
+ public static String calculateGradientColor(ColorValue firstColor, ColorValue lastColor, float ratio) {
+ int firstColorInt = firstColor.resolve(LightDarkMode.LIGHT_MODE);
+ int lastColorInt = lastColor.resolve(LightDarkMode.LIGHT_MODE);
+
+ int firstR = (firstColorInt >> 16) & 0xFF;
+ int firstG = (firstColorInt >> 8) & 0xFF;
+ int firstB = firstColorInt & 0xFF;
+ int firstA = (firstColorInt >> 24) & 0xFF;
+
+ int lastR = (lastColorInt >> 16) & 0xFF;
+ int lastG = (lastColorInt >> 8) & 0xFF;
+ int lastB = lastColorInt & 0xFF;
+ int lastA = (lastColorInt >> 24) & 0xFF;
+
+ int r = Math.max(0, Math.min(255, (int) (firstR + ratio * (lastR - firstR))));
+ int g = Math.max(0, Math.min(255, (int) (firstG + ratio * (lastG - firstG))));
+ int b = Math.max(0, Math.min(255, (int) (firstB + ratio * (lastB - firstB))));
+ int a = Math.max(0, Math.min(255, (int) (firstA + ratio * (lastA - firstA))));
+
+ return String.format("#%02X%02X%02X%02X", r, g, b, a);
+ }
+
@Override
public int resolve(LightDarkMode lightDarkMode) {
return color;
From 338829c829e6794fbc9b9c4effd3d6c761f6badc Mon Sep 17 00:00:00 2001
From: theabab2333 <2047477146@qq.com>
Date: Thu, 25 Dec 2025 22:05:53 +0800
Subject: [PATCH 2/2] =?UTF-8?q?feat(compiler):=20=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E6=B8=90=E5=8F=98=E8=89=B2=E6=A0=87=E7=AD=BE=E7=BC=96=E8=AF=91?=
=?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 实现了 GradientColourTagCompiler 类处理渐变色标签
- 在 ColorUtil 中添加 calculateGradientColor 方法计算渐变颜色
- 更新 AnvilCraftGuideME.java 注册新的渐变色标签编译器
- 修改 ModInfoTagCompiler 和 NeoColorTagCompiler 代码优化
- 更新 README.md 和 guidebook/dev.md 文档说明新功能
---
guidebook/dev.md | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/guidebook/dev.md b/guidebook/dev.md
index bc87fc5..fd3a696 100644
--- a/guidebook/dev.md
+++ b/guidebook/dev.md
@@ -15,15 +15,15 @@ navigation:
## 本模组目前状态:
- - [y] 绝大部分配方的兼容
- - [n] guide内容重写和新写
- - [?] 有用没用的功能添加
+- [y] 绝大部分配方的兼容
+- [n] guide内容重写和新写
+- [?] 有用没用的功能添加
### 其他:
- - [y] 在开发环境中[实时预览](https://guideme.appliedenergistics.org/live-preview)
- - [n] 从帕秋莉转换 ~~(已放弃 出各种莫名其妙的bug)~~
- - [?] 英文翻译 ~~(等中文补全再说吧 咕咕咕)~~
+- [y] 在开发环境中[实时预览](https://guideme.appliedenergistics.org/live-preview)
+- [n] 从帕秋莉转换 ~~(已放弃 出各种莫名其妙的bug)~~
+- [?] 英文翻译 ~~(等中文补全再说吧 咕咕咕)~~
## 模组加载情况:
@@ -34,8 +34,8 @@ navigation:
## 添加的功能:
- - ModInfo: **提供modid以查看当前当前模组加载情况** (可以添加url跳转至外部链接)
- - NeoColor: **提供十六进制颜色值以灵活自定义文本颜色** ~~("我吐了怎么guideme本体只能填那几个注册好的颜色啊")~~
- - ItemEntity: **方便在场景中显示物品实体**~~(由于技术原因,物品实体不会转)~~
- - Key: **提供某个功能的id以显示这个功能绑定的按键**
-- Colour: 渐变色,提供2种颜色让文本渐变(非动态)
\ No newline at end of file
+- ModInfo: **提供modid以查看当前当前模组加载情况**(可以添加url跳转至外部链接)
+- NeoColor: **提供十六进制颜色值以灵活自定义文本颜色** ~~("我吐了怎么guideme本体只能填那几个注册好的颜色啊")~~
+- ItemEntity: **方便在场景中显示物品实体**~~(由于技术原因,物品实体不会转)~~
+- Key: **提供某个功能的id以显示这个功能绑定的按键**
+- Colour: 渐变色,提供2种颜色让文本渐变(非动态)
\ No newline at end of file