2025-11-24 22:52:51 +03:00

58 lines
2.2 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.world.item;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractThrownPotion;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PotionItem;
import net.minecraft.world.item.ProjectileItem;
import net.minecraft.world.level.Level;
public abstract class ThrowablePotionItem
extends PotionItem
implements ProjectileItem {
public static float PROJECTILE_SHOOT_POWER = 0.5f;
public ThrowablePotionItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
ItemStack itemStack = player.getItemInHand(hand);
if (level instanceof ServerLevel) {
ServerLevel serverLevel = (ServerLevel)level;
Projectile.spawnProjectileFromRotation(this::createPotion, serverLevel, itemStack, player, -20.0f, PROJECTILE_SHOOT_POWER, 1.0f);
}
player.awardStat(Stats.ITEM_USED.get(this));
itemStack.consume(1, player);
return InteractionResult.SUCCESS;
}
protected abstract AbstractThrownPotion createPotion(ServerLevel var1, LivingEntity var2, ItemStack var3);
protected abstract AbstractThrownPotion createPotion(Level var1, Position var2, ItemStack var3);
@Override
public Projectile asProjectile(Level level, Position position, ItemStack itemStack, Direction direction) {
return this.createPotion(level, position, itemStack);
}
@Override
public ProjectileItem.DispenseConfig createDispenseConfig() {
return ProjectileItem.DispenseConfig.builder().uncertainty(ProjectileItem.DispenseConfig.DEFAULT.uncertainty() * 0.5f).power(ProjectileItem.DispenseConfig.DEFAULT.power() * 1.25f).build();
}
}