aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0707-Add-BlockBreakBlockEvent.patch
blob: b7f264d94f0d131c89277f568f735a9b67694051 (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 3 Jan 2021 17:58:11 -0800
Subject: [PATCH] Add BlockBreakBlockEvent


diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
index 6b4cd795f23bd8d51dff5f2b72f588ca51404b99..a80f4dc0a642c744223a155232291ace6e007636 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -331,6 +331,23 @@ public class Block extends BlockBehaviour implements ItemLike {
         }
 
     }
+    // Paper start
+    public static boolean dropResources(BlockState state, LevelAccessor world, BlockPos pos, @Nullable BlockEntity blockEntity, BlockPos source) {
+        if (world instanceof ServerLevel) {
+            List<org.bukkit.inventory.ItemStack> items = com.google.common.collect.Lists.newArrayList();
+            for (net.minecraft.world.item.ItemStack drop : net.minecraft.world.level.block.Block.getDrops(state, world.getMinecraftWorld(), pos, blockEntity)) {
+                items.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(drop));
+            }
+            io.papermc.paper.event.block.BlockBreakBlockEvent event = new io.papermc.paper.event.block.BlockBreakBlockEvent(org.bukkit.craftbukkit.block.CraftBlock.at(world, pos), org.bukkit.craftbukkit.block.CraftBlock.at(world, source), items);
+            event.callEvent();
+            for (var drop : event.getDrops()) {
+                popResource(world.getMinecraftWorld(), pos, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(drop));
+            }
+            state.spawnAfterBreak(world.getMinecraftWorld(), pos, ItemStack.EMPTY);
+        }
+        return true;
+    }
+    // Paper end
 
     public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack stack) {
         if (world instanceof ServerLevel) {
diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
index f4f49cc4109d4ae72c0a50f7acbd181d05bf415a..322b3119682fbab5e790ce9255e96a519f03143d 100644
--- a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
@@ -399,7 +399,7 @@ public class PistonBaseBlock extends DirectionalBlock {
                 iblockdata1 = world.getBlockState(blockposition3);
                 BlockEntity tileentity = iblockdata1.hasBlockEntity() ? world.getBlockEntity(blockposition3) : null;
 
-                dropResources(iblockdata1, world, blockposition3, tileentity);
+                dropResources(iblockdata1, world, blockposition3, tileentity, pos); // Paper
                 world.setBlock(blockposition3, Blocks.AIR.defaultBlockState(), 18);
                 if (!iblockdata1.is(BlockTags.FIRE)) {
                     world.addDestroyBlockEffect(blockposition3, iblockdata1);
diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
index 02be7c3d104fe3b3a2772201f5ebdfb6d16e9b49..ff40fe323964f173561a6838fb443e79abf9df38 100644
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
@@ -294,7 +294,7 @@ public abstract class FlowingFluid extends Fluid {
             ((LiquidBlockContainer) state.getBlock()).placeLiquid(world, pos, state, fluidState);
         } else {
             if (!state.isAir()) {
-                this.beforeDestroyingBlock(world, pos, state);
+                this.beforeDestroyingBlock(world, pos, state, pos.relative(direction.getOpposite())); // Paper
             }
 
             world.setBlock(pos, fluidState.createLegacyBlock(), 3);
@@ -302,6 +302,7 @@ public abstract class FlowingFluid extends Fluid {
 
     }
 
+    protected void beforeDestroyingBlock(LevelAccessor world, BlockPos pos, BlockState state, BlockPos source) { beforeDestroyingBlock(world, pos, state); } // Paper - add source parameter
     protected abstract void beforeDestroyingBlock(LevelAccessor world, BlockPos pos, BlockState state);
 
     private static short getCacheKey(BlockPos blockposition, BlockPos blockposition1) {
diff --git a/src/main/java/net/minecraft/world/level/material/WaterFluid.java b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
index c2beaba9095c9163f25a46c8b2c423e820639cf6..56d50b9310d30e0f81f3d2549ff5c256eb07cc2a 100644
--- a/src/main/java/net/minecraft/world/level/material/WaterFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
@@ -63,6 +63,13 @@ public abstract class WaterFluid extends FlowingFluid {
         return true;
     }
 
+    // Paper start
+    @Override
+    protected void beforeDestroyingBlock(LevelAccessor world, BlockPos pos, BlockState state,  BlockPos source) {
+        BlockEntity tileentity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
+        Block.dropResources(state, world, pos, tileentity, source);
+    }
+    // Paper end
     @Override
     protected void beforeDestroyingBlock(LevelAccessor world, BlockPos pos, BlockState state) {
         BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;