Skip to content

Commit c97669d

Browse files
committed
Update to 26.1-snapshot-4
1 parent 764a095 commit c97669d

File tree

10 files changed

+41
-17
lines changed

10 files changed

+41
-17
lines changed

docs/docs/02-changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import Video from '@site/src/components/Video';
33

44
# Changelog
55

6+
## 26.1.0.7-alpha (Minecraft 26.1-snapshot-4)
7+
8+
- Use ItemStackTemplate for navigation nodes to avoid crash on startup.
9+
610
## 26.1.0.6-alpha (Minecraft 26.1-snapshot-4)
711

812
- First update to 26.1-snapshot-4

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxEl
7979

8080
LytBlock listItemBlock = listItemPar;
8181

82-
if (showIcons && !childNode.icon().isEmpty()) {
82+
if (showIcons && childNode.icon() != null) {
8383
var lytHBox = new LytHBox();
8484

8585
var icon = new LytItemImage();
86-
icon.setItem(childNode.icon());
86+
icon.setItem(childNode.icon().create());
8787
lytHBox.append(icon);
8888
lytHBox.append(listItemPar);
8989
lytHBox.setAlignItems(AlignItems.CENTER);

src/main/java/guideme/internal/screen/GuideNavBar.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float par
251251
}
252252

253253
var icon = row.node.icon();
254-
if (!icon.isEmpty()) {
255-
renderContext.renderItem(icon, row.paragraph.getBounds().x() - 9, row.paragraph.getBounds().y(), 1,
254+
if (icon != null) {
255+
renderContext.renderItem(icon.create(), row.paragraph.getBounds().x() - 9,
256+
row.paragraph.getBounds().y(), 1,
256257
8,
257258
8);
258259
}
@@ -336,7 +337,7 @@ private void updateLayout() {
336337
indent = 0;
337338
}
338339

339-
if (!row.node.icon().isEmpty()) {
340+
if (row.node.icon() != null) {
340341
indent += 8; // Indent for icon;
341342
}
342343

src/main/java/guideme/internal/screen/GuideSearchScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ private void search(String query) {
168168
var icon = NavigationUtil.createNavigationIcon(page);
169169

170170
var image = new LytItemImage();
171-
if (!icon.isEmpty()) {
172-
image.setItem(icon);
171+
if (icon != null) {
172+
image.setItem(icon.create());
173173
}
174174
searchResultItem.append(image);
175175

src/main/java/guideme/internal/siteexport/SiteExporter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import net.minecraft.world.item.Item;
5454
import net.minecraft.world.item.ItemDisplayContext;
5555
import net.minecraft.world.item.ItemStack;
56+
import net.minecraft.world.item.ItemStackTemplate;
5657
import net.minecraft.world.item.Items;
5758
import net.minecraft.world.item.crafting.AbstractCookingRecipe;
5859
import net.minecraft.world.item.crafting.CraftingRecipe;
@@ -182,6 +183,16 @@ public void referenceItem(ItemStack stack) {
182183
}
183184
}
184185

186+
@Override
187+
public void referenceItem(ItemStackTemplate stack) {
188+
if (stack != null) {
189+
items.add(stack.item().value());
190+
if (!stack.components().isEmpty()) {
191+
LOG.error("Couldn't handle stack with NBT tag: {}", stack);
192+
}
193+
}
194+
}
195+
185196
@Override
186197
public void referenceFluid(Fluid fluid) {
187198
fluids.add(fluid);

src/main/java/guideme/internal/siteexport/model/NavigationNodeJson.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public static NavigationNodeJson of(NavigationNode node) {
1818
jsonNode.pageId = node.pageId().toString();
1919
}
2020
jsonNode.title = node.title();
21-
if (!node.icon().isEmpty()) {
22-
jsonNode.icon = SiteExportWriter.serializeItemStack(node.icon());
21+
if (node.icon() != null) {
22+
jsonNode.icon = SiteExportWriter.serializeItemStack(node.icon().create());
2323
}
2424
jsonNode.children = node.children().stream().map(NavigationNodeJson::of).toList();
2525
jsonNode.position = node.position();

src/main/java/guideme/internal/util/NavigationUtil.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import guideme.compiler.ParsedGuidePage;
55
import net.minecraft.core.component.DataComponentPatch;
66
import net.minecraft.core.registries.BuiltInRegistries;
7-
import net.minecraft.world.item.ItemStack;
7+
import net.minecraft.world.item.ItemStackTemplate;
8+
import org.jspecify.annotations.Nullable;
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
1011

@@ -14,10 +15,10 @@ public final class NavigationUtil {
1415
private NavigationUtil() {
1516
}
1617

17-
public static ItemStack createNavigationIcon(ParsedGuidePage page) {
18+
public static @Nullable ItemStackTemplate createNavigationIcon(ParsedGuidePage page) {
1819
var navigation = page.getFrontmatter().navigationEntry();
1920

20-
var icon = ItemStack.EMPTY;
21+
ItemStackTemplate icon = null;
2122
if (navigation != null && navigation.iconItemId() != null) {
2223
var iconItem = BuiltInRegistries.ITEM.get(navigation.iconItemId()).orElse(null);
2324
if (iconItem != null) {
@@ -26,13 +27,13 @@ public static ItemStack createNavigationIcon(ParsedGuidePage page) {
2627
.resultOrPartial(
2728
err -> LOG.error("Failed to deserialize component patch {} for icon {}: {}",
2829
navigation.iconComponents(), navigation.iconItemId(), err));
29-
icon = new ItemStack(iconItem, 1, patch.orElse(DataComponentPatch.EMPTY));
30+
icon = new ItemStackTemplate(iconItem, 1, patch.orElse(DataComponentPatch.EMPTY));
3031
} else {
31-
icon = new ItemStack(iconItem);
32+
icon = new ItemStackTemplate(iconItem);
3233
}
3334
}
3435

35-
if (icon.isEmpty()) {
36+
if (icon == null) {
3637
LOG.error("Couldn't find icon {} for icon of page {}", navigation.iconItemId(), page);
3738
}
3839
}

src/main/java/guideme/navigation/NavigationNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import java.util.List;
44
import net.minecraft.resources.Identifier;
5-
import net.minecraft.world.item.ItemStack;
5+
import net.minecraft.world.item.ItemStackTemplate;
66
import org.jetbrains.annotations.Nullable;
77

88
public record NavigationNode(
99
@Nullable Identifier pageId,
1010
String title,
11-
ItemStack icon,
11+
@org.jspecify.annotations.Nullable ItemStackTemplate icon,
1212
List<NavigationNode> children,
1313
int position,
1414
boolean hasPage) {

src/main/java/guideme/siteexport/ResourceExporter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.nio.file.Path;
44
import net.minecraft.resources.Identifier;
55
import net.minecraft.world.item.ItemStack;
6+
import net.minecraft.world.item.ItemStackTemplate;
67
import net.minecraft.world.item.crafting.Ingredient;
78
import net.minecraft.world.item.crafting.RecipeHolder;
89
import net.minecraft.world.item.crafting.display.SlotDisplay;
@@ -25,6 +26,11 @@ default void referenceItem(ItemLike item) {
2526
*/
2627
void referenceItem(ItemStack stack);
2728

29+
/**
30+
* Ensures the data needed to show tooltips or icons for this item is exported.
31+
*/
32+
void referenceItem(@org.jspecify.annotations.Nullable ItemStackTemplate stack);
33+
2834
/**
2935
* Ensures the data needed to show tooltips or icons for this fluid is exported.
3036
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
navigation:
33
title: Subpage
44
parent: markdown.md
5+
icon: minecraft:paper
56
---
67

78

0 commit comments

Comments
 (0)