SplashPotionItem .java

net.minecraft.world.item.SplashPotionItem (class, 45 lines): members: createPotion, use. imports: ThrownSplashPotion, AbstractThrownPotion, Position.

net.minecraft.world.itemclass45 linescommonextends ThrowablePotionItem1.5 KB

API Surface (3)

InteractionResult use(final Level level, final Player player, final InteractionHand hand)
AbstractThrownPotion createPotion(final ServerLevel level, final LivingEntity owner, final ItemStack itemStack)
AbstractThrownPotion createPotion(final Level level, final Position position, final ItemStack itemStack)

Full Source

SplashPotionItem.java45 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item;
2
3
import net.minecraft.core.Position;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.sounds.SoundEvents;
6
import net.minecraft.sounds.SoundSource;
7
import net.minecraft.world.InteractionHand;
8
import net.minecraft.world.InteractionResult;
9
import net.minecraft.world.entity.LivingEntity;
10
import net.minecraft.world.entity.player.Player;
11
import net.minecraft.world.entity.projectile.throwableitemprojectile.AbstractThrownPotion;
12
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownSplashPotion;
13
import net.minecraft.world.level.Level;
14
15
public class SplashPotionItem extends ThrowablePotionItem {
16
	public SplashPotionItem(final Item.Properties properties) {
17
		super(properties);
18
	}
19
20
	@Override
21
	public InteractionResult use(final Level level, final Player player, final InteractionHand hand) {
22
		level.playSound(
23
			null,
24
			player.getX(),
25
			player.getY(),
26
			player.getZ(),
27
			SoundEvents.SPLASH_POTION_THROW,
28
			SoundSource.PLAYERS,
29
			0.5F,
30
			0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)
31
		);
32
		return super.use(level, player, hand);
33
	}
34
35
	@Override
36
	protected AbstractThrownPotion createPotion(final ServerLevel level, final LivingEntity owner, final ItemStack itemStack) {
37
		return new ThrownSplashPotion(level, owner, itemStack);
38
	}
39
40
	@Override
41
	protected AbstractThrownPotion createPotion(final Level level, final Position position, final ItemStack itemStack) {
42
		return new ThrownSplashPotion(level, position.x(), position.y(), position.z(), itemStack);
43
	}
44
}
45

Decompiled Minecraft 26.3 source of SplashPotionItem (net/minecraft/world/item/SplashPotionItem.java) with Mojang official mappings, stored verbatim on the site.