minecraft-src/net/minecraft/world/entity/projectile/ThrownLingeringPotion.java
2025-07-04 03:45:38 +03:00

47 lines
1.7 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.Entity;
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 org.jetbrains.annotations.Nullable;
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, @Nullable Entity entity) {
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);
}
}