User Tools

Site Tools


zh_cn:tutorial:itemgroup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
zh_cn:tutorial:itemgroup [2019/12/18 11:57] lightcolourzh_cn:tutorial:itemgroup [2020/11/11 15:01] – [创建简单物品组] solidblock
Line 1: Line 1:
 ====== 物品组 ====== ====== 物品组 ======
 ==== 创建简单物品组 ==== ==== 创建简单物品组 ====
-要使“项目组’‘正确显示在创造性”菜单中,请使用''FabricItemGroupBuilder''创建它们:+要使你的''ItemGroup''属性显示在创造模式菜单中,请使用''FabricItemGroupBuilder''创建它们:
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public class ExampleMod implements ModInitializer +public class ExampleMod implements ModInitializer { 
-+
- // ...+
  public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(  public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(
  new Identifier("tutorial", "general"),  new Identifier("tutorial", "general"),
Line 17: Line 16:
 } }
 </code> </code>
-调用''FabricItemGroupBuilder#build''后,您的组将被添加到creative菜单中的项目组列表中。+调用''FabricItemGroupBuilder#build''后,您的组将被添加到创造模式菜单中的物品组列表中。
  
-请确保替换参数请记住,传递给''Identifier''构造函数的参数只能包含某些字符[两个参数(命名空间和路径)都可以包含//lowercase letters//,//numbers//,//下划线//,//periods//,或//dashes//.'[a-z0-9_.-]''\\第二个参数(“路径”可以包含//slashes//.'[a-z0-9_.-]''\\避免使用其他符号,否则将引发"InvalidIdentifierException!")将传递给具有实际mod ID的''Identifier''构造函数,以及稍后要为本地化提供项组转换密钥(第一个示例''item group''的完整转换密钥将是''ItemGroup.mod_ID.general''+请确保将您传递到''Identifier''构造器的参数((请记住,传递给''Identifier''构造函数的参数只能包含某些字符。\\ 两个参数(命名空间''namespace''和路径''path'')都可以包含小写字母、数字、下划线、点和横杠。''[a-z0-9_.-]''\\ 第二个参数(''path''可以包含斜杠。''[a-z0-9/_.-]'' \\ 避免使用其他符号,否则将引发''InvalidIdentifierException''))替换为实际模组ID和你需要给予您物品组用于稍后本地化的翻译键translation key)((第一个示例''item group''的完整翻译键将是''ItemGroup.mod_ID.general''))
  
 === 将物品添加到物品组 === === 将物品添加到物品组 ===
-创建自定义时,请在设置上调用''Item.Settings\group'',然后传入自定义组:+创建自定义物品时,请在设置上调用''Item.Settings#group'',然后传入自定义组:
 <code java> <code java>
 public static final Item YOUR_ITEM = new Item(new Item.Settings().group(ExampleMod.ITEM_GROUP)); public static final Item YOUR_ITEM = new Item(new Item.Settings().group(ExampleMod.ITEM_GROUP));
 </code> </code>
  
-==== 使物品组按特定顺序显示特定项目 ==== +==== 使物品组按特定顺序显示特定物品 ==== 
-调用''FabricItemGroupBuilder#appendItems'',并传递任何''Consumer<List<ItemStack//>//>''。然后,您可以按顺序将任何堆栈添加到定列表中ItemStack.EMPTY“”可用于在组中放置空格。 +调用''FabricItemGroupBuilder#appendItems'',并传递任何''Consumer<List<ItemStack//>//>''。然后,您可以按顺序将将你想要添加的堆栈添加到定列表中。''ItemStack.EMPTY''可用于在组中放置空格。 
-<code java [enable_line_numbers="true",highlight_lines_extra="11,12,13,14,15,16,17,18"]> +<code java [enable_line_numbers="true",highlight_lines_extra="11,12,13,14,15"]> 
-public class ExampleMod implements ModInitializer +public class ExampleMod implements ModInitializer { 
-+
- // ...+
  public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(  public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(
  new Identifier("tutorial", "general"),  new Identifier("tutorial", "general"),
Line 40: Line 38:
  new Identifier("tutorial", "other"))  new Identifier("tutorial", "other"))
  .icon(() -> new ItemStack(Items.BOWL))  .icon(() -> new ItemStack(Items.BOWL))
- .appendItems(stacks -> + .appendItems(stacks -> {
- {+
  stacks.add(new ItemStack(Blocks.BONE_BLOCK));  stacks.add(new ItemStack(Blocks.BONE_BLOCK));
  stacks.add(new ItemStack(Items.APPLE));  stacks.add(new ItemStack(Items.APPLE));
zh_cn/tutorial/itemgroup.txt · Last modified: 2023/11/18 08:09 by solidblock