2021-08-25 03:42:23 +02:00
|
|
|
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
|
2024-02-01 10:15:57 +01:00
|
|
|
index 89a62fbeeb78c864938a1cea84178478c6dc1b34..57d92c1785586dfab2b3934733d8ba253e042e2e 100644
|
2021-08-25 03:42:23 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
2024-02-01 10:15:57 +01:00
|
|
|
@@ -314,6 +314,24 @@ public class Block extends BlockBehaviour implements ItemLike {
|
2021-08-25 03:42:23 +02:00
|
|
|
|
|
|
|
}
|
2024-02-01 10:15:57 +01:00
|
|
|
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper start - Add BlockBreakBlockEvent
|
2024-02-01 10:15:57 +01:00
|
|
|
+ public static boolean dropResources(BlockState state, LevelAccessor levelAccessor, BlockPos pos, @Nullable BlockEntity blockEntity, BlockPos source) {
|
|
|
|
+ if (levelAccessor instanceof ServerLevel serverLevel) {
|
|
|
|
+ List<org.bukkit.inventory.ItemStack> items = new java.util.ArrayList<>();
|
|
|
|
+ for (ItemStack drop : Block.getDrops(state, serverLevel, pos, blockEntity)) {
|
2021-08-25 03:42:23 +02:00
|
|
|
+ items.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(drop));
|
|
|
|
+ }
|
2024-02-01 10:15:57 +01:00
|
|
|
+ io.papermc.paper.event.block.BlockBreakBlockEvent event = new io.papermc.paper.event.block.BlockBreakBlockEvent(org.bukkit.craftbukkit.block.CraftBlock.at(levelAccessor, pos), org.bukkit.craftbukkit.block.CraftBlock.at(levelAccessor, source), items);
|
2021-08-25 03:42:23 +02:00
|
|
|
+ event.callEvent();
|
2024-02-01 10:15:57 +01:00
|
|
|
+ for (org.bukkit.inventory.ItemStack drop : event.getDrops()) {
|
|
|
|
+ popResource(serverLevel, pos, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(drop));
|
2021-08-25 03:42:23 +02:00
|
|
|
+ }
|
2024-02-01 10:15:57 +01:00
|
|
|
+ state.spawnAfterBreak(serverLevel, pos, ItemStack.EMPTY, true);
|
2021-08-25 03:42:23 +02:00
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper end - Add BlockBreakBlockEvent
|
2024-02-01 10:15:57 +01:00
|
|
|
+
|
2023-06-08 04:04:01 +02:00
|
|
|
public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool) {
|
2021-08-25 03:42:23 +02:00
|
|
|
if (world instanceof ServerLevel) {
|
2024-02-01 10:15:57 +01:00
|
|
|
Block.getDrops(state, (ServerLevel) world, pos, blockEntity, entity, tool).forEach((itemstack1) -> {
|
2021-08-25 03:42:23 +02:00
|
|
|
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
|
2024-01-23 12:06:27 +01:00
|
|
|
index 3ae61e7b50bfc440c597f88843f92903f8a66801..0dbdcd443fe8a299119ea5ba3acb1a0412856184 100644
|
2021-08-25 03:42:23 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
|
2024-01-23 12:06:27 +01:00
|
|
|
@@ -402,7 +402,7 @@ public class PistonBaseBlock extends DirectionalBlock {
|
2021-08-25 03:42:23 +02:00
|
|
|
iblockdata1 = world.getBlockState(blockposition3);
|
|
|
|
BlockEntity tileentity = iblockdata1.hasBlockEntity() ? world.getBlockEntity(blockposition3) : null;
|
|
|
|
|
2021-11-25 02:24:51 +01:00
|
|
|
- dropResources(iblockdata1, world, blockposition3, tileentity);
|
2024-01-19 13:22:30 +01:00
|
|
|
+ dropResources(iblockdata1, world, blockposition3, tileentity, pos); // Paper - Add BlockBreakBlockEvent
|
2021-08-25 03:42:23 +02:00
|
|
|
world.setBlock(blockposition3, Blocks.AIR.defaultBlockState(), 18);
|
2022-06-08 12:20:57 +02:00
|
|
|
world.gameEvent(GameEvent.BLOCK_DESTROY, blockposition3, GameEvent.Context.of(iblockdata1));
|
2022-03-01 06:43:03 +01:00
|
|
|
if (!iblockdata1.is(BlockTags.FIRE)) {
|
2021-08-25 03:42:23 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
|
2024-01-21 13:56:22 +01:00
|
|
|
index 0aeb9faa1ce22359361741a591aa3d465d955970..a98ab20814cc29a25e9d29adfbb7e70d46768df2 100644
|
2021-08-25 03:42:23 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
|
2024-01-21 13:56:22 +01:00
|
|
|
@@ -295,7 +295,7 @@ public abstract class FlowingFluid extends Fluid {
|
2021-08-25 03:42:23 +02:00
|
|
|
((LiquidBlockContainer) state.getBlock()).placeLiquid(world, pos, state, fluidState);
|
|
|
|
} else {
|
|
|
|
if (!state.isAir()) {
|
|
|
|
- this.beforeDestroyingBlock(world, pos, state);
|
2024-01-19 13:22:30 +01:00
|
|
|
+ this.beforeDestroyingBlock(world, pos, state, pos.relative(direction.getOpposite())); // Paper - Add BlockBreakBlockEvent
|
2021-08-25 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
world.setBlock(pos, fluidState.createLegacyBlock(), 3);
|
2024-01-21 13:56:22 +01:00
|
|
|
@@ -303,6 +303,7 @@ public abstract class FlowingFluid extends Fluid {
|
2021-08-25 03:42:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-01-19 13:22:30 +01:00
|
|
|
+ protected void beforeDestroyingBlock(LevelAccessor world, BlockPos pos, BlockState state, BlockPos source) { beforeDestroyingBlock(world, pos, state); } // Paper - Add BlockBreakBlockEvent
|
2021-08-25 03:42:23 +02:00
|
|
|
protected abstract void beforeDestroyingBlock(LevelAccessor world, BlockPos pos, BlockState state);
|
|
|
|
|
2023-06-08 04:04:01 +02:00
|
|
|
private static short getCacheKey(BlockPos from, BlockPos to) {
|
2021-08-25 03:42:23 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/material/WaterFluid.java b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
|
2024-01-19 13:22:30 +01:00
|
|
|
index 1897c0012800d5ba9d2fc386f3e2bf57c9d878bb..c5f9eda32f2cd172569c7b7d72f5dd3e41a34a70 100644
|
2021-08-25 03:42:23 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/material/WaterFluid.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -64,6 +64,13 @@ public abstract class WaterFluid extends FlowingFluid {
|
|
|
|
return world.getGameRules().getBoolean(GameRules.RULE_WATER_SOURCE_CONVERSION);
|
2021-08-25 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper start - Add BlockBreakBlockEvent
|
2021-08-25 03:42:23 +02:00
|
|
|
+ @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);
|
|
|
|
+ }
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper end - Add BlockBreakBlockEvent
|
2021-08-25 03:42:23 +02:00
|
|
|
@Override
|
|
|
|
protected void beforeDestroyingBlock(LevelAccessor world, BlockPos pos, BlockState state) {
|
|
|
|
BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
|