Jump to content

OnFoodEaten error? 1.12.2


SonPlaying

Recommended Posts

Hello, i am a beginner in Java Modding.

So i added this in one of my ItemFood items :

protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
		if(!worldIn.isRemote) {
			player.addPotionEffect(new PotionEffect(effect.getPotion(), effect.getDuration(), effect.getAmplifier(), effect.getIsAmbient(), effect.doesShowParticles()));
		}
	}

I have some other itemfoods that have this code too... yet when i eat the food that is from this one... my minecraft crashes.

When i eat the other ones... its fine.

The whole class that makes the errored food :

package com.sonplaying.items;

import com.sonplaying.Main;
import com.sonplaying.init.ModItems;
import com.sonplaying.util.IHasModel;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemFood;
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 HealthyFood extends ItemFood implements IHasModel {
	PotionEffect effect;
	public HealthyFood(String name, int amount, float saturation, boolean isWolfFood, PotionEffect effect) {
		super(amount, saturation, isWolfFood);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.bufffoodtab);
		ModItems.ITEMS.add(this);
	}
	
	protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
		if(!worldIn.isRemote) {
			player.addPotionEffect(new PotionEffect(effect.getPotion(), effect.getDuration(), effect.getAmplifier(), effect.getIsAmbient(), effect.doesShowParticles()));
		}
	}
	
	@SideOnly(Side.CLIENT)
	public boolean hasEffect(ItemStack stack) {
		return true;
	}
	
	
	
	
	
	
	@Override
	public void registerModels() {
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}
	
}

Item Add :

public static final Item health_bread = new HealthyFood("health_bread", 5,  2.6f, false, new PotionEffect(MobEffects.REGENERATION, 15*20, 0, false, true));

Crash Report https://pastebin.com/EBsNQfRJ

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.