Skip to content

Commit 9e5d9d1

Browse files
authored
Implement item drop functionality with Q key (#99)
Added functionality to drop items using the Q key, with support for dropping entire stacks when Ctrl is held. Included checks to prevent dropping items while destroying blocks.
1 parent 109f563 commit 9e5d9d1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Minecraft.Client/Input.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,45 @@ void Input::tick(LocalPlayer *player)
169169
if (iPad == 0 && KMInput.IsKeyDown(VK_SPACE) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP))
170170
jumping = true;
171171
#endif
172+
173+
#ifdef _WINDOWS64
174+
// Keyboard drop (Q)
175+
// Press Q to drop one item. Hold Ctrl+Q to drop the whole stack.
176+
if (iPad == 0 && KMInput.ConsumeKeyPress('Q') && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_DROP) && !menuOpen)
177+
{
178+
// Prevent dropping while actively destroying a block (fix crash)
179+
MultiPlayerGameMode *mpgm = nullptr;
180+
if (pMinecraft->localgameModes[iPad] != NULL)
181+
{
182+
mpgm = dynamic_cast<MultiPlayerGameMode *>(pMinecraft->localgameModes[iPad]);
183+
}
184+
if (mpgm != nullptr && mpgm->IsDestroying())
185+
{
186+
// ignore drop while destroying
187+
}
188+
else
189+
{
190+
if (player != NULL)
191+
{
192+
// If CTRL is held, drop the entire stack
193+
if (KMInput.IsKeyDown(VK_CONTROL))
194+
{
195+
shared_ptr<ItemInstance> sel = player->inventory->getSelected();
196+
if (sel != NULL)
197+
{
198+
shared_ptr<ItemInstance> toDrop = player->inventory->removeItem(player->inventory->selected, sel->count);
199+
if (toDrop != NULL) player->drop(toDrop, false);
200+
}
201+
}
202+
else
203+
{
204+
// Drop a single item (Player::drop() will remove 1 from selected)
205+
player->drop();
206+
}
207+
}
208+
}
209+
}
210+
#endif
172211

173212
#ifndef _CONTENT_PACKAGE
174213
if (app.GetFreezePlayers()) jumping = false;

0 commit comments

Comments
 (0)