Reputation: 59242
In a Minecraft Forge mod, I want to create a portion that appears yellow and doesn't shimmer (like a yellow version of the "Water Bottle" potion).
I'm currently doing something like this (irrelevant bits omitted):
@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 registerPotionTypes(RegistryEvent.Register<PotionType> event) {
event.getRegistry().register(POTION_TYPE_LEMONADE.setRegistryName("lemonade"));
}
}
}
This creates a yellow potion, but it shimmers. Is there a way to remove the shimmering effect?
Upvotes: 1
Views: 135
Reputation: 59242
Based on responses from a Minecraft Forge forum post, this class defines an Item that behaves like a potion when you right-click:
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.List;
public class ItemLemonade extends Item {
/**
* This method needs to be overridden because otherwise the duration is too short,
* the potion consumption won't animate correctly, and there won't be any sound
*/
@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<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
tooltip.add("Delicious, refreshing lemonade");
}
}
Upvotes: 0
Reputation: 15941
Rather than using the systems vanilla has for brewing potions:
Diesieben07 said:
PotionType
is a potion that can be brewed,Potion
is just the "type of effect."
With info from that thread, just create a normal item class and override this method, like this:
@Override
public EnumAction getItemUseAction(ItemStack stack)
{
return EnumAction.DRINK;
}
This deals with the shimmer, as ItemPotion
overrides public boolean hasEffect(ItemStack stack)
to return true when the potion has any effects (and you don't want that).
Then all you have to do is give the PotionEffect
to the player when they drink your item by overriding onItemUseFinish
. You can look at ItemPotion
for an example of how to do this (although there will be large sections of code you won't need).
Upvotes: 1