EnderpearlItem .java

net.minecraft.world.item.EnderpearlItem (class): members: PROJECTILE_SHOOT_POWER, use. imports: ThrownEnderpearl, Projectile, Stats, InteractionHand.

net.minecraft.world.itemclass43 linescommonextends Item1.3 KB

API Surface (1)

InteractionResult use(final Level level, final Player player, final InteractionHand hand)

Fields & Constants (1)

PROJECTILE_SHOOT_POWER

Full Source

EnderpearlItem.java43 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item;
2
3
import net.minecraft.server.level.ServerLevel;
4
import net.minecraft.sounds.SoundEvents;
5
import net.minecraft.sounds.SoundSource;
6
import net.minecraft.stats.Stats;
7
import net.minecraft.world.InteractionHand;
8
import net.minecraft.world.InteractionResult;
9
import net.minecraft.world.entity.player.Player;
10
import net.minecraft.world.entity.projectile.Projectile;
11
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownEnderpearl;
12
import net.minecraft.world.level.Level;
13
14
public class EnderpearlItem extends Item {
15
	public static final float PROJECTILE_SHOOT_POWER = 1.5F;
16
17
	public EnderpearlItem(final Item.Properties properties) {
18
		super(properties);
19
	}
20
21
	@Override
22
	public InteractionResult use(final Level level, final Player player, final InteractionHand hand) {
23
		ItemStack itemStack = player.getItemInHand(hand);
24
		level.playSound(
25
			null,
26
			player.getX(),
27
			player.getY(),
28
			player.getZ(),
29
			SoundEvents.ENDER_PEARL_THROW,
30
			SoundSource.NEUTRAL,
31
			0.5F,
32
			0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)
33
		);
34
		if (level instanceof ServerLevel serverLevel) {
35
			Projectile.spawnProjectileFromRotation(ThrownEnderpearl::new, serverLevel, itemStack, player, 0.0F, 1.5F, 1.0F);
36
		}
37
38
		player.awardStat(Stats.ITEM_USED.get(this));
39
		itemStack.consume(1, player);
40
		return InteractionResult.SUCCESS;
41
	}
42
}
43

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