Fix: Dropping items outside of inventory menus#1159
Fix: Dropping items outside of inventory menus#1159Adem-Kurt wants to merge 2 commits intosmartcmd:mainfrom
Conversation
2026-03-11.22-29-27.mp4 |
|
Tested your branch, looks like there's a problem in the creative menu where some items don't get dropped even when the count reduces, leading to some getting lost. Doesn't look to be an issue in the inventory. adem-kurt-1159-pull.mp4 |
|
Hi, Thank you for testing the branch and providing the video. I found the root cause of the bug. It is related to the server's anti-spam protection mechanism for dropping items on creative mode. The Issue: else if (drop && validItem && validData)
{
if (dropSpamTickCount < SharedConstants::TICKS_PER_SECOND * 10)
{
dropSpamTickCount += SharedConstants::TICKS_PER_SECOND;
// drop item
shared_ptr<ItemEntity> dropped = player->drop(item);
if (dropped != nullptr)
{
dropped->setShortLifeTime();
}
}
}Right now, the game limit is 200. When you drop 1 item, the game adds 20 to a counter. If you click fast the items disappear. Possible Solutions:
I am not sure what the best solution is to fix this. Also, this change might be out of scope for this PR. |
|
Given this issue only occurs in the creative menu and not the inventory, how is it currently implemented in the inventory? Does the check only happen within the creative menu? |
|
Yes, the check only happens within the creative menu! In standard menus (like the survival inventory, chests, etc.), dropping items is handled via a standard \ContainerClickPacket. The server processes this in \PlayerConnection::handleContainerClick(), which evaluates the action via \AbstractContainerMenu::clicked(). If the click is outside the bounds (\SLOT_CLICKED_OUTSIDE), it simply calls \player->drop()\ directly (in \Minecraft.World/AbstractContainerMenu.cpp) without any spam limits. However, the creative menu operates differently. When you drop an item from the creative inventory, the client sends a \SetCreativeModeSlotPacket\ with a negative slot ID to the server. This packet is handled by \PlayerConnection::handleSetCreativeModeSlot()\ (in \Minecraft.Client/PlayerConnection.cpp), which is exactly where this \dropSpamTickCount\ anti-spam logic lives. Because regular containers use a completely different packet and logic path, they bypass this creative-specific spam filter entirely. I think the best option is removing the spam check for creative menu. |
Description
This PR fixes two separate bugs that prevented players from dropping items with clicking outside the inventory in menus.
Changes
Previous Behavior
Root Cause
IUIScene_CreativeMenu.cpp,handleValidKeyPresshad a check that captured any right-click (buttonNum == 1) and triggered the hotbar clearing function, terminating the input flow before the outside drop logic could process it.AbstractContainerMenu.cpp, theclickedfunction had an early bounds check (if (slotIndex < 0 || slotIndex >= slots.size()) return nullptr;). Because clicking outside the UI sends a slot ID ofSLOT_CLICKED_OUTSIDE(-999), this early check blocked the input, never allowing the drop code to execute.New Behavior
Fix Implementation
!m_bPointerOutsideMenuto the right-click interception logic inIUIScene_CreativeMenu.cppso it only clears the hotbar if the pointer is actually inside the UI boundaries.SLOT_CLICKED_OUTSIDEin the initial boundary bounds check inAbstractContainerMenu::clickedso the-999ID can properly reach the subsequent drag-and-drop code blocks.AI Use Disclosure
I used AI as a search tool, find the code causing this bug.
Related Issues