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:54] 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''后,您的组将被添加到创造模式菜单中的物品组列表中。 
-Make sure you replace the arguments ((Remember that the arguments you pass to the ''Identifier'' constructor can only contain certain characters.\\ Both arguments (the ''namespace'' ''path'') can contain //lowercase letters//, //numbers//, //underscores//, //periods//, or //dashes//''[a-z0-9_.-]''\\ The second argument (the ''path'') can also include //slashes//''[a-z0-9/._-]''\\ Avoid using other symbols, else an ''InvalidIdentifierException'' would be thrown!)) you pass to the ''Identifier'' constructor with your actual mod ID and the translation key you want to give your item group for localization ((The full translation key for the first example ''ItemGroup'' would be ''itemGroup.mod_id.general'')) later on.+ 
 +请确保将您传递到''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>
  
-==== 使物品组按特定顺序显示特定项目 ==== +==== 使物品组按特定顺序显示特定物品 ==== 
-Call ''FabricItemGroupBuilder#appendItems'' and pass any ''Consumer<List<ItemStack//>//>''. You can then add whatever stacks you want to the given list in some order. ''ItemStack.EMPTY'' can be used to place empty spaces in your group. +调用''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 39: 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