PaperMC/paper-server/patches/sources/net/minecraft/world/item/WindChargeItem.java.patch
2018-07-21 03:11:03 -05:00

42 lines
2.2 KiB
Diff

--- a/net/minecraft/world/item/WindChargeItem.java
+++ b/net/minecraft/world/item/WindChargeItem.java
@@ -27,7 +27,7 @@
public InteractionResult use(Level world, Player user, InteractionHand hand) {
ItemStack itemStack = user.getItemInHand(hand);
if (world instanceof ServerLevel serverLevel) {
- Projectile.spawnProjectileFromRotation(
+ final Projectile.Delayed<WindCharge> windCharge = Projectile.spawnProjectileFromRotationDelayed( // Paper - PlayerLaunchProjectileEvent
(world2, shooter, stack) -> new WindCharge(user, world, user.position().x(), user.getEyePosition().y(), user.position().z()),
serverLevel,
itemStack,
@@ -36,6 +36,21 @@
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) windCharge.projectile().getBukkitEntity());
+ if (!event.callEvent() || !windCharge.attemptSpawn()) {
+ user.containerMenu.sendAllDataToRemote();
+ if (user instanceof net.minecraft.server.level.ServerPlayer player) {
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundCooldownPacket(user.getCooldowns().getCooldownGroup(itemStack), 0)); // prevent visual desync of cooldown on the slot
+ }
+ return InteractionResult.FAIL;
+ }
+
+ user.awardStat(Stats.ITEM_USED.get(this));
+ if (event.shouldConsume()) itemStack.consume(1, user);
+ else if (!user.hasInfiniteMaterials()) {
+ user.containerMenu.sendAllDataToRemote();
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
world.playSound(
@@ -48,8 +63,6 @@
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
- user.awardStat(Stats.ITEM_USED.get(this));
- itemStack.consume(1, user);
return InteractionResult.SUCCESS;
}