Skip to content

Commit 8319349

Browse files
committed
Add drops in BreakEvent
1 parent 67dc196 commit 8319349

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/MiNET/MiNET/Worlds/Level.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,16 +1376,17 @@ public void BreakBlock(Player player, BlockCoordinates blockCoordinates, BlockFa
13761376

13771377
Item inHand = player.Inventory.GetItemInHand();
13781378
bool canBreak = inHand.BreakBlock(this, player, block, blockEntity);
1379-
1380-
if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, null)))
1379+
List<Item> drops = new List<Item>();
1380+
drops.AddRange(block.GetDrops(inHand ?? new ItemAir()));
1381+
if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops)))
13811382
{
13821383
// Revert
13831384

13841385
RevertBlockAction(player, block, blockEntity);
13851386
}
13861387
else
13871388
{
1388-
BreakBlock(player, block, blockEntity, inHand, face);
1389+
BreakBlock(player, block, drops, blockEntity, inHand, face);
13891390

13901391
player.Inventory.DamageItemInHand(ItemDamageReason.BlockBreak, null, block);
13911392
player.HungerManager.IncreaseExhaustion(0.025f);
@@ -1421,11 +1422,14 @@ private static void RevertBlockAction(Player player, Block block, BlockEntity bl
14211422
}
14221423
}
14231424

1424-
public void BreakBlock(Player player, Block block, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None)
1425+
public void BreakBlock(Player player, Block block, List<Item> drops = null, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None)
14251426
{
14261427
block.BreakBlock(this, face);
1427-
var drops = new List<Item>();
1428-
drops.AddRange(block.GetDrops(tool ?? new ItemAir()));
1428+
if (drops == null)
1429+
{
1430+
drops = new List<Item>();
1431+
drops.AddRange(block.GetDrops(tool ?? new ItemAir()));
1432+
}
14291433

14301434
if (blockEntity != null)
14311435
{

0 commit comments

Comments
 (0)