ThrownExperienceBottle .java

net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownExperienceBottle (class, 60 lines): members: getDefaultItem, onHit, getDefaultGravity.

net.minecraft.world.entity.projectile.throwableitemprojectileclass60 linescommonextends ThrowableItemProjectile2.0 KB

API Surface (3)

Item getDefaultItem()
double getDefaultGravity()
void onHit(final HitResult hitResult)

Full Source

ThrownExperienceBottle.java60 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.EntityType;
5
import net.minecraft.world.entity.EntityTypes;
6
import net.minecraft.world.entity.ExperienceOrb;
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.BlockHitResult;
13
import net.minecraft.world.phys.HitResult;
14
import net.minecraft.world.phys.Vec3;
15
16
public class ThrownExperienceBottle extends ThrowableItemProjectile {
17
	public ThrownExperienceBottle(final EntityType<? extends ThrownExperienceBottle> type, final Level level) {
18
		super(type, level);
19
	}
20
21
	public ThrownExperienceBottle(final Level level, final LivingEntity mob, final ItemStack itemStack) {
22
		super(EntityTypes.EXPERIENCE_BOTTLE, mob, level, itemStack);
23
	}
24
25
	public ThrownExperienceBottle(final Level level, final double x, final double y, final double z, final ItemStack itemStack) {
26
		super(EntityTypes.EXPERIENCE_BOTTLE, x, y, z, level, itemStack);
27
	}
28
29
	@Override
30
	protected Item getDefaultItem() {
31
		return Items.EXPERIENCE_BOTTLE;
32
	}
33
34
	@Override
35
	protected double getDefaultGravity() {
36
		return 0.07;
37
	}
38
39
	@Override
40
	protected void onHit(final HitResult hitResult) {
41
		super.onHit(hitResult);
42
		if (this.level() instanceof ServerLevel level) {
43
			level.levelEvent(2002, this.blockPosition(), -13083194);
44
			if (!this.isSilent()) {
45
				level.levelEvent(1053, this.blockPosition(), 0);
46
			}
47
48
			int xpCount = 3 + this.random.nextInt(5) + this.random.nextInt(5);
49
			if (hitResult instanceof BlockHitResult blockHitResult) {
50
				Vec3 blockNormalHit = blockHitResult.getDirection().getUnitVec3();
51
				ExperienceOrb.awardWithDirection(level, hitResult.getLocation(), blockNormalHit, xpCount);
52
			} else {
53
				ExperienceOrb.awardWithDirection(level, hitResult.getLocation(), this.getDeltaMovement().scale(-1.0), xpCount);
54
			}
55
56
			this.discard();
57
		}
58
	}
59
}
60

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