47 lines
1.7 KiB
Java
47 lines
1.7 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.Position;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
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.level.Level;
|
|
|
|
public class ThrowablePotionItem extends PotionItem implements ProjectileItem {
|
|
public ThrowablePotionItem(Item.Properties properties) {
|
|
super(properties);
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
|
|
ItemStack itemStack = player.getItemInHand(usedHand);
|
|
if (!level.isClientSide) {
|
|
ThrownPotion thrownPotion = new ThrownPotion(level, player);
|
|
thrownPotion.setItem(itemStack);
|
|
thrownPotion.shootFromRotation(player, player.getXRot(), player.getYRot(), -20.0F, 0.5F, 1.0F);
|
|
level.addFreshEntity(thrownPotion);
|
|
}
|
|
|
|
player.awardStat(Stats.ITEM_USED.get(this));
|
|
itemStack.consume(1, player);
|
|
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide());
|
|
}
|
|
|
|
@Override
|
|
public Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
|
ThrownPotion thrownPotion = new ThrownPotion(level, pos.x(), pos.y(), pos.z());
|
|
thrownPotion.setItem(stack);
|
|
return thrownPotion;
|
|
}
|
|
|
|
@Override
|
|
public ProjectileItem.DispenseConfig createDispenseConfig() {
|
|
return ProjectileItem.DispenseConfig.builder()
|
|
.uncertainty(ProjectileItem.DispenseConfig.DEFAULT.uncertainty() * 0.5F)
|
|
.power(ProjectileItem.DispenseConfig.DEFAULT.power() * 1.25F)
|
|
.build();
|
|
}
|
|
}
|