111 lines
3.8 KiB
Java
111 lines
3.8 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import net.minecraft.world.item.alchemy.Potion;
|
|
import net.minecraft.core.Registry;
|
|
import net.minecraft.core.NonNullList;
|
|
import net.minecraft.network.chat.Component;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
import net.minecraft.world.InteractionHand;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import net.minecraft.world.level.ItemLike;
|
|
import net.minecraft.stats.Stat;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.effect.MobEffectInstance;
|
|
import net.minecraft.advancements.CriteriaTriggers;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.item.alchemy.PotionUtils;
|
|
import net.minecraft.world.item.alchemy.Potions;
|
|
|
|
public class PotionItem extends Item {
|
|
public PotionItem(final Properties a) {
|
|
super(a);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getDefaultInstance() {
|
|
return PotionUtils.setPotion(super.getDefaultInstance(), Potions.WATER);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack finishUsingItem(final ItemStack bek, final Level bjt, final LivingEntity akw) {
|
|
final Player ayg5 = (akw instanceof Player) ? ((Player)akw) : null;
|
|
if (ayg5 instanceof ServerPlayer) {
|
|
CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayer)ayg5, bek);
|
|
}
|
|
if (!bjt.isClientSide) {
|
|
final List<MobEffectInstance> list6 = PotionUtils.getMobEffects(bek);
|
|
for (final MobEffectInstance akh8 : list6) {
|
|
if (akh8.getEffect().isInstantenous()) {
|
|
akh8.getEffect().applyInstantenousEffect(ayg5, ayg5, akw, akh8.getAmplifier(), 1.0);
|
|
}
|
|
else {
|
|
akw.addEffect(new MobEffectInstance(akh8));
|
|
}
|
|
}
|
|
}
|
|
if (ayg5 != null) {
|
|
ayg5.awardStat(Stats.ITEM_USED.get(this));
|
|
if (!ayg5.abilities.instabuild) {
|
|
bek.shrink(1);
|
|
}
|
|
}
|
|
if (ayg5 == null || !ayg5.abilities.instabuild) {
|
|
if (bek.isEmpty()) {
|
|
return new ItemStack(Items.GLASS_BOTTLE);
|
|
}
|
|
if (ayg5 != null) {
|
|
ayg5.inventory.add(new ItemStack(Items.GLASS_BOTTLE));
|
|
}
|
|
}
|
|
return bek;
|
|
}
|
|
|
|
@Override
|
|
public int getUseDuration(final ItemStack bek) {
|
|
return 32;
|
|
}
|
|
|
|
@Override
|
|
public UseAnim getUseAnimation(final ItemStack bek) {
|
|
return UseAnim.DRINK;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
|
|
ayg.startUsingItem(ajh);
|
|
return InteractionResultHolder.<ItemStack>success(ayg.getItemInHand(ajh));
|
|
}
|
|
|
|
@Override
|
|
public String getDescriptionId(final ItemStack bek) {
|
|
return PotionUtils.getPotion(bek).getName(this.getDescriptionId() + ".effect.");
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(final ItemStack bek, @Nullable final Level bjt, final List<Component> list, final TooltipFlag bft) {
|
|
PotionUtils.addPotionTooltip(bek, list, 1.0f);
|
|
}
|
|
|
|
@Override
|
|
public boolean isFoil(final ItemStack bek) {
|
|
return super.isFoil(bek) || !PotionUtils.getMobEffects(bek).isEmpty();
|
|
}
|
|
|
|
@Override
|
|
public void fillItemCategory(final CreativeModeTab bda, final NonNullList<ItemStack> fy) {
|
|
if (this.allowdedIn(bda)) {
|
|
for (final Potion bga5 : Registry.POTION) {
|
|
if (bga5 != Potions.EMPTY) {
|
|
fy.add(PotionUtils.setPotion(new ItemStack(this), bga5));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|