Minecraft 1.12.2模组开发(二十五) 多重食物效果

如果你想像伊森一样用完洗手液之后直接起飞,那你该怎么制作这样的洗手液呢?

其实就是对我们食物类的效果函数进行叠加就可以了!

第一期食物制作教程

1.新建一个FoodXiShouYe类,继承自FoodBase(详见上方食物教程)

package com.Joy187.newmod.items.food;

import com.Joy187.newmod.util.IHasModel;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;


public class FoodXiShouYe extends FoodBase implements IHasModel{
	
	//我们这个食物定义5种效果,你可以继续加效果进来……
	PotionEffect effect1,effect2,effect3,effect4,effect5;
	public FoodXiShouYe(String name, int amount, float saturation, boolean iswolfFood,CreativeTabs tab, PotionEffect effect1, PotionEffect effect2, PotionEffect effect3
			, PotionEffect effect4, PotionEffect effect5) {
		super(name, amount, saturation, iswolfFood, tab);
		
		//setAlwaysEdible();
		this.effect1=effect1;
		this.effect2=effect2;
		this.effect3=effect3;
		this.effect4=effect4;
		this.effect5=effect5;
	}
	
	//吃下这个食物,就赋予各种效果
	@Override
	protected void onFoodEaten(ItemStack stack,World worldIn, EntityPlayer player) {
		if (!worldIn.isRemote)
		{
			player.addPotionEffect(new PotionEffect(effect1.getPotion(), effect1.getDuration(), effect1.getAmplifier(), effect1.getIsAmbient(), effect1.doesShowParticles()));
			player.addPotionEffect(new PotionEffect(effect2.getPotion(), effect2.getDuration(), effect2.getAmplifier(), effect2.getIsAmbient(), effect2.doesShowParticles()));
			player.addPotionEffect(new PotionEffect(effect3.getPotion(), effect3.getDuration(), effect3.getAmplifier(), effect3.getIsAmbient(), effect3.doesShowParticles()));
			player.addPotionEffect(new PotionEffect(effect4.getPotion(), effect4.getDuration(), effect4.getAmplifier(), effect4.getIsAmbient(), effect4.doesShowParticles()));
			player.addPotionEffect(new PotionEffect(effect5.getPotion(), effect5.getDuration(), effect5.getAmplifier(), effect5.getIsAmbient(), effect5.doesShowParticles()));
		}
	}

    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 25;
    }
    
	@SideOnly(Side.CLIENT)
	public boolean hasEffect( ItemStack stack)
	{
		return true;
	}
}

2.在我们声明食物的地方(我在ModItems.java中),添加我们的食物及其效果就可以了。

    // 创建我们的FoodXiShouYe的实现,共有5种效果
	public static final ItemFood XISHOUYE = new FoodXiShouYe("xishouye", 8, 4f, false, Main.ITEM_TAB, 
	new PotionEffect(MobEffects.REGENERATION, 60 * 10, 2, false, true),
	new PotionEffect(MobEffects.RESISTANCE, 5000, 0, false, true), 
	new PotionEffect(MobEffects.FIRE_RESISTANCE, 4000, 2, false, true), 
	new PotionEffect(MobEffects.ABSORPTION, 3000, 3, false, true),
	new PotionEffect(MobEffects.STRENGTH, 3000, 3, false, true));

3.按照第一期制作食物的方法进行制作

4.刷新项目 -> 运行游戏

tak.jpg

使用物品

tak2.jpg

可以看到我们的的5种效果都已经成功拥有!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay_fearless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值