Update upstream
This commit is contained in:
74
patches/server/0010-Add-BlockDropResourcesEvent.patch
Normal file
74
patches/server/0010-Add-BlockDropResourcesEvent.patch
Normal file
@@ -0,0 +1,74 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: lexikiq <noellekiq@gmail.com>
|
||||
Date: Thu, 1 Jul 2021 21:36:03 -0400
|
||||
Subject: [PATCH] Add BlockDropResourcesEvent
|
||||
|
||||
Adds an event which allows plugin developers
|
||||
to easily get the items being dropped by any
|
||||
block instead of only blocks broken by players.
|
||||
|
||||
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 4f91e4832a94c3facbc711fcae4cb5ad540a5ca0..c357e09705c5405dc8fac666fc39c993febdee50 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
@@ -306,7 +306,7 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
ServerLevel worldserver = lootContext.getLevel();
|
||||
BlockPos blockposition = BlockPos.containing((Position) lootContext.getParameter(LootContextParams.ORIGIN));
|
||||
|
||||
- state.getDrops(lootContext).forEach((itemstack) -> {
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(worldserver, blockposition, state.getDrops(lootContext)).forEach((itemstack) -> { // Parchment
|
||||
Block.popResource(worldserver, blockposition, itemstack);
|
||||
});
|
||||
state.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY, true);
|
||||
@@ -314,7 +314,7 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
|
||||
public static void dropResources(BlockState state, Level world, BlockPos pos) {
|
||||
if (world instanceof ServerLevel) {
|
||||
- Block.getDrops(state, (ServerLevel) world, pos, (BlockEntity) null).forEach((itemstack) -> {
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, (BlockEntity) null)).forEach((itemstack) -> { // Parchment
|
||||
Block.popResource(world, pos, itemstack);
|
||||
});
|
||||
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true);
|
||||
@@ -324,7 +324,7 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
|
||||
public static void dropResources(BlockState state, LevelAccessor world, BlockPos pos, @Nullable BlockEntity blockEntity) {
|
||||
if (world instanceof ServerLevel) {
|
||||
- Block.getDrops(state, (ServerLevel) world, pos, blockEntity).forEach((itemstack) -> {
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, blockEntity)).forEach((itemstack) -> { // Parchment
|
||||
Block.popResource((ServerLevel) world, pos, itemstack);
|
||||
});
|
||||
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true);
|
||||
@@ -351,7 +351,8 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
|
||||
public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack tool) {
|
||||
if (world instanceof ServerLevel) {
|
||||
- Block.getDrops(state, (ServerLevel) world, pos, blockEntity, entity, tool).forEach((itemstack1) -> {
|
||||
+
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, blockEntity, entity, tool)).forEach((itemstack1) -> { // Parchment
|
||||
Block.popResource(world, pos, itemstack1);
|
||||
});
|
||||
state.spawnAfterBreak((ServerLevel) world, pos, tool, true);
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index 63ddbed83af9b8bfd237ca0c6b0727317dafe03f..df7cbca1fe99bdb47a112e7a0cb7b81496586518 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -1990,5 +1990,19 @@ public class CraftEventFactory {
|
||||
}
|
||||
});
|
||||
}
|
||||
+
|
||||
+ public static List<ItemStack> callBlockDropResourcesEvent(LevelAccessor world, BlockPos pos, List<ItemStack> items) {
|
||||
+ List<org.bukkit.inventory.ItemStack> bukkitItems = new ArrayList<>(items.size());
|
||||
+ for (ItemStack item : items) {
|
||||
+ bukkitItems.add(CraftItemStack.asBukkitCopy(item));
|
||||
+ }
|
||||
+ gg.projecteden.parchment.event.block.BlockDropResourcesEvent event = new gg.projecteden.parchment.event.block.BlockDropResourcesEvent(CraftBlock.at(world, pos), bukkitItems);
|
||||
+ event.callEvent();
|
||||
+ items = new ArrayList<>(bukkitItems.size());
|
||||
+ for (org.bukkit.inventory.ItemStack item : bukkitItems) {
|
||||
+ items.add(CraftItemStack.asNMSCopy(item));
|
||||
+ }
|
||||
+ return items;
|
||||
+ }
|
||||
// Parchment end
|
||||
}
|
||||
Reference in New Issue
Block a user