zh_cn:tutorial:itemgroup
This is an old revision of the document!
Table of Contents
物品组
创建简单物品组
要使“项目组’‘正确显示在“创造性”菜单中,请使用FabricItemGroupBuilder
创建它们:
public class ExampleMod implements ModInitializer { // ... public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( new Identifier("tutorial", "general"), () -> new ItemStack(Blocks.COBBLESTONE)); public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( new Identifier("tutorial", "other")) .icon(() -> new ItemStack(Items.BOWL)) .build(); // ... }
调用FabricItemGroupBuilder#build
后,您的组将被添加到creative菜单中的项目组列表中。
请确保替换参数(请记住,传递给Identifier
构造函数的参数只能包含某些字符)。[两个参数(命名空间和路径)都可以包含lowercase letters,numbers,下划线,periods,或dashes.'[a-z0-9_.-]\\第二个参数(“路径”)也可以包含slashes.'[a-z0-9_.-]
\\避免使用其他符号,否则将引发“InvalidIdentifierException!”)您将传递给具有实际mod ID的Identifier
构造函数,以及稍后要为本地化提供项组的转换密钥(第一个示例item group
的完整转换密钥将是ItemGroup.mod_ID.general
)。
将物品添加到物品组
创建自定义项时,请在设置上调用Item.Settings\group
,然后传入自定义组:
public static final Item YOUR_ITEM = new Item(new Item.Settings().group(ExampleMod.ITEM_GROUP));
使物品组按特定顺序显示特定项目
调用FabricItemGroupBuilder#appendItems
,并传递任何Consumer<List<ItemStack>>
。然后,您可以按顺序将任何堆栈添加到给定列表中ItemStack.EMPTY“”可用于在组中放置空格。
public class ExampleMod implements ModInitializer { // ... public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( new Identifier("tutorial", "general"), () -> new ItemStack(Blocks.COBBLESTONE)); public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( new Identifier("tutorial", "other")) .icon(() -> new ItemStack(Items.BOWL)) .appendItems(stacks -> { stacks.add(new ItemStack(Blocks.BONE_BLOCK)); stacks.add(new ItemStack(Items.APPLE)); stacks.add(PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER)); stacks.add(ItemStack.EMPTY); stacks.add(new ItemStack(Items.IRON_SHOVEL)); }) .build(); // ... }
zh_cn/tutorial/itemgroup.1576670264.txt.gz · Last modified: 2019/12/18 11:57 by lightcolour