Repository navigation
Route generated content to mod-owned creative tabs - #111
Conversation
dshadowwolf
left a comment
There was a problem hiding this comment.
Review findings (read from the diff only; I did not run tests or the game).
| fallbackIcons.forEach((namespace, icon) -> { | ||
| var id = ResourceLocation.fromNamespaceAndPath(namespace, | ||
| "mmdlib_content"); | ||
| if (!declarations.containsKey(id) |
There was a problem hiding this comment.
The fallback <ns>:mmdlib_content tab is registered for every namespace that has generated items, unless that exact ID is already declared. The comment above says it is only for a mod without an authored or Java tab, but nothing checks for other tabs in the namespace.
Every RuntimeContentRegistrar namespace already has <ns>:materials. choose() ranks materials (3) ahead of mmdlib_content (4), so these mods also get an extra tab that stays empty but still shows in the creative inventory. Suggest skipping the fallback when definitions() or the registrars already hold any tab in that namespace.
There was a problem hiding this comment.
Fixed in 0c70199. Fallback registration now runs after the owning mod registers its Java tabs and skips namespaces with any authored, queued, or registered tab. The companion GameTest checks that its Java machines tab suppresses the fallback and receives generated items exactly once.
| tabs.register("materials", () -> CreativeModeTab.builder() | ||
| .title( | ||
| Component.translatable("itemGroup." + namespace + ".materials")) | ||
| .title(ModCreativeTabs.modTitle(namespace)) |
There was a problem hiding this comment.
The title key changes from itemGroup.<ns>.materials to itemGroup.<ns>. Existing lang entries stop applying, including the itemGroup.mmdlib.materials that is still in en_us.json, and those of consumer mods. The tab then falls back to the mod display name.
Now that displayItems is empty, this tab only gets contents when choose() picks it. If the namespace also has a main tab, a default-for-mod tab or any other non-materials path, this tab stays visible with nothing in it. Same root cause as the mmdlib_content fallback: a placeholder tab gets registered even when it can't win.
There was a problem hiding this comment.
Fixed in 0c70199. The registrar no longer creates an unconditional materials placeholder. A materials fallback is registered only when its namespace has generated items and no other tab, and it retains itemGroup..materials so existing translations continue to apply. Unit and runtime regression tests cover the key and fallback contents.
| private static void contents(BuildCreativeModeTabContentsEvent event) { | ||
| var id = event.getTabKey().location(); | ||
| var registered = BuiltInRegistries.CREATIVE_MODE_TAB.keySet(); | ||
| var definitions = definitions(); |
There was a problem hiding this comment.
Minor: contents runs for every tab on every creative rebuild, including vanilla tabs and other mods' tabs. Each call copies all definitions into a new TreeMap and streams/sorts the registry keys in choose(). A cheap early exit before calling definitions() would avoid this, for example when no registrar or definition owns this tab's namespace. Another option is to compute the chosen tab per namespace once per rebuild.
There was a problem hiding this comment.
Fixed in 0c70199. Generated items are grouped by namespace during registration, and the destination tab is selected once during common setup. Contents events return immediately for unrelated or secondary tabs, without copying definitions or sorting registry keys. Tag exclusions and feature flags remain live on each rebuild.
| ResourceLocation.CODEC.optionalFieldOf("icon") | ||
| .forGetter(CreativeTabDefinition::icon), | ||
| ENTRY.listOf().fieldOf("contents") | ||
| ENTRY.listOf().optionalFieldOf("contents", List.of()) |
There was a problem hiding this comment.
Nit: making contents optional makes sense for include_mod_items and default_for_mod tabs. But RecordCodecBuilder ignores unknown keys, so a JSON tab that misspells it (content) now loads as an empty tab with no error. Before this change the load failed. Consider rejecting a definition that has no contents, include_mod_items false and default_for_mod false.
There was a problem hiding this comment.
Fixed in 0c70199. The definition constructor rejects empty contents unless include_mod_items or default_for_mod is enabled, covering JSON, XML, and Java builders. Regression tests cover omitted contents, an empty array, the content typo, and valid automatic-content definitions. Both CI workflows passed.
Generated machine and material items now join their owning mod's creative tab instead of a shared data-defined-machines tab. Mods can declare tabs in XML or JSON, select a default tab, include registered items from their namespace, and exclude items or reloadable tags. Java builders and CraftTweaker expose the same options.
Adds loader, routing and runtime coverage, including duplicate prevention and exclusion precedence. Fixtures use existing material items so this change is independent of the upcoming machine upgrades.
Validation:
spotlessCheck,verifyMachineImportsand diff checks passed. The combined stack compiled and passed the focused drawer client smoke; creative-tab runtime tests and full suites are left to CI.