Files
OldSliceMC/patches/server/0002-Add-PlayerShieldDisableEvent.patch
2022-12-30 15:15:54 -06:00

63 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Fri, 12 Aug 2022 08:16:16 -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 49b983064ea810382b6112f5dc7f93ba4e5710bd..efa3d635251fcf2b3293f9ad25ff1f2500445e80 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1660,7 +1660,10 @@ public abstract class Mob extends LivingEntity {
float f = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F;
if (this.random.nextFloat() < f) {
- player.getCooldowns().addCooldown(Items.SHIELD, 100);
+ //Slice start
+ io.papermc.paper.event.player.PlayerShieldDisableEvent shieldDisableEvent = new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) player.getBukkitEntity(), getBukkitEntity(), 100);
+ if (!shieldDisableEvent.callEvent()) return; // Slice
+ player.getCooldowns().addCooldown(Items.SHIELD, shieldDisableEvent.getCooldown());
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 61597ebe2f9faff43994c475074b87d11905e582..2ebb2e95241caf0393ed5db8f02776f566b88960 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -972,7 +972,7 @@ public abstract class Player extends LivingEntity {
protected void blockUsingShield(LivingEntity attacker) {
super.blockUsingShield(attacker);
if (attacker.canDisableShield()) {
- this.disableShield(true);
+ this.disableShield(true, attacker); // Slice
}
}
@@ -1456,6 +1456,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) {
@@ -1463,7 +1469,12 @@ public abstract class Player extends LivingEntity {
}
if (this.random.nextFloat() < f) {
- this.getCooldowns().addCooldown(Items.SHIELD, 100);
+ // Slice start
+ org.bukkit.entity.Entity finalAttacker = attacker != null ? attacker.getBukkitEntity() : null;
+ io.papermc.paper.event.player.PlayerShieldDisableEvent shieldDisableEvent = new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) getBukkitEntity(), finalAttacker, 100);
+ if (!shieldDisableEvent.callEvent()) return;
+ this.getCooldowns().addCooldown(Items.SHIELD, shieldDisableEvent.getCooldown());
+ // Slice end
this.stopUsingItem();
this.level.broadcastEntityEvent(this, (byte) 30);
}