From 006e8346e9c7984efae523860a41bf055d010ebe Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 10 Oct 2021 18:18:01 -0700
Subject: [PATCH] Fix HumanEntity#drop not updating the client inv

== AT ==
public net.minecraft.server.level.ServerPlayer containerSynchronizer
---
 .../bukkit/craftbukkit/entity/CraftHumanEntity.java   | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index 9509fa35cc..db99af60c8 100644
--- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -782,8 +782,15 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
     // Paper end
     @Override
     public boolean dropItem(boolean dropAll) {
-        if (!(this.getHandle() instanceof ServerPlayer)) return false;
-        return ((ServerPlayer) this.getHandle()).drop(dropAll);
+        // Paper start - Fix HumanEntity#drop not updating the client inv
+        if (!(this.getHandle() instanceof ServerPlayer player)) return false;
+        boolean success = player.drop(dropAll);
+        if (!success) return false;
+        final net.minecraft.world.entity.player.Inventory inv = player.getInventory();
+        final java.util.OptionalInt optionalSlot = player.containerMenu.findSlot(inv, inv.selected);
+        optionalSlot.ifPresent(slot -> player.containerSynchronizer.sendSlotChange(player.containerMenu, slot, inv.getSelected()));
+        return true;
+        // Paper end - Fix HumanEntity#drop not updating the client inv
     }
 
     @Override