Jump to content

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


Recommended Posts

Posted

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;
	}

}

 

Posted

I know that I just created the item, and then I will have to put the heal parameters, but my problem is that in-game didn't show up the drink animation and I wonder if my code is missing something. 

Posted (edited)

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
Posted

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));
        }
	}
}

 

Posted
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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Please read the FAQ and post logs as described there.   Also, do not just add a post onto someone else's thread with your issue, create a new one please.
    • I am creating a server with mods but when i try tostart it it say in the logs:   [29Jan2025 20:36:50.715] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/fmlcore/1.20.1-47.3.27/fmlcore-1.20.1-47.3.27.jar is missing mods.toml file 159[29Jan2025 20:36:50.717] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar 160[29Jan2025 20:36:50.717] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar is missing mods.toml file 161[29Jan2025 20:36:50.718] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar 162[29Jan2025 20:36:50.718] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar is missing mods.toml file 163[29Jan2025 20:36:50.719] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar 164[29Jan2025 20:36:50.719] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar is missing mods.toml file
    • How do you configure the entity reach of a custom weapon? Asking for 1.21 Minecraft parchment
    • This topic is over a year old. If you are having an issue, please read the FAQ for the proper way to post logs, and create your own thread.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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