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
|
2022-06-09 10:51:45 +02:00
|
|
|
index 718c67c630f7799c20df9850d9c2056a7218c220..224ce424b9a22548212ac157ec273c6dd80d6cfb 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
|
2022-06-08 12:20:57 +02:00
|
|
|
@@ -333,6 +333,23 @@ public class Block extends BlockBehaviour implements ItemLike {
|
2021-08-25 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
+ // 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));
|
|
|
|
+ }
|
2022-06-08 14:19:54 +02:00
|
|
|
+ state.spawnAfterBreak(world.getMinecraftWorld(), pos, ItemStack.EMPTY, true);
|
2021-08-25 03:42:23 +02:00
|
|
|
+ }
|
|
|
|
+ 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
|
2022-06-09 10:51:45 +02:00
|
|
|
index 8d73893100884c08aa552ff41c2a07a3e714df47..24a822ade17849a083161216c184f02c30b5cb1f 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
|
2022-06-08 12:20:57 +02:00
|
|
|
@@ -400,7 +400,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);
|
|
|
|
+ dropResources(iblockdata1, world, blockposition3, tileentity, pos); // Paper
|
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
|
2022-03-01 06:43:03 +01:00
|
|
|
index 02be7c3d104fe3b3a2772201f5ebdfb6d16e9b49..ff40fe323964f173561a6838fb443e79abf9df38 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
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -294,7 +294,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);
|
|
|
|
+ this.beforeDestroyingBlock(world, pos, state, pos.relative(direction.getOpposite())); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
world.setBlock(pos, fluidState.createLegacyBlock(), 3);
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -302,6 +302,7 @@ public abstract class FlowingFluid extends Fluid {
|
2021-08-25 03:42:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
+ 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
|
2022-06-08 12:20:57 +02:00
|
|
|
index a10b6a6b0ff9c104a94be3e9d0d1757333d81a00..ac33ba631f4b0ae0e08bff5748440ef5b76c2117 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
|
|
|
|
@@ -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;
|