Skip to content

Commit a255125

Browse files
committed
Add data component support for ItemLink.
(cherry picked from commit 4527bd5)
1 parent 9b00e2e commit a255125

File tree

6 files changed

+90
-8
lines changed

6 files changed

+90
-8
lines changed

docs/docs/02-changelog.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,40 @@ import Video from '@site/src/components/Video';
33

44
# Changelog
55

6+
## 21.10.2-beta (Minecraft 1.21.10)
7+
8+
- Added support for data components to `<ItemLink />`
9+
10+
## 21.10.1-beta (Minecraft 1.21.10)
11+
12+
- First update to 1.21.10
13+
14+
## 21.8.4 (Minecraft 1.21.8)
15+
16+
- Markdown parse errors now log the line and column where the error occurred.
17+
18+
## 21.8.3 (Minecraft 1.21.8)
19+
20+
- Fix fluid rendering in game scenes
21+
22+
## 21.8.2 (Minecraft 1.21.8)
23+
24+
- Make the stripped down version of GuideME the default to be published to CurseForge/Modrinth (Reduces mod size by 5MB)
25+
- Strip removed Lucene components from service files to fix startup crashes since NeoForge become stricter about service files
26+
27+
## 21.8.1 (Minecraft 1.21.8)
28+
29+
- First port to Minecraft 1.21.8
30+
- The `/guidemec export` command to export guide data for web use now works
31+
- Fixed rendering of in-world annotations in game scenes that was slightly broken since 1.21.5
32+
- Fixed several export related problems present since 1.21.5
33+
- Fixed error on startup complaining about an incubating JDK feature (vector), and the subsequent crash
34+
when that feature was actually enabled.
35+
636
## 21.5.9-beta (Minecraft 1.21.5)
737

838
- Fix text in floating elements disappearing while scrolling.
39+
- Fix layout of game scenes still including the vertical toolbar even if it was hidden.
940

1041
## 21.5.8-beta (Minecraft 1.21.5)
1142

