aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0884-Call-missing-BlockDispenseEvent.patch
blob: d63492c387467f440ce24108972ed429f07b31a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
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 b83af374a33a66a6ceeca119b961eea883bba41c..175b965c92b8b8be9c671e1ee478afa9a2f7bf82 100644
--- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
@@ -1112,6 +1112,13 @@ public interface DispenseItemBehavior {
                 this.setSuccess(true);
                 if (iblockdata.is(Blocks.RESPAWN_ANCHOR)) {
                     if ((Integer) iblockdata.getValue(RespawnAnchorBlock.CHARGE) != 4) {
+                        // Paper start - Call missing BlockDispenseEvent
+                        ItemStack result = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDispenseEvent(pointer, blockposition, stack, this);
+                        if (result != null) {
+                            this.setSuccess(false);
+                            return result;
+                        }
+                        // Paper end - Call missing BlockDispenseEvent
                         RespawnAnchorBlock.charge((Entity) null, worldserver, blockposition, iblockdata);
                         stack.shrink(1);
                     } else {
@@ -1134,6 +1141,13 @@ public interface DispenseItemBehavior {
                 Optional<BlockState> optional = HoneycombItem.getWaxed(iblockdata);
 
                 if (optional.isPresent()) {
+                    // Paper start - Call missing BlockDispenseEvent
+                    ItemStack result = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDispenseEvent(pointer, blockposition, stack, this);
+                    if (result != null) {
+                        this.setSuccess(false);
+                        return result;
+                    }
+                    // Paper end - Call missing BlockDispenseEvent
                     worldserver.setBlockAndUpdate(blockposition, (BlockState) optional.get());
                     worldserver.levelEvent(3003, blockposition, 0);
                     stack.shrink(1);
@@ -1159,6 +1173,12 @@ public interface DispenseItemBehavior {
                     if (!worldserver.getBlockState(blockposition1).is(BlockTags.CONVERTABLE_TO_MUD)) {
                         return this.defaultDispenseItemBehavior.dispense(pointer, stack);
                     } else {
+                        // Paper start - Call missing BlockDispenseEvent
+                        ItemStack result = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDispenseEvent(pointer, blockposition1, stack, this);
+                        if (result != null) {
+                            return result;
+                        }
+                        // Paper end - Call missing BlockDispenseEvent
                         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 7934eea4ede9db90ad2a45a2a5ac64b264b2f91a..c2beeff8f84de23981624890c2a88cf510f4cbab 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -2093,6 +2093,32 @@ public class CraftEventFactory {
     }
     // Paper end
 
+    // Paper start - Call missing BlockDispenseEvent
+    @Nullable
+    public static ItemStack handleBlockDispenseEvent(net.minecraft.core.dispenser.BlockSource pointer, BlockPos to, ItemStack itemStack, net.minecraft.core.dispenser.DispenseItemBehavior instance) {
+        org.bukkit.block.Block bukkitBlock = CraftBlock.at(pointer.level(), pointer.pos());
+        CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemStack.copyWithCount(1));
+
+        org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(bukkitBlock, craftItem.clone(), CraftVector.toBukkit(to));
+        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 itemBehavior = net.minecraft.world.level.block.DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
+            if (itemBehavior != net.minecraft.core.dispenser.DispenseItemBehavior.NOOP && itemBehavior != instance) {
+                itemBehavior.dispense(pointer, eventStack);
+                return itemStack;
+            }
+        }
+        return null;
+    }
+    // Paper end - Call missing BlockDispenseEvent
+
     // Paper start - add EntityFertilizeEggEvent
     /**
      * Calls the {@link io.papermc.paper.event.entity.EntityFertilizeEggEvent}.