zh_cn:tutorial:itemgroup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
zh_cn:tutorial:itemgroup [2020/11/11 15:00] – [使物品组按特定顺序显示特定项目] solidblock | zh_cn:tutorial:itemgroup [2023/08/17 12:17] – [创建简单物品组] wjz_p | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 物品组 ====== | ====== 物品组 ====== | ||
+ | |||
+ | 现在,你可以使用命令 ''/ | ||
+ | |||
+ | ==== 添加物品组 ==== | ||
+ | |||
+ | 首先,先决定需要将物品添加到哪个物品组。例如,添加到建筑方块物品组。原版物品组存储在 ''< | ||
+ | |||
+ | 然后,在你的 '' | ||
+ | |||
+ | 物品可以添加到一个相对于原版物品的位置。仔细思考你的模组的用户会期望物品出现在哪里。例如,如果你添加一种新的类型的木头,那么将其添加到已有木头的后面或许是最合理的。 | ||
+ | |||
+ | 例如,以下这个事件监听器会将你的模组中的物品放在建筑方块物品组中的橡木门后面: | ||
+ | |||
+ | < | ||
+ | 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(new class_2960(" | ||
+ | .icon(() | ||
+ | .build(); | ||
+ | </ | ||
+ | |||
+ | 你可以使用 '' | ||
- | === 将物品添加到物品组 === | + | <yarncode |
- | 创建自定义物品时,请在设置上调用'' | + | ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP).register(content -> { |
- | <code java> | + | content.add(CUSTOM_ITEM); |
- | public static final Item YOUR_ITEM = new Item(new Item.Settings().group(ExampleMod.ITEM_GROUP)); | + | }); |
- | </code> | + | </yarncode> |
- | ==== 使物品组按特定顺序显示特定物品 ==== | ||
- | 调用'' | ||
- | <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.txt · Last modified: 2023/11/18 08:09 by solidblock