minecraft-src/net/minecraft/world/entity/projectile/ThrownLingeringPotion.java
2025-09-18 12:27:44 +00:00

46 lines
1.6 KiB
Java

package net.minecraft.world.entity.projectile;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.HitResult;
public class ThrownLingeringPotion extends AbstractThrownPotion {
public ThrownLingeringPotion(EntityType<? extends ThrownLingeringPotion> entityType, Level level) {
super(entityType, level);
}
public ThrownLingeringPotion(Level level, LivingEntity owner, ItemStack item) {
super(EntityType.LINGERING_POTION, level, owner, item);
}
public ThrownLingeringPotion(Level level, double x, double y, double z, ItemStack item) {
super(EntityType.LINGERING_POTION, level, x, y, z, item);
}
@Override
protected Item getDefaultItem() {
return Items.LINGERING_POTION;
}
@Override
public void onHitAsPotion(ServerLevel level, ItemStack stack, HitResult hitResult) {
AreaEffectCloud areaEffectCloud = new AreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ());
if (this.getOwner() instanceof LivingEntity livingEntity) {
areaEffectCloud.setOwner(livingEntity);
}
areaEffectCloud.setRadius(3.0F);
areaEffectCloud.setRadiusOnUse(-0.5F);
areaEffectCloud.setDuration(600);
areaEffectCloud.setWaitTime(10);
areaEffectCloud.setRadiusPerTick(-areaEffectCloud.getRadius() / areaEffectCloud.getDuration());
areaEffectCloud.applyComponentsFromItemStack(stack);
level.addFreshEntity(areaEffectCloud);
}
}