Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

}

 

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.

  • Author

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. 

  • Author

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

  • Author

It is because it's just one single "Potion" right? So extending ItemFood is better. :o

  • Author

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

 

  • Author

So there is an other way that I can make my item? I'm really stuck :(

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.