Skip to content

Remove itemstack mutation on player drop method #11831

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
--- a/net/minecraft/server/commands/GiveCommand.java
+++ b/net/minecraft/server/commands/GiveCommand.java
@@ -51,6 +_,7 @@

private static int giveItem(CommandSourceStack source, ItemInput item, Collection<ServerPlayer> targets, int count) throws CommandSyntaxException {
ItemStack itemStack = item.createItemStack(1, false);
+ final Component displayName = itemStack.getDisplayName(); // Paper - get display name early
int maxStackSize = itemStack.getMaxStackSize();
int i = maxStackSize * 100;
if (count > i) {
@@ -66,7 +_,7 @@
ItemStack itemStack1 = item.createItemStack(min, false);
boolean flag = serverPlayer.getInventory().add(itemStack1);
Expand All @@ -17,17 +9,3 @@
if (itemEntity != null) {
itemEntity.makeFakeItem();
}
@@ -95,11 +_,11 @@

if (targets.size() == 1) {
source.sendSuccess(
- () -> Component.translatable("commands.give.success.single", count, itemStack.getDisplayName(), targets.iterator().next().getDisplayName()),
+ () -> Component.translatable("commands.give.success.single", count, displayName, targets.iterator().next().getDisplayName()), // Paper - use cached display name
true
);
} else {
- source.sendSuccess(() -> Component.translatable("commands.give.success.single", count, itemStack.getDisplayName(), targets.size()), true);
+ source.sendSuccess(() -> Component.translatable("commands.give.success.single", count, displayName, targets.size()), true); // Paper - use cached display name
}

return targets.size();
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@
if (traceItem) {
if (!item.isEmpty()) {
- this.awardStat(Stats.ITEM_DROPPED.get(item.getItem()), droppedItem.getCount());
+ this.awardStat(Stats.ITEM_DROPPED.get(item.getItem()), item.getCount()); // Paper - Fix PlayerDropItemEvent using wrong item
+ this.awardStat(Stats.ITEM_DROPPED.get(item.getItem()), item.getCount()); // Paper - Use updated count on item provided from event
}

this.awardStat(Stats.DROP);
Expand All @@ -1399,18 +1399,6 @@
return itemEntity;
}
}
@@ -1955,6 +_,11 @@
return null;
} else {
double d = this.getEyeY() - 0.3F;
+ // Paper start
+ ItemStack tmp = droppedItem.copy();
+ droppedItem.setCount(0);
+ droppedItem = tmp;
+ // Paper end
ItemEntity itemEntity = new ItemEntity(this.level(), this.getX(), d, this.getZ(), droppedItem);
itemEntity.setPickUpDelay(40);
if (includeThrowerName) {
@@ -2008,6 +_,16 @@
}

Expand Down
Loading