the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Minecraft.h"
3#include "GameMode.h"
4#include "..\Minecraft.World\net.minecraft.world.entity.player.h"
5#include "..\Minecraft.World\net.minecraft.world.level.h"
6#include "..\Minecraft.World\net.minecraft.world.level.storage.h"
7#include "Input.h"
8#include "..\Minecraft.Client\LocalPlayer.h"
9#include "Options.h"
10
11Input::Input()
12{
13 xa = 0;
14 ya = 0;
15 sprintForward = 0;
16 wasJumping = false;
17 jumping = false;
18 sneaking = false;
19 usingKeyboardMovement = false;
20
21 lReset = false;
22 rReset = false;
23 m_gamepadSneaking = false;
24}
25
26void Input::tick(LocalPlayer *player)
27{
28 // 4J Stu - Assume that we only need one input class, even though the java has subclasses for keyboard/controller
29 // This function is based on the ControllerInput class in the Java, and will probably need changed
30 //OutputDebugString("INPUT: Beginning input tick\n");
31
32 Minecraft *pMinecraft=Minecraft::GetInstance();
33 int iPad=player->GetXboxPad();
34
35 // 4J-PB minecraft movement seems to be the wrong way round, so invert x!
36 if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_RIGHT) )
37 xa = -InputManager.GetJoypadStick_LX(iPad);
38 else
39 xa = 0.0f;
40
41 if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD) )
42 ya = InputManager.GetJoypadStick_LY(iPad);
43 else
44 ya = 0.0f;
45 sprintForward = ya;
46 usingKeyboardMovement = false;
47
48#ifdef _WINDOWS64
49 // WASD movement (combine with gamepad)
50 if (iPad == 0 && KMInput.IsCaptured())
51 {
52 float kbX = 0.0f, kbY = 0.0f;
53 if (KMInput.IsKeyDown('W')) { kbY += 1.0f; sprintForward += 1.0f; usingKeyboardMovement = true; }
54 if (KMInput.IsKeyDown('S')) { kbY -= 1.0f; sprintForward -= 1.0f; usingKeyboardMovement = true; }
55 if (KMInput.IsKeyDown('A')) { kbX += 1.0f; usingKeyboardMovement = true; } // inverted like gamepad
56 if (KMInput.IsKeyDown('D')) { kbX -= 1.0f; usingKeyboardMovement = true; }
57 // Normalize diagonal
58 if (kbX != 0.0f && kbY != 0.0f) { kbX *= 0.707f; kbY *= 0.707f; }
59 if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_RIGHT))
60 xa = max(min(xa + kbX, 1.0f), -1.0f);
61 if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD))
62 ya = max(min(ya + kbY, 1.0f), -1.0f);
63 }
64#endif
65 sprintForward = max(min(sprintForward, 1.0f), -1.0f);
66
67#ifndef _CONTENT_PACKAGE
68 if (app.GetFreezePlayers())
69 {
70 xa = ya = 0.0f;
71 sprintForward = 0.0f;
72 player->abilities.flying = true;
73 }
74#endif
75
76 if (!lReset)
77 {
78 if (xa*xa+ya*ya==0.0f)
79 {
80 lReset = true;
81 }
82 xa = ya = 0.0f;
83 sprintForward = 0.0f;
84 }
85
86 // 4J: In flying mode, don't actually toggle sneaking (unless we're riding in which case we need to sneak to dismount)
87 if(!player->abilities.flying || player->riding != NULL)
88 {
89 if((player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_SNEAK_TOGGLE)) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE))
90 {
91 m_gamepadSneaking=!m_gamepadSneaking;
92 }
93 }
94 sneaking = m_gamepadSneaking;
95
96#ifdef _WINDOWS64
97 // Keyboard hold-to-sneak (overrides gamepad toggle)
98 if (iPad == 0 && KMInput.IsCaptured() && KMInput.IsKeyDown(VK_SHIFT) && !player->abilities.flying)
99 sneaking = true;
100#endif
101
102 if(sneaking)
103 {
104 xa*=0.3f;
105 ya*=0.3f;
106 }
107
108 float turnSpeed = 50.0f;
109
110 float tx = 0.0f;
111 float ty = 0.0f;
112 if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_RIGHT) )
113 tx = InputManager.GetJoypadStick_RX(iPad)*(((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InGame))/100.0f); // apply sensitivity to look
114 if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_UP) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LOOK_DOWN) )
115 ty = InputManager.GetJoypadStick_RY(iPad)*(((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InGame))/100.0f); // apply sensitivity to look
116
117#ifndef _CONTENT_PACKAGE
118 if (app.GetFreezePlayers()) tx = ty = 0.0f;
119#endif
120
121 // 4J: WESTY : Invert look Y if required.
122 if ( app.GetGameSettings(iPad,eGameSetting_ControlInvertLook) )
123 {
124 ty = -ty;
125 }
126
127 if (!rReset)
128 {
129 if (tx*tx+ty*ty==0.0f)
130 {
131 rReset = true;
132 }
133 tx = ty = 0.0f;
134 }
135 player->interpolateTurn(tx * abs(tx) * turnSpeed, ty * abs(ty) * turnSpeed);
136
137#ifdef _WINDOWS64
138 // Mouse look is now handled per-frame in Minecraft::applyFrameMouseLook()
139 // to eliminate the 20Hz tick delay. Only flush any remaining delta here
140 // as a safety measure.
141 if (iPad == 0 && KMInput.IsCaptured())
142 {
143 float rawDx, rawDy;
144 KMInput.ConsumeMouseDelta(rawDx, rawDy);
145 // Delta should normally be 0 since applyFrameMouseLook() already consumed it
146 if (rawDx != 0.0f || rawDy != 0.0f)
147 {
148 float mouseSensitivity = 0.5f;
149 float mdx = rawDx * mouseSensitivity;
150 float mdy = -rawDy * mouseSensitivity;
151 if (app.GetGameSettings(iPad, eGameSetting_ControlInvertLook))
152 mdy = -mdy;
153 player->interpolateTurn(mdx, mdy);
154 }
155 }
156#endif
157
158 //jumping = controller.isButtonPressed(0);
159
160
161 unsigned int jump = InputManager.GetValue(iPad, MINECRAFT_ACTION_JUMP);
162 if( jump > 0 && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP) )
163 jumping = true;
164 else
165 jumping = false;
166
167#ifdef _WINDOWS64
168 // Keyboard jump (Space)
169 if (iPad == 0 && KMInput.IsCaptured() && KMInput.IsKeyDown(VK_SPACE) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP))
170 jumping = true;
171#endif
172
173#ifndef _CONTENT_PACKAGE
174 if (app.GetFreezePlayers()) jumping = false;
175#endif
176
177 //OutputDebugString("INPUT: End input tick\n");
178}