2026-03-01 12:16:08 +08:00
# include "stdafx.h"
# include "Minecraft.h"
# include "GameMode.h"
2026-04-14 16:47:37 -05:00
# include "../Minecraft.World/net.minecraft.world.entity.player.h"
# include "../Minecraft.World/net.minecraft.world.level.h"
# include "../Minecraft.World/net.minecraft.world.level.storage.h"
2026-03-01 12:16:08 +08:00
# include "Input.h"
2026-04-14 16:47:37 -05:00
# include "../Minecraft.Client/LocalPlayer.h"
2026-03-01 12:16:08 +08:00
# include "Options.h"
2026-03-04 21:19:40 +08:00
# ifdef _WINDOWS64
2026-04-14 16:47:37 -05:00
# include "Windows64/KeyboardMouseInput.h"
2026-03-04 21:19:40 +08:00
# endif
2026-03-01 12:16:08 +08:00
Input : : Input ( )
{
xa = 0 ;
ya = 0 ;
wasJumping = false ;
jumping = false ;
sneaking = false ;
2026-03-04 21:19:40 +08:00
sprinting = false ;
2026-03-01 12:16:08 +08:00
lReset = false ;
rReset = false ;
}
void Input : : tick ( LocalPlayer * player )
{
// 4J Stu - Assume that we only need one input class, even though the java has subclasses for keyboard/controller
// This function is based on the ControllerInput class in the Java, and will probably need changed
//OutputDebugString("INPUT: Beginning input tick\n");
Minecraft * pMinecraft = Minecraft : : GetInstance ( ) ;
int iPad = player - > GetXboxPad ( ) ;
2026-03-04 21:19:40 +08:00
float controllerXA = 0.0f ;
float controllerYA = 0.0f ;
2026-03-01 12:16:08 +08:00
// 4J-PB minecraft movement seems to be the wrong way round, so invert x!
if ( pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_LEFT ) | | pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_RIGHT ) )
2026-03-04 21:19:40 +08:00
controllerXA = - InputManager . GetJoypadStick_LX ( iPad ) ;
2026-03-01 18:50:55 +08:00
2026-03-01 12:16:08 +08:00
if ( pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_FORWARD ) | | pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_BACKWARD ) )
2026-03-04 21:19:40 +08:00
controllerYA = InputManager . GetJoypadStick_LY ( iPad ) ;
2026-03-01 12:16:08 +08:00
2026-03-04 21:19:40 +08:00
float kbXA = 0.0f ;
float kbYA = 0.0f ;
2026-03-01 18:50:55 +08:00
# ifdef _WINDOWS64
2026-03-04 21:19:40 +08:00
if ( iPad = = 0 & & g_KBMInput . IsMouseGrabbed ( ) & & g_KBMInput . IsKBMActive ( ) )
2026-03-01 18:50:55 +08:00
{
2026-03-04 21:19:40 +08:00
if ( pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_LEFT ) | | pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_RIGHT ) )
kbXA = g_KBMInput . GetMoveX ( ) ;
if ( pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_FORWARD ) | | pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_BACKWARD ) )
kbYA = g_KBMInput . GetMoveY ( ) ;
2026-03-01 18:50:55 +08:00
}
# endif
2026-03-04 21:19:40 +08:00
if ( kbXA ! = 0.0f | | kbYA ! = 0.0f )
{
xa = kbXA ;
ya = kbYA ;
}
else
{
xa = controllerXA ;
ya = controllerYA ;
}
2026-03-01 18:50:55 +08:00
2026-03-01 12:16:08 +08:00
# ifndef _CONTENT_PACKAGE
if ( app . GetFreezePlayers ( ) )
{
xa = ya = 0.0f ;
player - > abilities . flying = true ;
}
# endif
2026-03-01 18:50:55 +08:00
2026-03-01 12:16:08 +08:00
if ( ! lReset )
{
if ( xa * xa + ya * ya = = 0.0f )
{
lReset = true ;
}
xa = ya = 0.0f ;
}
2026-03-03 03:04:10 +08:00
// 4J: In flying mode, don't actually toggle sneaking (unless we're riding in which case we need to sneak to dismount)
2026-03-08 19:08:36 -04:00
if ( ! player - > abilities . flying | | player - > riding ! = nullptr )
2026-03-01 12:16:08 +08:00
{
if ( ( player - > ullButtonsPressed & ( 1LL < < MINECRAFT_ACTION_SNEAK_TOGGLE ) ) & & pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_SNEAK_TOGGLE ) )
{
2026-03-04 21:19:40 +08:00
sneaking = ! sneaking ;
2026-03-01 12:16:08 +08:00
}
}
2026-03-01 18:50:55 +08:00
# ifdef _WINDOWS64
2026-03-04 21:19:40 +08:00
if ( iPad = = 0 & & g_KBMInput . IsMouseGrabbed ( ) & & g_KBMInput . IsKBMActive ( ) )
{
// Left Shift = sneak (hold to crouch)
if ( pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_SNEAK_TOGGLE ) )
{
if ( ! player - > abilities . flying )
{
sneaking = g_KBMInput . IsKeyDown ( KeyboardMouseInput : : KEY_SNEAK ) ;
}
}
2026-03-05 14:39:11 +01:00
// Ctrl + forward = sprint (hold to sprint, including while flying)
2026-03-04 21:19:40 +08:00
{
bool ctrlHeld = g_KBMInput . IsKeyDown ( KeyboardMouseInput : : KEY_SPRINT ) ;
bool movingForward = ( kbYA > 0.0f ) ;
if ( ctrlHeld & & movingForward )
{
sprinting = true ;
}
else
{
sprinting = false ;
}
}
}
else if ( iPad = = 0 )
{
sprinting = false ;
}
2026-03-01 18:50:55 +08:00
# endif
2026-03-01 12:16:08 +08:00
if ( sneaking )
{
xa * = 0.3f ;
ya * = 0.3f ;
}
float turnSpeed = 50.0f ;
float tx = 0.0f ;
float ty = 0.0f ;
2026-03-04 21:19:40 +08:00
2026-03-01 12:16:08 +08:00
if ( pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_LOOK_LEFT ) | | pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_LOOK_RIGHT ) )
2026-03-08 19:08:36 -04:00
tx = InputManager . GetJoypadStick_RX ( iPad ) * ( static_cast < float > ( app . GetGameSettings ( iPad , eGameSetting_Sensitivity_InGame ) ) / 100.0f ) ; // apply sensitivity to look
2026-03-01 12:16:08 +08:00
if ( pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_LOOK_UP ) | | pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_LOOK_DOWN ) )
2026-03-08 19:08:36 -04:00
ty = InputManager . GetJoypadStick_RY ( iPad ) * ( static_cast < float > ( app . GetGameSettings ( iPad , eGameSetting_Sensitivity_InGame ) ) / 100.0f ) ; // apply sensitivity to look
2026-03-01 18:50:55 +08:00
2026-03-01 12:16:08 +08:00
# ifndef _CONTENT_PACKAGE
if ( app . GetFreezePlayers ( ) ) tx = ty = 0.0f ;
# endif
// 4J: WESTY : Invert look Y if required.
if ( app . GetGameSettings ( iPad , eGameSetting_ControlInvertLook ) )
{
ty = - ty ;
}
if ( ! rReset )
{
if ( tx * tx + ty * ty = = 0.0f )
{
rReset = true ;
}
tx = ty = 0.0f ;
}
2026-03-04 21:19:40 +08:00
float turnX = tx * abs ( tx ) * turnSpeed ;
float turnY = ty * abs ( ty ) * turnSpeed ;
2026-03-01 18:50:55 +08:00
# ifdef _WINDOWS64
2026-03-04 21:19:40 +08:00
if ( iPad = = 0 & & g_KBMInput . IsMouseGrabbed ( ) & & g_KBMInput . IsKBMActive ( ) )
2026-03-01 18:50:55 +08:00
{
2026-03-08 19:08:36 -04:00
float mouseSensitivity = static_cast < float > ( app . GetGameSettings ( iPad , eGameSetting_Sensitivity_InGame ) ) / 100.0f ;
2026-03-04 21:19:40 +08:00
float mouseLookScale = 5.0f ;
float mx = g_KBMInput . GetLookX ( mouseSensitivity * mouseLookScale ) ;
float my = g_KBMInput . GetLookY ( mouseSensitivity * mouseLookScale ) ;
if ( app . GetGameSettings ( iPad , eGameSetting_ControlInvertLook ) )
2026-03-01 21:50:44 +08:00
{
2026-03-04 21:19:40 +08:00
my = - my ;
2026-03-01 21:50:44 +08:00
}
2026-03-04 21:19:40 +08:00
turnX + = mx ;
turnY + = my ;
2026-03-01 18:50:55 +08:00
}
# endif
2026-03-04 21:19:40 +08:00
player - > interpolateTurn ( turnX , turnY ) ;
2026-03-01 12:16:08 +08:00
2026-03-04 21:19:40 +08:00
//jumping = controller.isButtonPressed(0);
2026-03-01 18:50:55 +08:00
2026-03-01 12:16:08 +08:00
unsigned int jump = InputManager . GetValue ( iPad , MINECRAFT_ACTION_JUMP ) ;
2026-03-04 21:19:40 +08:00
bool kbJump = false ;
# ifdef _WINDOWS64
kbJump = ( iPad = = 0 ) & & g_KBMInput . IsMouseGrabbed ( ) & & g_KBMInput . IsKBMActive ( ) & & g_KBMInput . IsKeyDown ( KeyboardMouseInput : : KEY_JUMP ) ;
# endif
if ( ( jump > 0 | | kbJump ) & & pMinecraft - > localgameModes [ iPad ] - > isInputAllowed ( MINECRAFT_ACTION_JUMP ) )
2026-03-01 12:16:08 +08:00
jumping = true ;
else
jumping = false ;
# ifndef _CONTENT_PACKAGE
if ( app . GetFreezePlayers ( ) ) jumping = false ;
# endif
2026-03-04 21:19:40 +08:00
# ifdef _WINDOWS64
if ( iPad = = 0 & & g_KBMInput . IsKeyPressed ( VK_ESCAPE ) & & g_KBMInput . IsMouseGrabbed ( ) )
{
g_KBMInput . SetMouseGrabbed ( false ) ;
}
# endif
2026-03-01 12:16:08 +08:00
//OutputDebugString("INPUT: End input tick\n");
2026-03-02 01:21:56 +08:00
}