zh_cn:tutorial:itemgroup
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
zh_cn:tutorial:itemgroup [2019/12/18 11:52] – created lightcolour | zh_cn:tutorial:itemgroup [2023/11/18 08:09] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | ==== Creating a simple Item Group ==== | + | |
- | To have your '' | + | |
- | <code java [enable_line_numbers=" | + | |
- | public class ExampleMod implements ModInitializer | + | |
- | { | + | |
- | // ... | + | |
- | public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( | + | |
- | new Identifier(" | + | |
- | () -> new ItemStack(Blocks.COBBLESTONE)); | + | |
- | + | ||
- | public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( | + | |
- | new Identifier(" | + | |
- | .icon(() -> new ItemStack(Items.BOWL)) | + | |
- | .build(); | + | |
- | // ... | + | |
- | } | + | |
- | </ | + | |
- | Once '' | + | |
- | Make sure you replace the arguments ((Remember that the arguments you pass to the '' | + | //这是 1.20+ 版本的教程,对于 1.19 版本,请阅读[[1.19: |
- | === Adding your Items to your Item Group === | + | 现在,你可以使用命令 ''/ |
- | When creating a custom Item, call '' | + | |
- | <code java> | + | ==== 添加物品组 ==== |
- | public | + | |
- | </code> | + | 首先,先决定需要将物品添加到哪个物品组。例如,添加到建筑方块物品组。原版物品组存储在 ''< |
+ | |||
+ | 然后,在你的 '' | ||
+ | < | ||
+ | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | ||
+ | content.add(CUSTOM_ITEM); | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | 这个 modification event 也能够进行更加精细化的控制,例如将你的自定义物品放在特定的位置(例如,在 ''< | ||
+ | |||
+ | 物品可以添加到一个相对于原版物品的位置。仔细思考你的模组的用户会期望物品出现在哪里。例如,如果你添加一种新的类型的木头,那么将其添加到已有木头的后面或许是最合理的。 | ||
+ | |||
+ | 例如,以下这个事件监听器会将你的模组中的物品放在建筑方块物品组中的橡木门后面: | ||
+ | |||
+ | < | ||
+ | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | ||
+ | content.addAfter(class_1802.field_8691, CUSTOM_ITEM); | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== 创建简单物品组 ==== | ||
+ | |||
+ | 创建物品组之前,先决定是否有足够多的内容以至于需要自己的物品组。你的物品组会放置在单独的标签页中,影响可见性。 | ||
+ | |||
+ | 如果你认为需要自己的物品组,可以使用 | ||
+ | <yarncode | ||
+ | private | ||
+ | .icon(() -> new class_1799(CUSTOM_ITEM)) | ||
+ | .displayName(class_2561.method_43469(" | ||
+ | | ||
+ | entries.add(CUSTOM_ITEM); | ||
+ | }) | ||
+ | .build(); | ||
+ | </ | ||
+ | |||
+ | 你可以在 '' | ||
+ | |||
+ | 必须设置显示名称,否则会导致崩溃。 | ||
+ | |||
+ | 下一部是注册你的物品组。 | ||
+ | |||
+ | < | ||
+ | class_2378.method_10230(class_7923.field_44687, | ||
+ | </yarncode> | ||
- | ==== Making an Item Group display specific Items in a particular order ==== | ||
- | Call '' | ||
- | <code java [enable_line_numbers=" | ||
- | public class ExampleMod implements ModInitializer | ||
- | { | ||
- | // ... | ||
- | public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( | ||
- | new Identifier(" | ||
- | () -> new ItemStack(Blocks.COBBLESTONE)); | ||
- | |||
- | public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( | ||
- | new Identifier(" | ||
- | .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), | ||
- | stacks.add(ItemStack.EMPTY); | ||
- | stacks.add(new ItemStack(Items.IRON_SHOVEL)); | ||
- | }) | ||
- | .build(); | ||
- | // ... | ||
- | } | ||
- | </ | ||
{{: | {{: |
zh_cn/tutorial/itemgroup.1576669926.txt.gz · Last modified: 2019/12/18 11:52 by lightcolour