41 lines
1.5 KiB
Java
41 lines
1.5 KiB
Java
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.player.Player;
|
|
import net.minecraft.world.entity.projectile.Projectile;
|
|
import net.minecraft.world.entity.projectile.ThrownPotion;
|
|
import net.minecraft.world.item.ProjectileItem.DispenseConfig;
|
|
import net.minecraft.world.level.Level;
|
|
|
|
public class ThrowablePotionItem extends PotionItem implements ProjectileItem {
|
|
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) {
|
|
Projectile.spawnProjectileFromRotation(ThrownPotion::new, serverLevel, itemStack, player, -20.0F, 0.5F, 1.0F);
|
|
}
|
|
|
|
player.awardStat(Stats.ITEM_USED.get(this));
|
|
itemStack.consume(1, player);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
|
|
@Override
|
|
public Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
|
return new ThrownPotion(level, pos.x(), pos.y(), pos.z(), stack);
|
|
}
|
|
|
|
@Override
|
|
public DispenseConfig createDispenseConfig() {
|
|
return DispenseConfig.builder().uncertainty(DispenseConfig.DEFAULT.uncertainty() * 0.5F).power(DispenseConfig.DEFAULT.power() * 1.25F).build();
|
|
}
|
|
}
|