aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLulu13022002 <[email protected]>2023-07-03 01:12:07 +0200
committerGitHub <[email protected]>2023-07-02 16:12:07 -0700
commit4356758b645f3d4d91268ac40cd3b682eb3faecf (patch)
tree9c1d554e0043a36515fab389afda6aea9e390124
parent171ba7ccf321ac2be372a3eb3651e4fa6c8b9145 (diff)
downloadPaper-4356758b645f3d4d91268ac40cd3b682eb3faecf.tar.gz
Paper-4356758b645f3d4d91268ac40cd3b682eb3faecf.zip
Call missing BlockDispenseEvents (#8518)
* Call missing BlockDispenseEvent * Avoid duplicate event * Show a single item for event * Move glowstone refill event * rebased --------- Co-authored-by: Jake Potrebic <[email protected]>
-rw-r--r--patches/server/0984-Call-missing-BlockDispenseEvent.patch88
1 files changed, 88 insertions, 0 deletions
diff --git a/patches/server/0984-Call-missing-BlockDispenseEvent.patch b/patches/server/0984-Call-missing-BlockDispenseEvent.patch
new file mode 100644
index 0000000000..db959592eb
--- /dev/null
+++ b/patches/server/0984-Call-missing-BlockDispenseEvent.patch
@@ -0,0 +1,88 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Lulu13022002 <[email protected]>
+Date: Sat, 29 Oct 2022 15:41:56 +0200
+Subject: [PATCH] Call missing BlockDispenseEvent
+
+
+diff --git a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
+index b4f5dbe9022dd20437c15c4f6fbe2ac06dacbadb..70aade6a8d36f8376cc567800258ea6fabb0607f 100644
+--- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
++++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
+@@ -1105,6 +1105,13 @@ public interface DispenseItemBehavior {
+ this.setSuccess(true);
+ if (iblockdata.is(Blocks.RESPAWN_ANCHOR)) {
+ if ((Integer) iblockdata.getValue(RespawnAnchorBlock.CHARGE) != 4) {
++ // Paper start
++ ItemStack result = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDispenseEvent(pointer, blockposition, stack, this);
++ if (result != null) {
++ this.setSuccess(false);
++ return result;
++ }
++ // Paper end
+ RespawnAnchorBlock.charge((Entity) null, worldserver, blockposition, iblockdata);
+ stack.shrink(1);
+ } else {
+@@ -1127,6 +1134,13 @@ public interface DispenseItemBehavior {
+ Optional<BlockState> optional = HoneycombItem.getWaxed(iblockdata);
+
+ if (optional.isPresent()) {
++ // Paper start
++ ItemStack result = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDispenseEvent(pointer, blockposition, stack, this);
++ if (result != null) {
++ this.setSuccess(false);
++ return result;
++ }
++ // Paper end
+ worldserver.setBlockAndUpdate(blockposition, (BlockState) optional.get());
+ worldserver.levelEvent(3003, blockposition, 0);
+ stack.shrink(1);
+@@ -1152,6 +1166,12 @@ public interface DispenseItemBehavior {
+ if (!worldserver.getBlockState(blockposition1).is(BlockTags.CONVERTABLE_TO_MUD)) {
+ return this.defaultDispenseItemBehavior.dispense(pointer, stack);
+ } else {
++ // Paper start
++ ItemStack result = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDispenseEvent(pointer, blockposition1, stack, this);
++ if (result != null) {
++ return result;
++ }
++ // Paper end
+ if (!worldserver.isClientSide) {
+ for (int k = 0; k < 5; ++k) {
+ worldserver.sendParticles(ParticleTypes.SPLASH, (double) blockposition.getX() + worldserver.random.nextDouble(), (double) (blockposition.getY() + 1), (double) blockposition.getZ() + worldserver.random.nextDouble(), 1, 0.0D, 0.0D, 0.0D, 1.0D);
+diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+index c1583340ecaedab0af44501213b2d24f8ad71e0c..568527cccebb5669184026f6cbaf4835ead6792a 100644
+--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+@@ -1986,6 +1986,32 @@ public class CraftEventFactory {
+ }
+ // Paper end
+
++ // Paper start - missing BlockDispenseEvent calls
++ @Nullable
++ public static ItemStack handleBlockDispenseEvent(net.minecraft.core.BlockSource pointer, BlockPos to, ItemStack itemStack, net.minecraft.core.dispenser.DispenseItemBehavior instance) {
++ org.bukkit.block.Block bukkitBlock = pointer.getLevel().getWorld().getBlockAt(pointer.getPos().getX(), pointer.getPos().getY(), pointer.getPos().getZ());
++ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemStack.copyWithCount(1));
++
++ org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(to.getX(), to.getY(), to.getZ()));
++ if (!net.minecraft.world.level.block.DispenserBlock.eventFired) {
++ if (!event.callEvent()) {
++ return itemStack;
++ }
++ }
++
++ if (!event.getItem().equals(craftItem)) {
++ // Chain to handler for new item
++ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
++ net.minecraft.core.dispenser.DispenseItemBehavior idispensebehavior = net.minecraft.world.level.block.DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
++ if (idispensebehavior != net.minecraft.core.dispenser.DispenseItemBehavior.NOOP && idispensebehavior != instance) {
++ idispensebehavior.dispense(pointer, eventStack);
++ return itemStack;
++ }
++ }
++ return null;
++ }
++ // Paper end - missing BlockDispenseEvent calls
++
+ // Paper start - add EntityFertilizeEggEvent
+ /**
+ * Calls the io.papermc.paper.event.entity.EntityFertilizeEggEvent.