minecraft-source/src/net/minecraft/world/item/BottleItem.java

67 lines
3.0 KiB
Java

package net.minecraft.world.item;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.core.BlockPos;
import java.util.List;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.ItemLike;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
public class BottleItem extends Item {
public BottleItem(final Properties a) {
super(a);
}
@Override
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
final List<AreaEffectCloud> list5 = bjt.<AreaEffectCloud>getEntitiesOfClass(AreaEffectCloud.class, ayg.getBoundingBox().inflate(2.0), akm -> akm != null && akm.isAlive() && akm.getOwner() instanceof EnderDragon);
final ItemStack bek6 = ayg.getItemInHand(ajh);
if (!list5.isEmpty()) {
final AreaEffectCloud akm2 = list5.get(0);
akm2.setRadius(akm2.getRadius() - 0.5f);
bjt.playSound(null, ayg.getX(), ayg.getY(), ayg.getZ(), SoundEvents.BOTTLE_FILL_DRAGONBREATH, SoundSource.NEUTRAL, 1.0f, 1.0f);
return InteractionResultHolder.<ItemStack>success(this.turnBottleIntoItem(bek6, ayg, new ItemStack(Items.DRAGON_BREATH)));
}
final HitResult cvf7 = Item.getPlayerPOVHitResult(bjt, ayg, ClipContext.Fluid.SOURCE_ONLY);
if (cvf7.getType() == HitResult.Type.MISS) {
return InteractionResultHolder.<ItemStack>pass(bek6);
}
if (cvf7.getType() == HitResult.Type.BLOCK) {
final BlockPos fk8 = ((BlockHitResult)cvf7).getBlockPos();
if (!bjt.mayInteract(ayg, fk8)) {
return InteractionResultHolder.<ItemStack>pass(bek6);
}
if (bjt.getFluidState(fk8).is(FluidTags.WATER)) {
bjt.playSound(ayg, ayg.getX(), ayg.getY(), ayg.getZ(), SoundEvents.BOTTLE_FILL, SoundSource.NEUTRAL, 1.0f, 1.0f);
return InteractionResultHolder.<ItemStack>success(this.turnBottleIntoItem(bek6, ayg, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)));
}
}
return InteractionResultHolder.<ItemStack>pass(bek6);
}
protected ItemStack turnBottleIntoItem(final ItemStack bek1, final Player ayg, final ItemStack bek3) {
bek1.shrink(1);
ayg.awardStat(Stats.ITEM_USED.get(this));
if (bek1.isEmpty()) {
return bek3;
}
if (!ayg.inventory.add(bek3)) {
ayg.drop(bek3, false);
}
return bek1;
}
}