Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

给item文件加了注释 #1

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.item.FoodComponent;

public class ModFoodComponents {
//食用后恢复6点饥饿值,0.25的饱和度修正值。
public static final FoodComponent DOUZHIR = new FoodComponent.Builder()
.hunger(6)
.saturationModifier(0.25f)
Expand Down
38 changes: 24 additions & 14 deletions src/main/java/cn/shidux/chinesefoods/item/ModItemGroups.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package cn.shidux.chinesefoods.item;

import cn.shidux.chinesefoods.ChineseFoods;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import cn.shidux.chinesefoods.ChineseFoods; // 引入自定义模组的包和类
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; // 引入Fabric API的ItemGroup构建器
import net.minecraft.item.ItemGroup; // 引入Minecraft的ItemGroup接口
import net.minecraft.item.ItemStack; // 引入Minecraft的ItemStack类,用于表示物品栈
import net.minecraft.registry.Registries; // 引入Minecraft的注册表管理类
import net.minecraft.registry.Registry; // 引入Minecraft的注册表类
import net.minecraft.text.Text; // 引入Minecraft的文本类
import net.minecraft.util.Identifier; // 引入Minecraft的标识符类

public class ModItemGroups {

public static final ItemGroup CHINESE_FOODS_GROUP = Registry.register(Registries.ITEM_GROUP,
new Identifier(ChineseFoods.MOD_ID, "chinesefoods"),
FabricItemGroup.builder().displayName(Text.translatable("itemgroup.chinesefoods"))
.icon(() -> new ItemStack(ModItems.DOUZHIR)).entries((displayContext, entries) -> {
new Identifier(ChineseFoods.MOD_ID, "chinesefoods"), // 使用模组的ID和物品组的名称创建标识符
FabricItemGroup.builder() // 使用Fabric的ItemGroup构建器开始构建
.displayName(Text.translatable("itemgroup.chinesefoods")) // 设置物品组的可翻译显示名称
.icon(() -> new ItemStack(ModItems.DOUZHIR)) // 设置物品组的图标为豆汁儿
.entries((displayContext, entries) -> { // 设置物品组中应包含的物品
// 添加所有食物和相关物品到物品组中
entries.add(ModItems.DOUZHIR);
entries.add(ModItems.FRIED_RING);
entries.add(ModItems.SALTED_VEGETABLE);
Expand All @@ -23,15 +27,21 @@ public class ModItemGroups {
entries.add(ModItems.ROUGAMO);
entries.add(ModItems.PITA_BREAD_SOAKED_IN_LAMB_SOUP);

// 添加食材和种子
entries.add(ModItems.MUNG_BEANS);
entries.add(ModItems.RUTABAGA);

entries.add(ModItems.MUNGBEAN_SEEDS);
entries.add(ModItems.RUTABAGA_SEEDS);

// 如果有其他需要添加到物品组的物品,也可以在这里添加
// entries.add(ModItems.item);

// 添加一碗水作为示例
entries.add(ModItems.A_BOWL_OF_WATER);
}).build());
}).build()); // 完成构建并返回ItemGroup实例

public static void registerItemGroups() {
ChineseFoods.LOGGER.info("Registering Item Groups for " + ChineseFoods.MOD_ID);
ChineseFoods.LOGGER.info("Registering Item Groups for " + ChineseFoods.MOD_ID); // 记录日志信息
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/shidux/chinesefoods/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

//这个类包含了所有由中国传统食品模组定义的食物和材料的物品注册。
public class ModItems {
public static final Item DOUZHIR = registerItem("douzhir", new Item(new FabricItemSettings()
.food(ModFoodComponents.DOUZHIR)));
Expand Down