Jump to content

[1.12.2] How do I make a Potion? (Not Potion Effect)


XmorpH

Recommended Posts

Hello everyone I need help please!

 

In my mod I'm trying to make a drinkable Potion that heals player (more specifically an Estus Flask) but I'm in trouble with the code and functionality of the item, I know that I have to make a ItemFood for that and change the animation to EnumAction.DRINK but didn't work for me, if anyone could help me with the code of what to do next I will be very grateful. Thanks!

 

This is my code so far:

package com.xmorph.craftsoulsmod.items;

import javax.annotation.Nonnull;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;

public class ItemEstusFlask extends ItemFood 
{
public ItemEstusFlask(String name, int amount, float saturation, boolean isWolfFood) 
{
	super(amount, saturation, isWolfFood);
	this.setAlwaysEdible();
	this.setMaxStackSize(1);
	setUnlocalizedName(name);
	setRegistryName(name);
	setCreativeTab(CreativeTabs.FOOD);
}

	@Override
	@Nonnull
	public EnumAction getItemUseAction(ItemStack stack) 
	{
		return EnumAction.DRINK;
	}

}

 

Link to comment
Share on other sites

24 minutes ago, XmorpH said:

but didn't work for me

This is just as ambiguous as telling a doctor it hurts.

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

Well, I figured it out extending ItemFood and it worked as I want, only with the problem that the Potion Icon didn't show up.

 

Now, if you can help me extending ItemPotion this time, I would be very grateful. Just to see what is best to do. Thanks again.

Edited by XmorpH
Link to comment
Share on other sites

Why not? I want my item behavies like a vanilla instant health potion. The only thing I want is somebody help

 

Here's my code extending ItemFood working:

public class ItemCustomDrink extends ItemFood implements IHasModel
{
	public ItemCustomDrink(String name, int amount, boolean isWolfFood) 
	{
		super(amount, isWolfFood);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.BREWING);
		setAlwaysEdible();
		setMaxStackSize(20);
		
		ModItems.ITEMS.add(this);
	}
	
	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}
	
	@Override
	public EnumAction getItemUseAction(ItemStack stack) 
	{
		return EnumAction.DRINK;
	}
}

And this is my Item:

public class ItemEstusFlask extends ItemCustomDrink 
{
	public ItemEstusFlask(String name, int amount, boolean isWolfFood) 
	{
	super(name, amount, isWolfFood);
	}
		
	@Override
	protected void onFoodEaten(ItemStack itemStack, World worldIn, EntityPlayer player)
    {	
        if (!worldIn.isRemote)
        {
        		player.addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 100, 1));
        }
	}
}

 

Link to comment
Share on other sites

40 minutes ago, XmorpH said:

So there is an other way that I can make my item?

Make your own class and override the methods that allow you to drink it and apply the potion effect.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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