fix: hotbarSlot is zero-indexed, move max hotbar slots into a constant
Some checks are pending
Build (Linux, x86_64) / build-linux (push) Waiting to run
Build (Linux, x86_64) / build-linux-debug (push) Waiting to run

This commit is contained in:
Tropical 2026-03-10 20:18:03 -05:00
parent 28018e5022
commit ca9ac8e7f7
2 changed files with 6 additions and 4 deletions

View file

@ -161,14 +161,16 @@ void C_4JInput::Tick() {
int C_4JInput::GetHotbarSlotPressed(int iPad) {
if (iPad != 0) return -1;
static const int sc[10] = {
constexpr size_t NUM_HOTBAR_SLOTS = 9;
static const int sc[NUM_HOTBAR_SLOTS] = {
SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4,
SDL_SCANCODE_5, SDL_SCANCODE_6, SDL_SCANCODE_7, SDL_SCANCODE_8,
SDL_SCANCODE_9,
};
static bool s_wasDown[10] = {};
static bool s_wasDown[NUM_HOTBAR_SLOTS] = {};
for (int i = 0; i < 10; ++i) {
for (int i = 0; i < NUM_HOTBAR_SLOTS; ++i) {
bool down = KDown(sc[i]);
bool pressed = down && !s_wasDown[i];
s_wasDown[i] = down;

View file

@ -3438,7 +3438,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
#endif
{
int hotbarSlot = InputManager.GetHotbarSlotPressed(iPad);
if (hotbarSlot > 0 && hotbarSlot < 10)
if (hotbarSlot >= 0 && hotbarSlot <= 9)
{
player->inventory->selected = hotbarSlot;
selected = true;