mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 10:17:38 +01:00
55 lines
2.9 KiB
Diff
55 lines
2.9 KiB
Diff
|
--- a/net/minecraft/world/item/SnowballItem.java
|
||
|
+++ b/net/minecraft/world/item/SnowballItem.java
|
||
|
@@ -23,22 +_,38 @@
|
||
|
@Override
|
||
|
public InteractionResult use(Level level, Player player, InteractionHand hand) {
|
||
|
ItemStack itemInHand = player.getItemInHand(hand);
|
||
|
- level.playSound(
|
||
|
- null,
|
||
|
- player.getX(),
|
||
|
- player.getY(),
|
||
|
- player.getZ(),
|
||
|
- SoundEvents.SNOWBALL_THROW,
|
||
|
- SoundSource.NEUTRAL,
|
||
|
- 0.5F,
|
||
|
- 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)
|
||
|
- );
|
||
|
+ // CraftBukkit start - moved down
|
||
|
if (level instanceof ServerLevel serverLevel) {
|
||
|
- Projectile.spawnProjectileFromRotation(Snowball::new, serverLevel, itemInHand, player, 0.0F, PROJECTILE_SHOOT_POWER, 1.0F);
|
||
|
+ // Paper start - PlayerLaunchProjectileEvent
|
||
|
+ final Projectile.Delayed<Snowball> snowball = Projectile.spawnProjectileFromRotationDelayed(Snowball::new, serverLevel, itemInHand, player, 0.0F, SnowballItem.PROJECTILE_SHOOT_POWER, 1.0F);
|
||
|
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) player.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemInHand), (org.bukkit.entity.Projectile) snowball.projectile().getBukkitEntity());
|
||
|
+ if (event.callEvent() && snowball.attemptSpawn()) {
|
||
|
+ player.awardStat(Stats.ITEM_USED.get(this));
|
||
|
+ if (event.shouldConsume()) {
|
||
|
+ itemInHand.consume(1, player);
|
||
|
+ } else if (player instanceof net.minecraft.server.level.ServerPlayer) {
|
||
|
+ ((net.minecraft.server.level.ServerPlayer) player).getBukkitEntity().updateInventory();
|
||
|
+ }
|
||
|
+ // Paper end - PlayerLaunchProjectileEvent
|
||
|
+
|
||
|
+ level.playSound(
|
||
|
+ null,
|
||
|
+ player.getX(),
|
||
|
+ player.getY(),
|
||
|
+ player.getZ(),
|
||
|
+ SoundEvents.SNOWBALL_THROW,
|
||
|
+ SoundSource.NEUTRAL,
|
||
|
+ 0.5F,
|
||
|
+ 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)
|
||
|
+ );
|
||
|
+ } else { if (player instanceof net.minecraft.server.level.ServerPlayer) { // Paper - PlayerLaunchProjectileEvent - return fail
|
||
|
+ ((net.minecraft.server.level.ServerPlayer) player).getBukkitEntity().updateInventory();
|
||
|
+ } return InteractionResult.FAIL; } // Paper - PlayerLaunchProjectileEvent - return fail
|
||
|
+ // CraftBukkit end
|
||
|
}
|
||
|
|
||
|
- player.awardStat(Stats.ITEM_USED.get(this));
|
||
|
- itemInHand.consume(1, player);
|
||
|
+ // Paper - PlayerLaunchProjectileEvent - moved up
|
||
|
+ // itemInHand.consume(1, player); // CraftBukkit - moved up
|
||
|
return InteractionResult.SUCCESS;
|
||
|
}
|
||
|
|