mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +01:00
Expose clicked BlockFace during BlockDamageEvent (#9632)
This commit is contained in:
parent
2be57c6943
commit
b29ecd4c22
@ -61,4 +61,5 @@ Emily <emilia.lopezf.1999@gmail.com>
|
||||
dawon <dawon@dawon.eu>
|
||||
Ollie <69084614+olijeffers0n@users.noreply.github.com>
|
||||
Oliwier Miodun <naczs@blueflow.pl>
|
||||
aerulion <aerulion@gmail.com>
|
||||
```
|
||||
|
@ -0,0 +1,42 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: aerulion <aerulion@gmail.com>
|
||||
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() {
|
@ -0,0 +1,39 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: aerulion <aerulion@gmail.com>
|
||||
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;
|
Loading…
Reference in New Issue
Block a user