zh_cn:tutorial:itemgroup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:itemgroup [2019/12/18 11:57] – lightcolour | zh_cn:tutorial:itemgroup [2023/11/18 08:09] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 物品组 ====== | ====== 物品组 ====== | ||
+ | |||
+ | //这是 1.20+ 版本的教程,对于 1.19 版本,请阅读[[1.19: | ||
+ | |||
+ | 现在,你可以使用命令 ''/ | ||
+ | |||
+ | ==== 添加物品组 ==== | ||
+ | |||
+ | 首先,先决定需要将物品添加到哪个物品组。例如,添加到建筑方块物品组。原版物品组存储在 ''< | ||
+ | |||
+ | 然后,在你的 '' | ||
+ | < | ||
+ | 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, | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | |||
==== 创建简单物品组 ==== | ==== 创建简单物品组 ==== | ||
- | 要使“项目组’‘正确显示在“创造性”菜单中,请使用'' | ||
- | <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(); | ||
- | // ... | ||
- | } | ||
- | </ | ||
- | 调用'' | ||
- | 请确保替换参数(请记住,传递给'' | + | 创建物品组之前,先决定是否有足够多的内容以至于需要自己的物品组。你的物品组会放置在单独的标签页中,影响可见性。 |
+ | |||
+ | 如果你认为需要自己的物品组,可以使用 | ||
+ | < | ||
+ | private static final class_1761 ITEM_GROUP = FabricItemGroup.builder() | ||
+ | .icon(() | ||
+ | .displayName(class_2561.method_43469(" | ||
+ | .entries((context, | ||
+ | entries.add(CUSTOM_ITEM); | ||
+ | }) | ||
+ | .build(); | ||
+ | </ | ||
+ | |||
+ | 你可以在 | ||
+ | |||
+ | 必须设置显示名称,否则会导致崩溃。 | ||
+ | |||
+ | 下一部是注册你的物品组。 | ||
- | === 将物品添加到物品组 === | + | <yarncode |
- | 创建自定义项时,请在设置上调用'' | + | class_2378.method_10230(class_7923.field_44687, |
- | <code java> | + | </yarncode> |
- | public static final Item YOUR_ITEM = new Item(new Item.Settings().group(ExampleMod.ITEM_GROUP)); | + | |
- | </code> | + | |
- | ==== 使物品组按特定顺序显示特定项目 ==== | ||
- | 调用'' | ||
- | <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.1576670264.txt.gz · Last modified: 2019/12/18 11:57 by lightcolour