Jump to content

[1.9.4/1.10.2] Adding potion effect when a player eat food


TheMulti

Recommended Posts

Hi!

    My name is TheMulti. I have a problem with adding effects to food class. I want to give a player INSTANT_DAMAGE effect, but I can't do it.

Thank you in advance.

 

Here is my Solvent.java (If you need any other file , let me know - I will send them :) )

 

 

package themulti.gunwo.init;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameRegistry;
import themulti.gunwo.Gunwo;
import themulti.gunwo.Reference;

public class Solvent
{
public static Item SOLVENT;

public static void init()
{
	SOLVENT = registerItem(new ItemFood(-20, 1, true), "Solvent").setUnlocalizedName("Solvent").setMaxStackSize(16).setCreativeTab(ColorTabCraft.ColorTab);
}


public static void registerRenders()
{
	registerRender(SOLVENT);
}

public static void registerRender(Item item)
{
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}

public static Item registerItem(Item item, String name)
{
	return registerItem(item, name, null);
}

public static Item registerItem(Item item, String name, CreativeTabs tab)
	{

	GameRegistry.register(item, new ResourceLocation(Reference.MODID, name));
	Gunwo.proxy.registerItemSided(item);
	return item;
}

}

 

I would ask you to send me a revised file. :)

 

//

Sorry for my English , but I am from Poland.  :-\

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

You need to create a class that extends ItemFood and use that to initialize your food item.

 

What should I put in this class?

 

Whether it should look like a client/commonproxy but with ItemFood extends?

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

And in that class you will need to overwrite the @Override onFoodEaten and have something kinda like this

 

    protected void onFoodEaten(ItemStack itemStack, World world, EntityPlayer player)
    {	
        if (!world.isRemote)
        {
        		player.addPotionEffect(new PotionEffect(Potion.getPotionById(3), 5400, 0));
        }
    }

 

Use the Potion ID of the effect you want and the duration/strenght you need.

Link to comment
Share on other sites

Unless you want the food to only have one then you don't even have to make a new class apparently

 

// the 1 is for percentage as a decimal
customFoodItem = new ItemFood(5, false).setPotionEffect(PotionEffects.INVISIBLITY, 1);

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Unless you want the food to only have one then you don't even have to make a new class apparently

 

// the 1 is for percentage as a decimal
customFoodItem = new ItemFood(5, false).setPotionEffect(PotionEffects.INVISIBLITY, 1);

 

PotionEffects is not working in 1.10.2, but I found a counterpart: MobEffects.INSTANT_DAMAGE.

eyFnNtW.png

 

Here's a tutorial about making custom food, it's for 1.8, but shouldn't be too hard to fix up for 1.10, as long as you know some programming/java.

 

http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/custom-food/

 

I tried it, but It's not working to me... Maybe I'm stupid or too old Minecraft version. Rather, the first... :)

 

 

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

It's telling you what's wrong, you have an int where you need a float.

That is not the problem it is true that PotionEffects doesn't exist in 1.10 instead use

 

//The numbers are Duration then level
(new PotionEffect(MobEffects.REGENERATION, 400, 1);

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

It's telling you what's wrong, you have an int where you need a float.

That is not the problem it is true that PotionEffects doesn't exist in 1.10 instead use

 

//The numbers are Duration then level
(new PotionEffect(MobEffects.REGENERATION, 400, 1);

 

 

Partially it works... Partially... :'(

 

xujN34F.png

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

That is not the problem it is true that PotionEffects doesn't exist in 1.10 instead use

 

//The numbers are Duration then level
(new PotionEffect(MobEffects.REGENERATION, 400, 1);

 

Did you not see my post?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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