Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drops in BreakEvent #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/MiNET/MiNET/Worlds/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,15 +1377,17 @@ public void BreakBlock(Player player, BlockCoordinates blockCoordinates, BlockFa
Item inHand = player.Inventory.GetItemInHand();
bool canBreak = inHand.BreakBlock(this, player, block, blockEntity);

if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, null)))
List<Item> drops = new List<Item>();
drops.AddRange(block.GetDrops(inHand ?? new ItemAir()));
if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops)))
{
// Revert

RevertBlockAction(player, block, blockEntity);
}
else
{
BreakBlock(player, block, blockEntity, inHand, face);
BreakBlock(player, block, drops, blockEntity, inHand, face);

player.Inventory.DamageItemInHand(ItemDamageReason.BlockBreak, null, block);
player.HungerManager.IncreaseExhaustion(0.025f);
Expand Down Expand Up @@ -1421,11 +1423,14 @@ private static void RevertBlockAction(Player player, Block block, BlockEntity bl
}
}

public void BreakBlock(Player player, Block block, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None)
public void BreakBlock(Player player, Block block, List<Item> drops = null, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None)
{
block.BreakBlock(this, face);
var drops = new List<Item>();
drops.AddRange(block.GetDrops(tool ?? new ItemAir()));
if (drops == null)
{
drops = new List<Item>();
drops.AddRange(block.GetDrops(tool ?? new ItemAir()));
}

if (blockEntity != null)
{
Expand Down Expand Up @@ -1764,4 +1769,4 @@ public BlockBreakEventArgs(Player player, Level level, Block block, List<Item> d
Drops = drops;
}
}
}
}