Skip to content

Commit

Permalink
[Savestates] Fixed camera not being correctly applied after loadstate
Browse files Browse the repository at this point in the history
  • Loading branch information
ScribbleTAS committed Jul 27, 2024
1 parent 030e215 commit 1af74d5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.minecrafttas.tasmod.mixin.events;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.minecrafttas.mctcommon.events.EventListenerRegistry;
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbarAlways;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.GlStateManager;

@Mixin(EntityRenderer.class)
public class MixinEntityRenderer {

@Shadow
private Minecraft mc;

@Inject(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V"))
public void inject_onRenderGameOverlay(CallbackInfo ci) {
ScaledResolution scaledResolution = new ScaledResolution(this.mc);
GlStateManager.clear(256);
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
GlStateManager.ortho(0.0, scaledResolution.getScaledWidth_double(), scaledResolution.getScaledHeight_double(), 0.0, 1000.0, 3000.0);
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
GlStateManager.translate(0.0F, 0.0F, -2000.0F);
EventListenerRegistry.fireEvent(EventDrawHotbarAlways.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.minecrafttas.tasmod.savestates.exceptions.SavestateException;
import com.minecrafttas.tasmod.savestates.gui.GuiSavestateSavingScreen;
import com.minecrafttas.tasmod.util.Ducks.ChunkProviderDuck;
import com.minecrafttas.tasmod.util.Ducks.SubtickDuck;
import com.minecrafttas.tasmod.util.LoggerMarkers;
import com.mojang.realmsclient.gui.ChatFormatting;

Expand Down Expand Up @@ -287,9 +288,12 @@ public static void loadPlayer(NBTTagCompound compound) {
GameType type = GameType.getByID(gamemode);
mc.playerController.setGameType(type);

// #?? Player rotation does not change when loading a savestate
// Player rotation does not change when loading a savestate
// CameraInterpolationEvents.rotationPitch = player.rotationPitch;
// CameraInterpolationEvents.rotationYaw = player.rotationYaw + 180f;
TASmodClient.virtual.CAMERA_ANGLE.setCamera(player.rotationPitch, player.rotationYaw);
SubtickDuck entityRenderer = (SubtickDuck) Minecraft.getMinecraft().entityRenderer;
entityRenderer.runUpdate(0);

SavestateHandlerClient.keepPlayerInLoadedEntityList(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.minecrafttas.tasmod.mixin.playbackhooks.MixinEntityRenderer;
import com.minecrafttas.tasmod.mixin.playbackhooks.MixinMinecraft;
import com.minecrafttas.tasmod.util.Ducks;
import com.minecrafttas.tasmod.util.Ducks.SubtickDuck;
import com.minecrafttas.tasmod.util.LoggerMarkers;
import com.minecrafttas.tasmod.util.PointerNormalizer;
import com.minecrafttas.tasmod.virtual.event.VirtualKeyboardEvent;
Expand Down Expand Up @@ -144,8 +145,9 @@ public void preloadInput(VirtualKeyboard keyboardToPreload, VirtualMouse mouseTo
MOUSE.nextMouse.deepCopyFrom(mouseToPreload);
CAMERA_ANGLE.nextCameraAngle.deepCopyFrom(angleToPreload);
Minecraft.getMinecraft().runTickKeyboard(); // Letting mouse and keyboard tick once to load inputs into the "currentKeyboard"
//
Minecraft.getMinecraft().runTickMouse();
SubtickDuck entityRenderer = (SubtickDuck) Minecraft.getMinecraft().entityRenderer;
entityRenderer.runUpdate(0);
}

public List<String> getCurrentMousePresses() {
Expand Down Expand Up @@ -615,10 +617,10 @@ public void updateNextCameraAngle(float pitchDelta, float yawDelta) {
* <br>
* Runs every frame
*
* @see com.minecrafttas.tasmod.mixin.playbackhooks.MixinEntityRenderer#runUpdate(float);
* @param pitchDelta Relative rotationPitch delta from LWJGLs mouse delta.
* @param yawDelta Relative rotationYaw delta from LWJGLs mouse delta.
* @param updateSubtick Whether to add the previous camera angle to the {@link Subtickable#subtickList}
* @see MixinEntityRenderer#runUpdate(float)
*/
public void updateNextCameraAngle(float pitchDelta, float yawDelta, boolean updateSubtick) {
// LOGGER.debug("Pitch: {}, Yaw: {}", pitch, yaw);
Expand Down

0 comments on commit 1af74d5

Please sign in to comment.