Files
OldSliceMC/patches/server/0002-Add-PlayerShieldDisableEvent.patch
2021-09-26 15:39:21 -05:00

54 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Tue, 21 Sep 2021 08:33:45 -0500
Subject: [PATCH] Add PlayerShieldDisableEvent
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 8a864238e154e2131834d013652746b7e7a78c97..806975b124bf91ae560dc3a0289f3a298373546d 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1588,6 +1588,7 @@ public abstract class Mob extends LivingEntity {
float f = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F;
if (this.random.nextFloat() < f) {
+ if (!new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) player.getBukkitEntity(), getBukkitEntity()).callEvent()) return; // Slice
player.getCooldowns().addCooldown(Items.SHIELD, 100);
this.level.broadcastEntityEvent(player, (byte) 30);
}
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index cea92f1dc663bf0648b2bd877d86ca380a517bc9..a1d1d8b5fbb5d7f8e980b4c116b8fec34f8878d5 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -936,7 +936,7 @@ public abstract class Player extends LivingEntity {
protected void blockUsingShield(LivingEntity attacker) {
super.blockUsingShield(attacker);
if (attacker.getMainHandItem().getItem() instanceof AxeItem) {
- this.disableShield(true);
+ this.disableShield(true, attacker); // Slice
}
}
@@ -1403,6 +1403,12 @@ public abstract class Player extends LivingEntity {
}
public void disableShield(boolean sprinting) {
+ // Slice start
+ disableShield(sprinting, null);
+ }
+
+ public void disableShield(boolean sprinting, @Nullable LivingEntity attacker) {
+ // Slice end
float f = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F;
if (sprinting) {
@@ -1410,6 +1416,8 @@ public abstract class Player extends LivingEntity {
}
if (this.random.nextFloat() < f) {
+ org.bukkit.entity.Entity finalAttacker = attacker != null ? attacker.getBukkitEntity() : null; // Slice
+ if (!new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) getBukkitEntity(), finalAttacker).callEvent()) return; // Slice
this.getCooldowns().addCooldown(Items.SHIELD, 100);
this.stopUsingItem();
this.level.broadcastEntityEvent(this, (byte) 30);