如果你想像伊森一样用完洗手液之后直接起飞,那你该怎么制作这样的洗手液呢?
其实就是对我们食物类的效果函数进行叠加就可以了!
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.刷新项目 -> 运行游戏
使用物品
可以看到我们的的5种效果都已经成功拥有!