diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.Client/Input.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.Client/Input.cpp')
| -rw-r--r-- | Minecraft.Client/Input.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/Minecraft.Client/Input.cpp b/Minecraft.Client/Input.cpp new file mode 100644 index 00000000..645f3477 --- /dev/null +++ b/Minecraft.Client/Input.cpp @@ -0,0 +1,118 @@ +#include "stdafx.h" +#include "Minecraft.h" +#include "GameMode.h" +#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" +#include "Input.h" +#include "..\Minecraft.Client\LocalPlayer.h" +#include "Options.h" + +Input::Input() +{ + xa = 0; + ya = 0; + wasJumping = false; + jumping = false; + sneaking = false; + + 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(); + + // 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) ) + xa = -InputManager.GetJoypadStick_LX(iPad); + else + xa = 0.0f; + + if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD) ) + ya = InputManager.GetJoypadStick_LY(iPad); + else + ya = 0.0f; + +#ifndef _CONTENT_PACKAGE + if (app.GetFreezePlayers()) + { + xa = ya = 0.0f; + player->abilities.flying = true; + } +#endif + + if (!lReset) + { + if (xa*xa+ya*ya==0.0f) + { + lReset = true; + } + xa = ya = 0.0f; + } + + // 4J - in flying mode, don't actually toggle sneaking + if(!player->abilities.flying) + { + if((player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_SNEAK_TOGGLE)) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE)) + { + sneaking=!sneaking; + } + } + + if(sneaking) + { + xa*=0.3f; + ya*=0.3f; + } + + float turnSpeed = 50.0f; + + float tx = 0.0f; + float ty = 0.0f; + if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_RIGHT) ) + tx = InputManager.GetJoypadStick_RX(iPad)*(((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InGame))/100.0f); // apply sensitivity to look + if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_UP) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_DOWN) ) + ty = InputManager.GetJoypadStick_RY(iPad)*(((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InGame))/100.0f); // apply sensitivity to look + +#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; + } + player->interpolateTurn(tx * abs(tx) * turnSpeed, ty * abs(ty) * turnSpeed); + + //jumping = controller.isButtonPressed(0); + + + unsigned int jump = InputManager.GetValue(iPad, MINECRAFT_ACTION_JUMP); + if( jump > 0 && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP) ) + jumping = true; + else + jumping = false; + +#ifndef _CONTENT_PACKAGE + if (app.GetFreezePlayers()) jumping = false; +#endif + + //OutputDebugString("INPUT: End input tick\n"); +}
\ No newline at end of file |
