From b29ecd4c226e0aedf95d3eca2bc4a0cae8f5d010 Mon Sep 17 00:00:00 2001 From: aerulion Date: Tue, 22 Aug 2023 05:07:18 +0200 Subject: [PATCH] Expose clicked BlockFace during BlockDamageEvent (#9632) --- LICENSE.md | 1 + ...ed-BlockFace-during-BlockDamageEvent.patch | 42 +++++++++++++++++++ ...ed-BlockFace-during-BlockDamageEvent.patch | 39 +++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 patches/api/0429-Expose-clicked-BlockFace-during-BlockDamageEvent.patch create mode 100644 patches/server/1015-Expose-clicked-BlockFace-during-BlockDamageEvent.patch diff --git a/LICENSE.md b/LICENSE.md index b1706a76d6..b26adb448a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -61,4 +61,5 @@ Emily dawon Ollie <69084614+olijeffers0n@users.noreply.github.com> Oliwier Miodun +aerulion ``` diff --git a/patches/api/0429-Expose-clicked-BlockFace-during-BlockDamageEvent.patch b/patches/api/0429-Expose-clicked-BlockFace-during-BlockDamageEvent.patch new file mode 100644 index 0000000000..0358060657 --- /dev/null +++ b/patches/api/0429-Expose-clicked-BlockFace-during-BlockDamageEvent.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: aerulion +Date: Mon, 21 Aug 2023 04:36:07 +0200 +Subject: [PATCH] Expose clicked BlockFace during BlockDamageEvent + + +diff --git a/src/main/java/org/bukkit/event/block/BlockDamageEvent.java b/src/main/java/org/bukkit/event/block/BlockDamageEvent.java +index cd04a0bd9d232857408b38605787016a217cb8d2..0e4751f9844dcbfcfb97af21f9462e9662771709 100644 +--- a/src/main/java/org/bukkit/event/block/BlockDamageEvent.java ++++ b/src/main/java/org/bukkit/event/block/BlockDamageEvent.java +@@ -19,9 +19,12 @@ public class BlockDamageEvent extends BlockEvent implements Cancellable { + private boolean instaBreak; + private boolean cancel; + private final ItemStack itemstack; ++ private final org.bukkit.block.BlockFace blockFace; // Paper - Expose BlockFace + +- public BlockDamageEvent(@NotNull final Player player, @NotNull final Block block, @NotNull final ItemStack itemInHand, final boolean instaBreak) { ++ @org.jetbrains.annotations.ApiStatus.Internal // Paper ++ public BlockDamageEvent(@NotNull final Player player, @NotNull final Block block, @NotNull final org.bukkit.block.BlockFace blockFace, @NotNull final ItemStack itemInHand, final boolean instaBreak) { // Paper - Expose BlockFace + super(block); ++ this.blockFace = blockFace; // Paper - Expose BlockFace + this.instaBreak = instaBreak; + this.player = player; + this.itemstack = itemInHand; +@@ -67,6 +70,17 @@ public class BlockDamageEvent extends BlockEvent implements Cancellable { + public ItemStack getItemInHand() { + return itemstack; + } ++ // Paper start - Expose BlockFace ++ /** ++ * Gets the BlockFace the player is interacting with. ++ * ++ * @return The BlockFace clicked to damage the block ++ */ ++ @NotNull ++ public org.bukkit.block.BlockFace getBlockFace() { ++ return this.blockFace; ++ } ++ //Paper end + + @Override + public boolean isCancelled() { diff --git a/patches/server/1015-Expose-clicked-BlockFace-during-BlockDamageEvent.patch b/patches/server/1015-Expose-clicked-BlockFace-during-BlockDamageEvent.patch new file mode 100644 index 0000000000..af6d906a2c --- /dev/null +++ b/patches/server/1015-Expose-clicked-BlockFace-during-BlockDamageEvent.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: aerulion +Date: Mon, 21 Aug 2023 04:36:07 +0200 +Subject: [PATCH] Expose clicked BlockFace during BlockDamageEvent + + +diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java +index 9a17193c9fe26c9c0390906b4c1f9d619ccba249..618ab9a2903f6d4139acd4aaa2e6db0a26e88ba9 100644 +--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java ++++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java +@@ -258,7 +258,7 @@ public class ServerPlayerGameMode { + } + return; + } +- org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, pos, this.player.getInventory().getSelected(), f >= 1.0f); ++ org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, pos, direction, this.player.getInventory().getSelected(), f >= 1.0f); // Paper - Expose BlockFace + + if (blockEvent.isCancelled()) { + // Let the client know the block still exists +diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +index 26e1a9002d675245d4cf91e6682605314b078fb2..676c44f688c41df66e304db30a05d6cc967bcf99 100644 +--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java ++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +@@ -648,13 +648,13 @@ public class CraftEventFactory { + /** + * BlockDamageEvent + */ +- public static BlockDamageEvent callBlockDamageEvent(ServerPlayer who, BlockPos pos, ItemStack itemstack, boolean instaBreak) { ++ public static BlockDamageEvent callBlockDamageEvent(ServerPlayer who, BlockPos pos, Direction direction, ItemStack itemstack, boolean instaBreak) { // Paper - Expose BlockFace + Player player = who.getBukkitEntity(); + CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack); + + Block blockClicked = CraftBlock.at(who.level(), pos); + +- BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak); ++ BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, CraftBlock.notchToBlockFace(direction), itemInHand, instaBreak); // Paper - Expose BlockFace + player.getServer().getPluginManager().callEvent(event); + + return event;