@@ -14,18 +45,27 @@ import Video from '@site/src/components/Video';
1445
This change allows the same structure to be added multiple times to a scene at different positions.
1546
- Add a new `<RemoveBlock id="..." />` tag to game scenes to clear out tags of a given type. This is useful for clearing out support blocks
1647
from structures after they have been imported into a scene. See the [game scene documentation](./30-authoring/game-scenes.md#remove-blocks) for details.
48+
- Fix rendering of diamond overlay annotations in game scenes.
1749

1850
## 21.5.7-beta (Minecraft 1.21.5)
1951

2052
- Fix rendering of text in floated elements.
53+
- Fix hover-status for widgets embedded in the document when the screen is scaled independently of the GUI (on odd GUI scales).
54+
- Add `fallbackText` attribute to `<Recipe />`, `<RecipeFor />` and `<RecipesFor />` to allow the guide author to explicitly handle when recipes are missing due to datapacks removing them.
55+
See [authoring pages](./30-authoring/index.md#recipes) for details.
56+
- Add a new configuration option to always hide recipe errors that result from recipes being removed or hidden by datapacks and guide authors not explicitly handling those cases with the `fallbackText` attribute.
57+
This is primarily intended to be used by modpacks.
58+
- Adds the ability to color text both with a color specified in the page (`<Color color="#ff0000">text</Color>`), and by
59+
adding guide-specific custom color constants, both in [data-driven guides](./20-data-driven-guides.md#custom-colors)
60+
and for mods using an [extension point](./20-integration/symbolic-colors.md).
2161

22-
## 21.5.5-beta (Minecraft 1.21.5)
62+
## 21.5.6-beta (Minecraft 1.21.5)
2363

2464
- Fix a crash when Minecraft uses an unusual language code with uppercase components (i.e. `en_US` instead of the default `en_us`).
2565
- Added a `<PlayerName />` tag to address the player by their current name.
2666
- Added a `<KeyBind id="..." />` tag to show what a keybind is currently bound to. See [authoring pages](./30-authoring/index.md#key-bindings) for details.
2767

28-
## 21.5.4-beta (Minecraft 1.21.5)
68+
## 21.5.5-beta (Minecraft 1.21.5)
2969

3070
- Adds the ability to specify data components on `ItemImage` and `ItemIcon` using the same format used by the `/give` command.
3171
For example: `<ItemImage id="minecraft:stone" components="enchantment_glint_override=true" />` shows a piece of stone with enchantment glint applied.
@@ -39,10 +79,33 @@ import Video from '@site/src/components/Video';
3979

4080
- Remove a misplaced black pixel in the border of recipe panels.
4181

82+
## 21.5.4-beta (Minecraft 1.21.5)
83+
84+
- Fix item images being shown on top of the navigation bar.
85+
- Use same random-source as normal level rendering to avoid constantly changing block appearance in game scenes.
86+
4287
## 21.1.7 (Minecraft 1.21.1)
4388

4489
- Guard against crashes when mods return null results from their custom recipes.
4590

91+
## 21.5.3-beta (Minecraft 1.21.5)
92+
93+
- Java API: Fix Off-Screen-Renderer for Website export.
94+
- Java API: Fix various website export issues.
95+
- Java API: Introduce new extension points for the site export,
96+
and make it usable via new system properties.
97+
98+
## 21.5.2-beta (Minecraft 1.21.5)
99+
100+
- Java API: Add back the semantics of `RecipeTypeMappings.add`, which supports mapping RecipeHolders to a nullable LytBlock for custom recipes.
101+
- Java API: The registration method for factories that return a `Stream<LytBlock>` has been renamed to `addMulti`.
102+
- Java API: Added convenience constructors to `LytSlot` for aiding with new idioms used by Vanilla, such as `Optional<Ingredient>` being used instead of empty ingredients (which no longer exist).
103+
- Java API: Made the row/column factory methods for `LytSlotGrid` accept null-entries in the ingredient lists to better interface with Ingredients no longer being able to be empty.
104+
105+
## 21.5.1-beta (Minecraft 1.21.5)
106+
107+
- First port to Minecraft 1.21.5
108+
46109
## 21.1.6 (Minecraft 1.21.1)
47110

48111
- Fix wrapping of content in `<Row />` elements.

docs/docs/30-authoring/index.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ Example for horizontally centering an image on the page:
126126

127127
To automatically show the translated item name, including an appropriate tooltip, and have the item name link to the
128128
primary guidebook page for that item, use the `<ItemLink id="item_id" />` tag. The id can omit the guides default
129-
namespace.
129+
namespace.
130130

131131
[Pages need to be set as the primary target for certain item ids manually](#declaring-pages-as-itemlink-targets).
132132

133+
Similar to `ItemImage` tags, the `ItemLink` tag also accepts additional data components in the `components` attribute,
134+
same as the [Minecraft give command](https://minecraft.wiki/w/Commands/give). The data components are used for creating the ItemStack that the tooltip and
135+
shown item name are retrieved from. `<ItemLink id="minecraft:stick" components="rarity=epic" />` will show the tooltip
136+
using the epic rarity color, for example.
137+
133138
### Command Links
134139

135140
You can make links that run a command when clicked using `<CommandLink command="/command">text text</CommandLink>`.

src/main/java/guideme/compiler/tags/ItemLinkCompiler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public Set<String> getTagNames() {
1717

1818
@Override
1919
public void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElementFields el) {
20-
var itemAndId = MdxAttrs.getRequiredItemAndId(compiler, parent, el, "id");
20+
var itemAndId = MdxAttrs.getRequiredItemStackAndId(compiler, parent, el);
2121
if (itemAndId == null) {
2222
return;
2323
}
2424
var id = itemAndId.getLeft();
25-
var item = itemAndId.getRight();
25+
var stack = itemAndId.getRight();
2626

2727
var linksTo = compiler.getIndex(ItemIndex.class).get(id);
2828
// We'll error out for item-links to our own mod because we expect them to have a page
@@ -32,8 +32,6 @@ public void compile(PageCompiler compiler, LytFlowParent parent, MdxJsxElementFi
3232
return;
3333
}
3434

35-
var stack = item.getDefaultInstance();
36-
3735
// If the item link is already on the page we're linking to, replace it with an underlined
3836
// text that has a tooltip.
3937
if (linksTo == null || linksTo.anchor() == null && compiler.getPageId().equals(linksTo.pageId())) {

src/main/java/guideme/compiler/tags/MdxAttrs.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ public static Item getRequiredItem(PageCompiler compiler, LytErrorSink errorSink
154154
@Nullable
155155
public static ItemStack getRequiredItemStack(PageCompiler compiler, LytErrorSink errorSink,
156156
MdxJsxElementFields el) {
157+
var result = getRequiredItemStackAndId(compiler, errorSink, el);
158+
return result != null ? result.getValue() : null;
159+
}
160+
161+
@Nullable
162+
public static Pair<ResourceLocation, ItemStack> getRequiredItemStackAndId(PageCompiler compiler,
163+
LytErrorSink errorSink,
164+
MdxJsxElementFields el) {
157165
var itemAndId = getRequiredItemAndId(compiler, errorSink, el, "id");
158166
if (itemAndId == null) {
159167
return null;
@@ -180,7 +188,7 @@ public <T> void visitRemovedComponent(DataComponentType<T> componentType) {
180188
}
181189
}
182190

183-
return stack;
191+
return Pair.of(itemAndId.getKey(), stack);
184192
}
185193

186194
public static float getFloat(PageCompiler compiler, LytErrorSink errorSink, MdxJsxElementFields el, String name,

src/testmod/resources/assets/testmod/guides/testmod/guide/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ You may ~~need~~ a <Color color="#ff0000">door</Color> <Color id="test_color">do
1919

2020
<CommandLink command="/tp @s 0 90 0" title="Tooltip" close={true}>Teleport!</CommandLink>
2121

22+
<ItemLink id="minecraft:stick" components="rarity=epic" />
23+
2224
<GameScene zoom={4} interactive={true}>
2325
<Entity id="minecraft:sheep" data="{Color: 2}" />
2426
</GameScene>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
item_ids:
3+
- minecraft:stick
4+
---
5+
6+
# Test Page for Stick

0 commit comments

Comments
 (0)