mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 19:12:22 +01:00
37 lines
2.8 KiB
Diff
37 lines
2.8 KiB
Diff
--- a/net/minecraft/world/item/SnowballItem.java
|
|
+++ b/net/minecraft/world/item/SnowballItem.java
|
|
@@ -25,13 +25,30 @@
|
|
public InteractionResult use(Level world, Player user, InteractionHand hand) {
|
|
ItemStack itemstack = user.getItemInHand(hand);
|
|
|
|
- world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
|
+ // CraftBukkit start - moved down
|
|
+ // world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
|
if (world instanceof ServerLevel worldserver) {
|
|
- Projectile.spawnProjectileFromRotation(Snowball::new, worldserver, itemstack, user, 0.0F, SnowballItem.PROJECTILE_SHOOT_POWER, 1.0F);
|
|
+ // Paper start - PlayerLaunchProjectileEvent
|
|
+ final Projectile.Delayed<Snowball> snowball = Projectile.spawnProjectileFromRotationDelayed(Snowball::new, worldserver, itemstack, user, 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) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) snowball.projectile().getBukkitEntity());
|
|
+ if (event.callEvent() && snowball.attemptSpawn()) {
|
|
+ user.awardStat(Stats.ITEM_USED.get(this));
|
|
+ if (event.shouldConsume()) {
|
|
+ itemstack.consume(1, user);
|
|
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
|
|
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
|
|
+ }
|
|
+ // Paper end - PlayerLaunchProjectileEvent
|
|
+
|
|
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
|
+ } else { if (user instanceof net.minecraft.server.level.ServerPlayer) { // Paper - PlayerLaunchProjectileEvent - return fail
|
|
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
|
|
+ } return InteractionResult.FAIL; } // Paper - PlayerLaunchProjectileEvent - return fail
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
- user.awardStat(Stats.ITEM_USED.get(this));
|
|
- itemstack.consume(1, user);
|
|
+ // Paper - PlayerLaunchProjectileEvent - moved up
|
|
+ // itemstack.consume(1, entityhuman); // CraftBukkit - moved up
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
|