151 lines
9.2 KiB
Diff
151 lines
9.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Fri, 30 Dec 2022 10:03:50 -0600
|
|
Subject: [PATCH] Add BlockDestroyedByNeighborEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/MappedRegistry.java b/src/main/java/net/minecraft/core/MappedRegistry.java
|
|
index 834a6f2eb2d6c0aa3afd450034f32b4e008b3a3c..3b2090503a4208c416167f5c70d3d8a4121cf916 100644
|
|
--- a/src/main/java/net/minecraft/core/MappedRegistry.java
|
|
+++ b/src/main/java/net/minecraft/core/MappedRegistry.java
|
|
@@ -335,7 +335,7 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
|
|
|
|
@Override
|
|
public Registry<T> freeze() {
|
|
- if (this.true) { // Slice (a TODO in Paper, thanks Owen)
|
|
+ if (true) { // Slice (a TODO in Paper, thanks Owen)
|
|
return this;
|
|
} else {
|
|
this.frozen = true;
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
index 0989c7deef13ee202560fb2f44cbd273f9817f91..168e68f1a93b2a134952cd88a35501a3290694e9 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -410,6 +410,7 @@ public class ServerPlayerGameMode {
|
|
org.bukkit.block.BlockState state = bblock.getState();
|
|
level.captureDrops = new ArrayList<>();
|
|
// CraftBukkit end
|
|
+ level.pendingPlayerBlockEvents.put(pos, new Level.PendingBlockEvent(pos, this.player)); // Paper
|
|
block.playerWillDestroy(this.level, pos, iblockdata, this.player);
|
|
boolean flag = this.level.removeBlock(pos, false);
|
|
|
|
@@ -438,6 +439,7 @@ public class ServerPlayerGameMode {
|
|
// CraftBukkit start
|
|
java.util.List<net.minecraft.world.entity.item.ItemEntity> itemsToDrop = level.captureDrops; // Paper - store current list
|
|
level.captureDrops = null; // Paper - Remove this earlier so that we can actually drop stuff
|
|
+ level.pendingPlayerBlockEvents.remove(pos); // Paper
|
|
if (event.isDropItems()) {
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, itemsToDrop); // Paper - use stored ref
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
index 6ed921621f66dc4bfec66a307db24defb3caf380..c5a8e12055c46015b499eadf5614597c77a39e90 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
@@ -353,6 +353,7 @@ public final class ItemStack {
|
|
}
|
|
}
|
|
Item item = this.getItem();
|
|
+ if (entityhuman != null) world.pendingPlayerBlockEvents.put(blockposition, new Level.PendingBlockEvent(blockposition, entityhuman)); // Paper
|
|
InteractionResult enuminteractionresult = item.useOn(itemactioncontext);
|
|
CompoundTag newData = this.getTagClone();
|
|
int newCount = this.getCount();
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 264a6bc9f174a42dfeed4822dbb1bd3cc608d108..1914c22c9d3cdc338a9c5ddf03ddf00cf7eb457d 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -181,6 +181,27 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
public final Map<Explosion.CacheKey, Float> explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions
|
|
public java.util.ArrayDeque<net.minecraft.world.level.block.RedstoneTorchBlock.Toggle> redstoneUpdateInfos; // Paper - Move from Map in BlockRedstoneTorch to here
|
|
|
|
+ // Paper start - Holder class used to track what Player is responsible the last block event
|
|
+ public static class PendingBlockEvent {
|
|
+
|
|
+ public final BlockPos block;
|
|
+ public final Player player;
|
|
+ public @Nullable BlockPos sourceBlock;
|
|
+
|
|
+ public PendingBlockEvent(BlockPos block, Player player) {
|
|
+ this(block, player, null);
|
|
+ }
|
|
+
|
|
+ public PendingBlockEvent(BlockPos block, Player player, @Nullable BlockPos sourceBlock) {
|
|
+ this.block = block;
|
|
+ this.player = player;
|
|
+ this.sourceBlock = sourceBlock;
|
|
+ }
|
|
+
|
|
+ }
|
|
+ public final Map<BlockPos, PendingBlockEvent> pendingPlayerBlockEvents = new HashMap<>();
|
|
+ // Paper end
|
|
+
|
|
// Paper start - fix and optimise world upgrading
|
|
// copied from below
|
|
public static ResourceKey<DimensionType> getDimensionKey(DimensionType manager) {
|
|
@@ -662,6 +683,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
if (!this.preventPoiUpdated) {
|
|
this.onBlockStateChange(blockposition, iblockdata1, iblockdata2);
|
|
}
|
|
+ pendingPlayerBlockEvents.remove(blockposition); // Paper
|
|
// CraftBukkit end
|
|
}
|
|
}
|
|
@@ -683,6 +705,17 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
if (iblockdata.isAir()) {
|
|
return false;
|
|
} else {
|
|
+ // Paper start
|
|
+ PendingBlockEvent blockEvent = pendingPlayerBlockEvents.get(pos);
|
|
+ if (blockEvent != null && blockEvent.sourceBlock != null) {
|
|
+ io.papermc.paper.event.block.BlockDestroyedByNeighborEvent event =
|
|
+ new io.papermc.paper.event.block.BlockDestroyedByNeighborEvent(org.bukkit.craftbukkit.block.CraftBlock.at(this, pos),
|
|
+ (org.bukkit.entity.Player) blockEvent.player.getBukkitEntity(),
|
|
+ org.bukkit.craftbukkit.block.CraftBlock.at(this, blockEvent.sourceBlock));
|
|
+ event.callEvent();
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
FluidState fluid = this.getFluidState(pos);
|
|
// Paper start - while the above setAir method is named same and looks very similar
|
|
// they are NOT used with same intent and the above should not fire this event. The above method is more of a BlockSetToAirEvent,
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java b/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
|
|
index e234ae13fe9793db237adb6f6216fa32638cfc4f..c126742149b10cc67caa18c7c4d8e1c7108c6c15 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
|
|
@@ -105,6 +105,15 @@ public class DoublePlantBlock extends BushBlock {
|
|
BlockPos blockposition1 = pos.below();
|
|
BlockState iblockdata1 = world.getBlockState(blockposition1);
|
|
|
|
+ Level.PendingBlockEvent blockEvent = world.pendingPlayerBlockEvents.remove(pos);
|
|
+ if (blockEvent != null) {
|
|
+ io.papermc.paper.event.block.BlockDestroyedByNeighborEvent event =
|
|
+ new io.papermc.paper.event.block.BlockDestroyedByNeighborEvent(org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition1),
|
|
+ (org.bukkit.entity.Player) blockEvent.player.getBukkitEntity(),
|
|
+ org.bukkit.craftbukkit.block.CraftBlock.at(world, pos));
|
|
+ if (!event.callEvent()) return;
|
|
+ }
|
|
+
|
|
if (iblockdata1.is(state.getBlock()) && iblockdata1.getValue(DoublePlantBlock.HALF) == DoubleBlockHalf.LOWER) {
|
|
BlockState iblockdata2 = iblockdata1.getFluidState().is((Fluid) Fluids.WATER) ? Blocks.WATER.defaultBlockState() : Blocks.AIR.defaultBlockState();
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
index 25ce337ed266be7bafeacd9eb6f53a9474775fc5..cd4a84f8ab08dbed23a6cd15b90c0d530728b85f 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
@@ -1016,6 +1016,16 @@ public abstract class BlockBehaviour implements FeatureElement {
|
|
Direction enumdirection = aenumdirection[l];
|
|
|
|
blockposition_mutableblockposition.setWithOffset(pos, enumdirection);
|
|
+ // Paper start - Propagate the PendingBlockEvent from the current blockPos to the next block
|
|
+ // if it will break (!canSurvive)
|
|
+ if (this.getMaterial() == Material.AIR && !world.getBlockState(blockposition_mutableblockposition).canSurvive(world, blockposition_mutableblockposition)) {
|
|
+ Level.PendingBlockEvent blockEvent = ((Level) world).pendingPlayerBlockEvents.get(pos);
|
|
+ if (blockEvent != null) {
|
|
+ BlockPos blockPosCopy = blockposition_mutableblockposition.immutable();
|
|
+ ((Level) world).pendingPlayerBlockEvents.put(blockPosCopy, new Level.PendingBlockEvent(blockPosCopy, blockEvent.player, pos));
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
world.neighborShapeChanged(enumdirection.getOpposite(), this.asState(), blockposition_mutableblockposition, pos, flags, maxUpdateDepth);
|
|
}
|
|
|