Skip to content

Commit 0915358

Browse files
committed
[VirtualInput] Clean up camera changes
- Adjusted documentation - Move VirtualInput#clear from onDoneLoadingPlayer to onPlayerJoinedClientSide - Renamed VirtualInput#clear to VirtualInput#clearKeys for clarity - Added clearNext methods to Keyboard and Mouse to be able to clear individual input methods. Also to be consistent with the camera angle
1 parent a8786bc commit 0915358

File tree

5 files changed

+52
-29
lines changed

5 files changed

+52
-29
lines changed

src/main/java/com/minecrafttas/mctcommon/events/EventClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ public static interface EventDoneLoadingWorld extends EventBase {
6262
}
6363

6464
/**
65-
* Fired when the player is done loading, after the position has been loaded from the server side
65+
* Fired when the player is done loading, after the position has been loaded from the server side.<br>
66+
* This also fires every time the player switches dimensions.
67+
*
6668
* @author Scribble
6769
* @see NetHandlerPlayClient#handlePlayerPosLook(net.minecraft.network.play.server.SPacketPlayerPosLook)
6870
*/
6971
@FunctionalInterface
7072
public static interface EventDoneLoadingPlayer extends EventBase {
7173

7274
/**
73-
* Fired when the player is done loading, after the position has been loaded from the server side
75+
* Fired when the player is done loading, after the position has been loaded from the server side.<br>
76+
* This also fires every time the player switches dimensions.
77+
*
7478
* @see NetHandlerPlayClient#handlePlayerPosLook(net.minecraft.network.play.server.SPacketPlayerPosLook)
7579
*/
7680
public void onDoneLoadingPlayer();

src/main/java/com/minecrafttas/tasmod/handlers/LoadingScreenHandler.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
import com.minecrafttas.mctcommon.events.EventClient.EventDoneLoadingPlayer;
77
import com.minecrafttas.mctcommon.events.EventClient.EventDoneLoadingWorld;
88
import com.minecrafttas.mctcommon.events.EventClient.EventLaunchIntegratedServer;
9+
import com.minecrafttas.mctcommon.events.EventClient.EventPlayerJoinedClientSide;
910
import com.minecrafttas.mctcommon.events.EventClient.EventPlayerLeaveClientSide;
1011
import com.minecrafttas.tasmod.TASmod;
1112
import com.minecrafttas.tasmod.TASmodClient;
12-
import com.minecrafttas.tasmod.mixin.playbackhooks.MixinEntityRenderer;
1313
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
1414
import com.minecrafttas.tasmod.util.LoggerMarkers;
15-
import com.minecrafttas.tasmod.virtual.VirtualInput;
1615
import com.minecrafttas.tasmod.virtual.VirtualInput.VirtualCameraAngleInput;
1716

1817
import net.minecraft.client.Minecraft;
@@ -23,7 +22,7 @@
2322
*
2423
* @author Scribble
2524
*/
26-
public class LoadingScreenHandler implements EventLaunchIntegratedServer, EventClientGameLoop, EventDoneLoadingWorld, EventDoneLoadingPlayer, EventPlayerLeaveClientSide {
25+
public class LoadingScreenHandler implements EventLaunchIntegratedServer, EventClientGameLoop, EventDoneLoadingWorld, EventDoneLoadingPlayer, EventPlayerJoinedClientSide, EventPlayerLeaveClientSide {
2726

2827
private boolean waszero;
2928
private boolean isLoading;
@@ -78,17 +77,7 @@ public boolean isLoading() {
7877
/**
7978
* {@inheritDoc}
8079
*
81-
* <p>Fixes an issue, where the look position of the player is reset to 0 -180,<br>
82-
* As well as removing any keyboard inputs present in the main menu
83-
*
84-
* <p>{@link MixinEntityRenderer#runUpdate(float)} rewrites the camera input,<br>
85-
* So that it can be used with interpolation. <br>
86-
* However, when you start the game, this camera input needs to be initialised with the current look position from the server.<br>
87-
* So a special condition is set, that if the {@link VirtualInput#CAMERA_ANGLE} is null,<br>
88-
* it intialises the {@link VirtualInput#CAMERA_ANGLE CAMERA_ANGLE} with the current player camera angle.
89-
*
90-
* <p>So {@link VirtualInput#clear()} has to be called at the right moment in the player initialisation<br>
91-
* to set the correct values. Before that, the playerRotation defaults to 0 -180
80+
* <p>Initializes the virtual camera to be in line with the vanilla camera.
9281
*/
9382
@Override
9483
public void onDoneLoadingPlayer() {
@@ -99,15 +88,29 @@ public void onDoneLoadingPlayer() {
9988
Minecraft mc = Minecraft.getMinecraft();
10089
EntityPlayerSP player = mc.player;
10190
cameraAngle.setCamera(player.rotationPitch, player.rotationYaw);
102-
TASmodClient.virtual.clear();
10391
}
10492
}
10593

94+
/**
95+
* {@inheritDoc}
96+
*
97+
* <p>Fixes stuck keys when loading the world
98+
*/
99+
@Override
100+
public void onPlayerJoinedClientSide(EntityPlayerSP player) {
101+
TASmodClient.virtual.clearKeys();
102+
}
103+
104+
/**
105+
* {@inheritDoc}
106+
*
107+
* <p>Resets the camera angle when leaving the world.
108+
* <p>If you later rejoin the world {@link #onDoneLoadingPlayer()} will re-initialise the camera angle
109+
*/
106110
@Override
107111
public void onPlayerLeaveClientSide(EntityPlayerSP player) {
108112
LOGGER.debug(LoggerMarkers.Event, "Finished leaving on the on the client side");
109-
LOGGER.debug("Resetting pitch and yaw");
110-
TASmodClient.virtual.CAMERA_ANGLE.clear();
113+
LOGGER.debug("Resetting the camera angle on leaving the world");
114+
TASmodClient.virtual.CAMERA_ANGLE.clearNext();
111115
}
112-
113116
}

src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public String setTASStateClient(TASstate stateIn, boolean verbose) {
245245
LOGGER.debug(LoggerMarkers.Playback, "Pausing a playback");
246246
state = TASstate.PAUSED;
247247
stateAfterPause = TASstate.PLAYBACK;
248-
TASmodClient.virtual.clear();
248+
TASmodClient.virtual.clearKeys();
249249
return verbose ? TextFormatting.GREEN + "Pausing a playback" : "";
250250
case NONE:
251251
stopPlayback(true);
@@ -291,7 +291,7 @@ private void startRecording() {
291291

292292
private void stopRecording() {
293293
LOGGER.debug(LoggerMarkers.Playback, "Stopping a recording");
294-
TASmodClient.virtual.clear();
294+
TASmodClient.virtual.clearKeys();
295295
}
296296

297297
private void startPlayback() {
@@ -305,7 +305,7 @@ private void stopPlayback(boolean clearInputs) {
305305
LOGGER.debug(LoggerMarkers.Playback, "Stopping a playback");
306306
Minecraft.getMinecraft().gameSettings.chatLinks = true;
307307
if (clearInputs) {
308-
TASmodClient.virtual.clear();
308+
TASmodClient.virtual.clearKeys();
309309
}
310310
}
311311

src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static void loadstate(String nameOfSavestate) throws Exception {
203203

204204
preload(savestateContainerList, index);
205205
controller.setInputs(savestateContainerList, index);
206-
TASmodClient.virtual.clear();
206+
TASmodClient.virtual.clearKeys();
207207
}
208208
/*
209209
* When loading a savestate during a playback 2 different scenarios can happen.
@@ -237,7 +237,7 @@ else if (state == TASstate.PLAYBACK) {
237237

238238
preload(controller.getInputs(), index);
239239
controller.setIndex(index);
240-
TASmodClient.virtual.clear();
240+
TASmodClient.virtual.clearKeys();
241241
}
242242
/*
243243
* Scenario 2:

src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ public boolean willKeyBeDown(int keycode) {
134134
/**
135135
* Unpresses all keys in {@link VirtualKeyboardInput#nextKeyboard} and {@link VirtualMouseInput#nextMouse}
136136
*/
137-
public void clear() {
138-
KEYBOARD.nextKeyboard.clear();
139-
MOUSE.nextMouse.clear();
137+
public void clearKeys() {
138+
KEYBOARD.clearNext();
139+
MOUSE.clearNext();
140140
}
141141

142142
public void preloadInput(VirtualKeyboard keyboardToPreload, VirtualMouse mouseToPreload, VirtualCameraAngle angleToPreload) {
@@ -339,6 +339,13 @@ public boolean isKeyDown(int keycode) {
339339
public boolean willKeyBeDown(int keycode) {
340340
return nextKeyboard.isKeyDown(keycode);
341341
}
342+
343+
/**
344+
* Clears the {@link #nextKeyboard}
345+
*/
346+
public void clearNext() {
347+
nextKeyboard.clear();
348+
}
342349
}
343350

344351
/**
@@ -530,6 +537,12 @@ public boolean willKeyBeDown(int keycode) {
530537
return nextMouse.isKeyDown(keycode);
531538
}
532539

540+
/**
541+
* Clears the {@link #nextMouse}
542+
*/
543+
public void clearNext() {
544+
nextMouse.clear();
545+
}
533546
}
534547

535548
/**
@@ -710,7 +723,10 @@ public Triple<Float, Float, Float> getInterpolatedState(float partialTick, float
710723
return Triple.of(interpolatedPitch, interpolatedYaw, 0f);
711724
}
712725

713-
public void clear() {
726+
/**
727+
* Clears the {@link #nextCameraAngle}
728+
*/
729+
public void clearNext() {
714730
nextCameraAngle.clear();
715731
}
716732
}

0 commit comments

Comments
 (0)