Add EntityAttemptSmashAttackEvent (#12113)

This commit is contained in:
Chaosdave34
2025-02-16 20:19:28 +01:00
committed by GitHub
parent 7bee99714a
commit b9023b5dc3
2 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
--- a/net/minecraft/world/item/MaceItem.java
+++ b/net/minecraft/world/item/MaceItem.java
@@ -61,7 +_,13 @@
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
- if (canSmashAttack(attacker)) {
+ // Paper start - Add EntityAttemptSmashAttackEvent
+ final boolean canSmashAttack = canSmashAttack(attacker);
+ io.papermc.paper.event.entity.EntityAttemptSmashAttackEvent event = new io.papermc.paper.event.entity.EntityAttemptSmashAttackEvent(attacker.getBukkitLivingEntity(), target.getBukkitLivingEntity(), stack.asBukkitCopy(), canSmashAttack);
+ event.callEvent();
+ final org.bukkit.event.Event.Result result = event.getResult();
+ if (result == org.bukkit.event.Event.Result.ALLOW || (canSmashAttack && result == org.bukkit.event.Event.Result.DEFAULT)) {
+ // Paper end - Add EntityAttemptSmashAttackEvent
ServerLevel serverLevel = (ServerLevel)attacker.level();
attacker.setDeltaMovement(attacker.getDeltaMovement().with(Direction.Axis.Y, 0.01F));
if (attacker instanceof ServerPlayer serverPlayer) {