WindChargeItem .java

net.minecraft.world.item.WindChargeItem (class, 82 lines): members: PROJECTILE_SHOOT_POWER, createDispenseConfig, shoot, asProjectile, use. imports: Stats.

net.minecraft.world.itemclass82 linescommonextends Item2.8 KB

Implements

API Surface (4)

InteractionResult use(final Level level, final Player player, final InteractionHand hand)
Projectile asProjectile(final Level level, final Position position, final ItemStack itemStack, final Direction direction)
void shoot(final Projectile projectile, final double xd, final double yd, final double zd, final float pow, final float uncertainty)
ProjectileItem.DispenseConfig createDispenseConfig()

Fields & Constants (1)

PROJECTILE_SHOOT_POWER

Full Source

WindChargeItem.java82 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item;
2
3
import net.minecraft.core.Direction;
4
import net.minecraft.core.Position;
5
import net.minecraft.server.level.ServerLevel;
6
import net.minecraft.sounds.SoundEvents;
7
import net.minecraft.sounds.SoundSource;
8
import net.minecraft.stats.Stats;
9
import net.minecraft.util.RandomSource;
10
import net.minecraft.world.InteractionHand;
11
import net.minecraft.world.InteractionResult;
12
import net.minecraft.world.entity.player.Player;
13
import net.minecraft.world.entity.projectile.Projectile;
14
import net.minecraft.world.entity.projectile.hurtingprojectile.windcharge.WindCharge;
15
import net.minecraft.world.level.Level;
16
import net.minecraft.world.level.block.DispenserBlock;
17
import net.minecraft.world.phys.Vec3;
18
19
public class WindChargeItem extends Item implements ProjectileItem {
20
	public static final float PROJECTILE_SHOOT_POWER = 1.5F;
21
22
	public WindChargeItem(final Item.Properties properties) {
23
		super(properties);
24
	}
25
26
	@Override
27
	public InteractionResult use(final Level level, final Player player, final InteractionHand hand) {
28
		ItemStack stack = player.getItemInHand(hand);
29
		if (level instanceof ServerLevel serverLevel) {
30
			Projectile.spawnProjectileFromRotation(
31
				(source, l, itemStack) -> new WindCharge(player, level, player.position().x(), player.getEyePosition().y(), player.position().z()),
32
				serverLevel,
33
				stack,
34
				player,
35
				0.0F,
36
				1.5F,
37
				1.0F
38
			);
39
		}
40
41
		level.playSound(
42
			null,
43
			player.getX(),
44
			player.getY(),
45
			player.getZ(),
46
			SoundEvents.WIND_CHARGE_THROW,
47
			SoundSource.NEUTRAL,
48
			0.5F,
49
			0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)
50
		);
51
		player.awardStat(Stats.ITEM_USED.get(this));
52
		stack.consume(1, player);
53
		return InteractionResult.SUCCESS;
54
	}
55
56
	@Override
57
	public Projectile asProjectile(final Level level, final Position position, final ItemStack itemStack, final Direction direction) {
58
		RandomSource random = level.getRandom();
59
		double dirX = random.triangle(direction.getStepX(), 0.11485000000000001);
60
		double dirY = random.triangle(direction.getStepY(), 0.11485000000000001);
61
		double dirZ = random.triangle(direction.getStepZ(), 0.11485000000000001);
62
		Vec3 dir = new Vec3(dirX, dirY, dirZ);
63
		WindCharge windCharge = new WindCharge(level, position.x(), position.y(), position.z(), dir);
64
		windCharge.setDeltaMovement(dir);
65
		return windCharge;
66
	}
67
68
	@Override
69
	public void shoot(final Projectile projectile, final double xd, final double yd, final double zd, final float pow, final float uncertainty) {
70
	}
71
72
	@Override
73
	public ProjectileItem.DispenseConfig createDispenseConfig() {
74
		return ProjectileItem.DispenseConfig.builder()
75
			.positionFunction((source, direction) -> DispenserBlock.getDispensePosition(source, 1.0, Vec3.ZERO))
76
			.uncertainty(6.6666665F)
77
			.power(1.0F)
78
			.overrideDispenseEvent(1051)
79
			.build();
80
	}
81
}
82

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