55 lines
2.2 KiB
Java
55 lines
2.2 KiB
Java
package net.minecraft.item;
|
|
|
|
import java.util.List;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.client.util.ITooltipFlag;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.entity.projectile.EntityPotion;
|
|
import net.minecraft.init.SoundEvents;
|
|
import net.minecraft.potion.PotionUtils;
|
|
import net.minecraft.stats.StatList;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.EnumActionResult;
|
|
import net.minecraft.util.EnumHand;
|
|
import net.minecraft.util.SoundCategory;
|
|
import net.minecraft.util.text.translation.I18n;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class ItemLingeringPotion extends ItemPotion
|
|
{
|
|
public String getItemStackDisplayName(ItemStack stack)
|
|
{
|
|
return I18n.translateToLocal(PotionUtils.getPotionFromItem(stack).getNamePrefixed("lingering_potion.effect."));
|
|
}
|
|
|
|
/**
|
|
* allows items to add custom lines of information to the mouseover description
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
|
{
|
|
PotionUtils.addPotionTooltip(stack, tooltip, 0.25F);
|
|
}
|
|
|
|
/**
|
|
* Called when the equipped item is right clicked.
|
|
*/
|
|
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
|
{
|
|
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
|
ItemStack itemstack1 = playerIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
|
|
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_LINGERINGPOTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
|
|
|
if (!worldIn.isRemote)
|
|
{
|
|
EntityPotion entitypotion = new EntityPotion(worldIn, playerIn, itemstack1);
|
|
entitypotion.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
|
|
worldIn.spawnEntity(entitypotion);
|
|
}
|
|
|
|
playerIn.addStat(StatList.getObjectUseStats(this));
|
|
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
|
}
|
|
} |