ThrownLingeringPotion .java

net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownLingeringPotion (class): members: onHitAsPotion, getDefaultItem. imports: HitResult.

net.minecraft.world.entity.projectile.throwableitemprojectileclass55 linescommonextends AbstractThrownPotion2.0 KB

API Surface (2)

Item getDefaultItem()
void onHitAsPotion(final ServerLevel level, final ItemStack potionItem, final HitResult hitResult)

Full Source

ThrownLingeringPotion.java55 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.projectile.throwableitemprojectile;
2
3
import net.minecraft.server.level.ServerLevel;
4
import net.minecraft.world.entity.AreaEffectCloud;
5
import net.minecraft.world.entity.EntityType;
6
import net.minecraft.world.entity.EntityTypes;
7
import net.minecraft.world.entity.LivingEntity;
8
import net.minecraft.world.item.Item;
9
import net.minecraft.world.item.ItemStack;
10
import net.minecraft.world.item.Items;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.phys.EntityHitResult;
13
import net.minecraft.world.phys.HitResult;
14
15
public class ThrownLingeringPotion extends AbstractThrownPotion {
16
	public ThrownLingeringPotion(final EntityType<? extends ThrownLingeringPotion> type, final Level level) {
17
		super(type, level);
18
	}
19
20
	public ThrownLingeringPotion(final Level level, final LivingEntity owner, final ItemStack itemStack) {
21
		super(EntityTypes.LINGERING_POTION, level, owner, itemStack);
22
	}
23
24
	public ThrownLingeringPotion(final Level level, final double x, final double y, final double z, final ItemStack itemStack) {
25
		super(EntityTypes.LINGERING_POTION, level, x, y, z, itemStack);
26
	}
27
28
	@Override
29
	protected Item getDefaultItem() {
30
		return Items.LINGERING_POTION;
31
	}
32
33
	@Override
34
	public void onHitAsPotion(final ServerLevel level, final ItemStack potionItem, final HitResult hitResult) {
35
		AreaEffectCloud cloud;
36
		if (hitResult instanceof EntityHitResult entityHitResult) {
37
			cloud = new AreaEffectCloud(this.level(), entityHitResult.getEntity().getX(), entityHitResult.getEntity().getY(), entityHitResult.getEntity().getZ());
38
		} else {
39
			cloud = new AreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ());
40
		}
41
42
		if (this.getOwner() instanceof LivingEntity livingEntity) {
43
			cloud.setOwner(livingEntity);
44
		}
45
46
		cloud.setRadius(3.0F);
47
		cloud.setRadiusOnUse(-0.5F);
48
		cloud.setDuration(600);
49
		cloud.setWaitTime(10);
50
		cloud.setRadiusPerTick(-cloud.getRadius() / cloud.getDuration());
51
		cloud.applyComponentsFromItemStack(potionItem);
52
		level.addFreshEntity(cloud);
53
	}
54
}
55

Decompiled Minecraft 26.3 source of ThrownLingeringPotion (net/minecraft/world/entity/projectile/throwableitemprojectile/ThrownLingeringPotion.java) with Mojang official mappings, stored verbatim on the site.