Merge 164a6552bfbc53ef01f9225878fc9d32eb9b0b36 into 7c326bb2a24ada5ab57662a1719669730e4fc9a8

This commit is contained in:
flaffy 2025-08-02 18:54:28 +00:00 committed by GitHub
commit fea1967269
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 72 additions and 69 deletions

View File

@ -853,29 +853,29 @@ static void LocalPlayer_DoRespawn(struct LocalPlayer* p) {
p->Base.OnGround = Entity_TouchesAny(&bb, LocalPlayer_IsSolidCollide);
}
static cc_bool LocalPlayer_HandleRespawn(int key, struct InputDevice* device) {
static cc_ipt_flags LocalPlayer_HandleRespawn(int key, struct InputDevice* device) {
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
if (Gui.InputGrab) return false;
if (Gui.InputGrab) return IPT_NONE;
if (p->Hacks.CanRespawn) {
LocalPlayer_DoRespawn(p);
return true;
return IPT_HANDLED;
} else if (!p->_warnedRespawn) {
p->_warnedRespawn = true;
if (hackPermMsgs) Chat_AddRaw("&cRespawning is currently disabled");
}
return false;
return IPT_NONE;
}
static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) {
static cc_ipt_flags LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) {
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
if (Gui.InputGrab) return false;
if (Gui.InputGrab) return IPT_NONE;
if (p->Hacks.CanRespawn) {
if (!p->Hacks.CanNoclip && !p->Base.OnGround) {
Chat_AddRaw("&cCannot set spawn midair when noclip is disabled");
return false;
return IPT_NONE;
}
/* Spawn is normally centered to match vanilla Minecraft classic */
@ -897,44 +897,44 @@ static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) {
return LocalPlayer_HandleRespawn(key, device);
}
static cc_bool LocalPlayer_HandleFly(int key, struct InputDevice* device) {
static cc_ipt_flags LocalPlayer_HandleFly(int key, struct InputDevice* device) {
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
if (Gui.InputGrab) return false;
if (Gui.InputGrab) return IPT_NONE;
if (p->Hacks.CanFly && p->Hacks.Enabled) {
HacksComp_SetFlying(&p->Hacks, !p->Hacks.Flying);
return true;
return IPT_HANDLED;
} else if (!p->_warnedFly) {
p->_warnedFly = true;
if (hackPermMsgs) Chat_AddRaw("&cFlying is currently disabled");
}
return false;
return IPT_NONE;
}
static cc_bool LocalPlayer_HandleNoclip(int key, struct InputDevice* device) {
static cc_ipt_flags LocalPlayer_HandleNoclip(int key, struct InputDevice* device) {
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
p->Hacks._noclipping = true;
if (Gui.InputGrab) return false;
if (Gui.InputGrab) return IPT_NONE;
if (p->Hacks.CanNoclip && p->Hacks.Enabled) {
if (p->Hacks.WOMStyleHacks) return true; /* don't handle this here */
if (p->Hacks.WOMStyleHacks) return IPT_HANDLED; /* don't handle this here */
if (p->Hacks.Noclip) p->Base.Velocity.y = 0;
HacksComp_SetNoclip(&p->Hacks, !p->Hacks.Noclip);
return true;
return IPT_HANDLED;
} else if (!p->_warnedNoclip) {
p->_warnedNoclip = true;
if (hackPermMsgs) Chat_AddRaw("&cNoclip is currently disabled");
}
return false;
return IPT_NONE;
}
static cc_bool LocalPlayer_HandleJump(int key, struct InputDevice* device) {
static cc_ipt_flags LocalPlayer_HandleJump(int key, struct InputDevice* device) {
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
struct HacksComp* hacks = &p->Hacks;
struct PhysicsComp* physics = &p->Physics;
int maxJumps;
if (Gui.InputGrab) return false;
if (Gui.InputGrab) return IPT_NONE;
physics->Jumping = true;
if (!p->Base.OnGround && !(hacks->Flying || hacks->Noclip)) {
@ -945,28 +945,28 @@ static cc_bool LocalPlayer_HandleJump(int key, struct InputDevice* device) {
PhysicsComp_DoNormalJump(physics);
physics->MultiJumps++;
}
return true;
return IPT_HANDLED;
}
return false;
return IPT_NONE;
}
static cc_bool LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) {
static cc_ipt_flags LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) {
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
cc_bool touch = device->type == INPUT_DEVICE_TOUCH;
if (Gui.InputGrab) return false;
if (Gui.InputGrab) return IPT_NONE;
hacks->HalfSpeeding = (!touch || !hacks->HalfSpeeding) && hacks->Enabled;
return true;
return IPT_HANDLED;
}
static cc_bool LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) {
static cc_ipt_flags LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) {
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
cc_bool touch = device->type == INPUT_DEVICE_TOUCH;
if (Gui.InputGrab) return false;
if (Gui.InputGrab) return IPT_NONE;
hacks->Speeding = (!touch || !hacks->Speeding) && hacks->Enabled;
return true;
return IPT_HANDLED;
}
static void LocalPlayer_ReleaseHalfSpeed(int key, struct InputDevice* device) {

View File

@ -632,71 +632,69 @@ static void BindReleased_PickBlock(int key, struct InputDevice* device) {
}
static cc_bool BindTriggered_HideFPS(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_HideFPS(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
Gui.ShowFPS = !Gui.ShowFPS;
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_Fullscreen(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
Game_ToggleFullscreen();
return true;
static cc_ipt_flags BindTriggered_Fullscreen(int key, struct InputDevice* device) {
Game_ToggleFullscreen();
return IPT_HANDLED | IPT_SUPPRESS_UI;
}
static cc_bool BindTriggered_Fog(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_Fog(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
Game_CycleViewDistance();
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_HideGUI(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_HideGUI(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
Game_HideGui = !Game_HideGui;
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_SmoothCamera(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_SmoothCamera(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
InputHandler_Toggle(key, &Camera.Smooth,
" &eSmooth camera is &aenabled",
" &eSmooth camera is &cdisabled");
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_AxisLines(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_AxisLines(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
InputHandler_Toggle(key, &AxisLinesRenderer_Enabled,
" &eAxis lines (&4X&e, &2Y&e, &1Z&e) now show",
" &eAxis lines no longer show");
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_AutoRotate(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_AutoRotate(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
InputHandler_Toggle(key, &AutoRotate_Enabled,
" &eAuto rotate is &aenabled",
" &eAuto rotate is &cdisabled");
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_ThirdPerson(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_ThirdPerson(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
Camera_CycleActive();
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_DropBlock(int key, struct InputDevice* device) {
if (Gui.InputGrab) return false;
static cc_ipt_flags BindTriggered_DropBlock(int key, struct InputDevice* device) {
if (Gui.InputGrab) return IPT_NONE;
if (Inventory_CheckChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) {
/* Don't assign SelectedIndex directly, because we don't want held block
@ -704,17 +702,17 @@ static cc_bool BindTriggered_DropBlock(int key, struct InputDevice* device) {
Inventory_Set(Inventory.SelectedIndex, BLOCK_AIR);
Event_RaiseVoid(&UserEvents.HeldBlockChanged);
}
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_IDOverlay(int key, struct InputDevice* device) {
static cc_ipt_flags BindTriggered_IDOverlay(int key, struct InputDevice* device) {
struct Screen* s = Gui_GetScreen(GUI_PRIORITY_TEXIDS);
if (s) {
Gui_Remove(s);
} else {
TexIdsOverlay_Show();
}
return true;
return IPT_HANDLED;
}
static cc_bool BindTriggered_BreakLiquids(int key, struct InputDevice* device) {
@ -836,7 +834,7 @@ static void OnPointerUp(void* obj, int idx) {
static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* device) {
struct Screen* s;
cc_bool triggered;
cc_ipt_flags triggered_flags;
int i;
if (Input.DownHook && Input.DownHook(key, device)) return;
@ -854,23 +852,24 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev
Game_ScreenshotRequested = true; return;
}
triggered = false;
triggered_flags = IPT_NONE;
for (i = 0; !was && i < BIND_COUNT; i++)
{
if (!InputBind_Claims(i, key, device)) continue;
Bind_IsTriggered[i] |= device->type;
if (!Bind_OnTriggered[i]) continue;
triggered |= Bind_OnTriggered[i](key, device);
triggered_flags |= Bind_OnTriggered[i](key, device);
}
for (i = 0; i < Gui.ScreensCount; i++)
{
s = Gui_Screens[i];
s->dirty = true;
if (s->VTABLE->HandlesInputDown(s, key, device)) return;
if (!(triggered_flags & IPT_SUPPRESS_UI)) { //if key is supressing gui's key handling skip it
for (i = 0; i < Gui.ScreensCount; i++)
{
s = Gui_Screens[i];
s->dirty = true;
if (s->VTABLE->HandlesInputDown(s, key, device)) return;
}
if (Gui.InputGrab) return;
}
if (Gui.InputGrab) return;
if (InputDevice_IsPause(key, device)) {
#ifdef CC_BUILD_WEB
@ -887,7 +886,7 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev
/* Hotkeys should not be triggered multiple times when holding down */
if (was) return;
if (triggered) {
if (triggered_flags & IPT_HANDLED) {
} else if (key == CCKEY_F5 && Game_ClassicMode) {
int weather = Env.Weather == WEATHER_SUNNY ? WEATHER_RAINY : WEATHER_SUNNY;
Env_SetWeather(weather);

View File

@ -53,8 +53,12 @@ cc_bool Input_HandleMouseWheel(float delta);
void InputHandler_Tick(float delta);
void InputHandler_OnScreensChanged(void);
typedef cc_uint8 cc_ipt_flags; /*dont know if this is the best place to put this*/
#define IPT_NONE 0x00 /* key havent been handled */
#define IPT_HANDLED 0x01 /* key has been handled */
#define IPT_SUPPRESS_UI 0x02 /* key supresses GUI's key processing*/
typedef cc_bool (*BindTriggered)(int key, struct InputDevice* device);
typedef cc_ipt_flags (*BindTriggered)(int key, struct InputDevice* device); /*changes this to use 'cc_key_flag' instead of bool*/
typedef void (*BindReleased)(int key, struct InputDevice* device);
/* Gets whether the given input binding is currently being triggered */
CC_API cc_bool KeyBind_IsPressed(InputBind binding);