Jump to content

Custom potion that is yellow and doesn't shimmer


modder819

Recommended Posts

I'm trying to create a "lemonade" potion. I'd like it to look yellow, and not shimmer (the way that a water bottle looks, except yellow instead of blue). It should boost health when drunk.

 

I looked but couldn't find any info about creating potions in the MinecraftForge documentation. I tried doing something like this:

 

@Mod(modid=modId, name="Lemonade Mod", version="1.0")
public class LemonadeMod {
...
    private static final Potion POTION_LEMONADE = new PotionHealth(false, 0xFF_FF_FF_55);
    private static final PotionType POTION_TYPE_LEMONADE = new PotionType("lemonade", new PotionEffect(POTION_LEMONADE));
...
    @Mod.EventBusSubscriber
    public static class RegistrationHandler {
        @SubscribeEvent
        public static void registerPotions(RegistryEvent.Register<Potion> event) {
            event.getRegistry().register(POTION_LEMONADE.setRegistryName("lemonade"));
        }

        @SubscribeEvent
        public static void registerPotionTypes(RegistryEvent.Register<PotionType> event) {
            event.getRegistry().register(POTION_TYPE_LEMONADE.setRegistryName("lemonade"));
        }
	}
}

This created a new potion, but it shimmered (enchantment glint?).

 

Do I need to create a subclass of ItemPotion and override the hasEffect method? If so, how do I associate the PotionType with an instance of my ItemPotion subclass?

 

 

Edited by modder819
incomplete
Link to comment
Share on other sites

If you use the lemonade as a potion, the built in system will add others... I think extended lemonade, splash lemonade, etc.

 

Would it be better to make the lemonade a "normal" item? Override

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

This will also deal with the shimmer issue.

Then you can simply set up a brewing recipe to produce your lemonade.

Link to comment
Share on other sites

I created my own item, and overrode getItemUseAction, but right-clicking had no effect. So then I also overrode onItemRightClick, using the code from the ItemPotion class:

 

public class ItemLemonade extends Item {
    @Override
    public EnumAction getItemUseAction(ItemStack stack) {
        return EnumAction.DRINK;
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    }
}

 

Now right-clicking does an animation when I've equipped the potion, but it's a different animation from the one with a regular potion (the potion just goes up and down in the character's right hand instead of centering like a potion). How do I recreate the animation of a regular potion?

 

Also, how do I add in the sound effect that occurs when drinking a regular potion?

Link to comment
Share on other sites

I think your issue was the time of use of the item was too short and the animation sound didn't play.  These 3 overrides from ItemPotion work for me in a new Item.

@Override
	public int getMaxItemUseDuration(ItemStack stack) {
		return 32;
	}
	
	 @Override
	    public EnumAction getItemUseAction(ItemStack stack)
	    {
	        return EnumAction.DRINK;
	    }
	 @Override
	 public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
	    {
	        playerIn.setActiveHand(handIn);
	        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
	    }

 

  • Thanks 1
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.