Paper/patches/server/0948-Call-missing-BlockDispenseEvent.patch
Nassim Jahnke e035fd7034
Updated Upstream (Bukkit/CraftBukkit/Spigot)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities
f23325b6 Add API for per-world simulation distances
26e1774e Add API for per-world view distances
0b541e60 Add PlayerLoginEvent#getRealAddress
5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types

CraftBukkit Changes:
bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs
7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst
752aac669 Implement APIs for per world view and simulation distances
57d7ef433 Preserve empty enchantment tags for glow effect
465ec3fb4 Remove connected check on setScoreboard
f90ce621e Use one PermissibleBase for all command blocks
5876cca44 SPIGOT-7550: Fix creation of Arrow instances
f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition
9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item

Spigot Changes:
ed9ba9a4 Drop no longer required patch ignoring -o option
86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message
aa7cde7a Remove obsolete APIs for per world view and simulation distances
6dff577e Remove obsolete patch preserving empty `ench` tags
a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress
1b02f5d6 Remove obsolete connected check on setScoreboard patch
acf717eb Remove obsolete command block PermissibleBase patch
053fa2a9 Remove redundant patch dealing with null tile entities
2023-12-26 00:18:13 +01:00

89 lines
5.3 KiB
Diff

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 dd017c33ff89a516022378160410bc41cce9222e..105bb94b844c5ee85b53aca95360e7b2caf374cc 100644
--- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
@@ -1114,6 +1114,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 {
@@ -1136,6 +1143,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);
@@ -1161,6 +1175,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 864ff2d3c8e2e2bef744e8048ba0cdbb42787268..c62396041c1546f3136ab6de3b174983f49287b3 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -2098,6 +2098,32 @@ public class CraftEventFactory {
}
// Paper end
+ // Paper start - missing BlockDispenseEvent calls
+ @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 = pointer.level().getWorld().getBlockAt(pointer.pos().getX(), pointer.pos().getY(), pointer.pos().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.