Le schede d'inventario, anche dette gruppi di oggetti, sono quelle dell'inventario in Creativa, in cui vengono memorizzati gli oggetti. Puoi creare la tua scheda personalizzata per memorizzare i tuoi oggetti a parte. Questo è piuttosto utile se la tua mod aggiunge molti oggetti e vuoi tenerli organizzati in una sola posizione per facilitarne l'accesso per i giocatori.
Creare la scheda d'inventario
Aggiungere una scheda all'inventario è abbastanza semplice. Basta creare un nuovo attributo static final nella classe dei tuoi oggetti per memorizzare la scheda e una chiave di registry per essa. Poi, potrai usare FabricItemGroup.builder per crearla e aggiungerci gli oggetti:
java
public static final ResourceKey<CreativeModeTab> CUSTOM_CREATIVE_TAB_KEY = ResourceKey.create(BuiltInRegistries.CREATIVE_MODE_TAB.key(), Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "creative_tab"));
public static final CreativeModeTab CUSTOM_CREATIVE_TAB = FabricItemGroup.builder()
.icon(() -> new ItemStack(ModItems.GUIDITE_SWORD))
.title(Component.translatable("itemGroup.example-mod"))
.displayItems((params, output) -> {
output.accept(ModItems.SUSPICIOUS_SUBSTANCE);
output.accept(ModItems.POISONOUS_APPLE);
// The tab builder also accepts Blocks
output.accept(ModBlocks.CONDENSED_OAK_LOG);
output.accept(ModBlocks.PRISMARINE_LAMP);
// And custom ItemStacks
ItemStack stack = new ItemStack(Items.SEA_PICKLE);
stack.set(DataComponents.ITEM_NAME, Component.literal("Pickle Rick"));
stack.set(DataComponents.LORE, new ItemLore(List.of(Component.literal("I'm pickle riiick!!"))));
output.accept(stack);
})
.build();1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
java
// Register the group.
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, CUSTOM_CREATIVE_TAB_KEY, CUSTOM_CREATIVE_TAB);1
2
2
Dovresti notare che la nuova scheda è ora nel menu dell'inventario in Creativa. Tuttavia, è rimasto senza traduzione - devi aggiungere una chiave al tuo file di traduzioni - come quando hai tradotto il tuo primo oggetto.

Aggiungere una Chiave di Traduzione
Se avessi per caso usato Component.translatable per il metodo title del costruttore della scheda, dovrai aggiungere la traduzione al tuo file di lingua.
json
{
"itemGroup.example-mod": "Example Mod"
}1
2
3
2
3
Ora, come puoi notare, la scheda dovrebbe avere il nome corretto:



