mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Expose clicked BlockFace during BlockDamageEvent (#9632)
This commit is contained in:
parent
1316321c7f
commit
dad6cfe6c4
@ -61,4 +61,5 @@ Emily <emilia.lopezf.1999@gmail.com>
|
|||||||
dawon <dawon@dawon.eu>
|
dawon <dawon@dawon.eu>
|
||||||
Ollie <69084614+olijeffers0n@users.noreply.github.com>
|
Ollie <69084614+olijeffers0n@users.noreply.github.com>
|
||||||
Oliwier Miodun <naczs@blueflow.pl>
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/event/block/BlockDamageEvent.java
|
||||||
|
+++ b/src/main/java/org/bukkit/event/block/BlockDamageEvent.java
|
||||||
|
@@ -0,0 +0,0 @@ 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;
|
||||||
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||||
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||||
|
@@ -0,0 +0,0 @@ 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