我才是Joy

我们本次在模组中制作一款食物


在1.18中,食物作为一种物品,可以直接调用Item类中的构造方法


1.在ItemInit类中添加我们的食物信息


//tab(放到哪个物品栏中),nutrition(i) 回复i点饥饿度,saturationMod(j)饱腹度为j点,
    public static final RegistryObject<Item> MCHEESE = ITEMS.register("mcheese",
    () -> new Item(new Item.Properties().tab(Main.TUTORIAL_TAB).food(new FoodProperties.Builder().nutrition(4).saturationMod(2.5F).
            alwaysEat().alwaysEat().build())));

    //第二个食物...
    //    public static final RegistryObject<Item> MCHEESE = ITEMS.register("mcheese",
    //() -> new Item(new Item.Properties().tab(Main.TUTORIAL_TAB).food(new //FoodProperties.Builder().nutrition(4).saturationMod(2.5F).
    //        alwaysEat().alwaysEat().build())));

2.如果你想给自己的食品加上一些效果,可以直接使用addEffect()函数:


public static final RegistryObject<Item> MCHEESE = ITEMS.register("mcheese", 
    () -> new Item(new Item.Properties().tab(Main.TUTORIAL_TAB).food(new FoodProperties.Builder().nutrition(4).saturationMod(2.5F).
            effect(() -> new MobEffectInstance(MobEffects.REGENERATION, 200, 0,false,true), 1.0F).
            effect(() -> new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 1000, 1,false,true), 1.0F).
            alwaysEat().alwaysEat().build())));

3.代码部分结束,现在转到资源包制作



![shi.png]()

resources\assets\你的modid中的lang中添加食物的名称:


en_us.lang


"item.re8joymod.mcheese":"Your Food Name",

zh_cn.lang


"item.re8joymod.mcheese":"你的食物名称",

在models包中的item包中新建我们物品的模型文件mcheese.json


mcheese.json


{
    "parent": "item/generated",
    "textures": {
        "layer0": "re8joymod:item/mcheese"
    }
}

在textures包中的item包中添加我们的食物贴图:



![cr3.png]()

4.保存所有文件 -> 进入游戏测试



![cr.png]()

如果你的饱食度和添加的buff都正确出现的话,食物制作就完成了!





第一页 上一页 下一页 最后一页