Skip to content

Commit b2ebee1

Browse files
committed
Use dynamic registries to parse items in custom creative tabs. Fixes #722
1 parent 62b35e7 commit b2ebee1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/java/net/earthcomputer/clientcommands/command/CreativeTabCommand.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ public static void registerCreativeTabs() {
7171
// FIXME: this is a hack because creative tabs must be registered on startup but item stacks normally can't be
7272
// parsed until the world is loaded. Use the default registries for now, as most things in item stacks aren't
7373
// in dynamic registries yet. Fix this once creative tabs can be registered dynamically.
74-
var holderLookupProvider = new RegistryAccess.ImmutableRegistryAccess(BuiltInRegistries.REGISTRY.stream().toList());
74+
// This only affects the icon of the creative tab and the contents, which is lazily populated and has access to
75+
// the dynamic registries.
76+
var builtinLookupProvider = new RegistryAccess.ImmutableRegistryAccess(BuiltInRegistries.REGISTRY.stream().toList());
7577
tabs.forEach((key, tab) -> {
7678
try {
77-
tab.registerCreativeTab(holderLookupProvider, key);
79+
tab.registerCreativeTab(builtinLookupProvider, key);
7880
} catch (Throwable e) {
7981
LOGGER.error("Could not load tab {}", key, e);
8082
}
@@ -323,14 +325,14 @@ private static ItemStack singleItemFromNbt(HolderLookup.Provider holderLookupPro
323325
}
324326

325327
private record Tab(CompoundTag icon, ListTag items) {
326-
void registerCreativeTab(HolderLookup.Provider holderLookupProvider, String key) {
328+
void registerCreativeTab(HolderLookup.Provider builtinLookupProvider, String key) {
327329
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath("clientcommands", key), FabricItemGroup.builder()
328330
.title(Component.literal(key))
329-
.icon(() -> singleItemFromNbt(holderLookupProvider, icon))
331+
.icon(() -> singleItemFromNbt(builtinLookupProvider, icon))
330332
.displayItems((displayContext, entries) -> {
331333
Set<ItemStack> existingStacks = ItemStackLinkedSet.createTypeAndComponentsSet();
332334
for (int i = 0; i < items.size(); i++) {
333-
ItemStack stack = singleItemFromNbt(holderLookupProvider, items.getCompound(i));
335+
ItemStack stack = singleItemFromNbt(displayContext.holders(), items.getCompound(i));
334336
if (stack.isEmpty()) {
335337
continue;
336338
}

0 commit comments

Comments
 (0)