Stop spectating when applying camera keyframe

This commit is contained in:
Moulberry committed 2025-02-11 18:31:09 +08:00
1 parent 7b9f11f60d
commit a6bb7bf506
4 files changed
+22

No files matched your search

@@ -10,6 +10,7 @@ import com.moulberry.flashback.editor.ui.ReplayUI;
import com.moulberry.flashback.keyframe.KeyframeType;
import com.moulberry.flashback.keyframe.KeyframeRegistry;
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
import com.moulberry.flashback.record.ReplayMarker;
import com.moulberry.flashback.state.EditorScene;
@@ -1730,6 +1731,11 @@ public class TimelineWindow {
ImGui.setCursorPosX(buttonX - x);
if (ImGui.invisibleButton("##Add", buttonSize, buttonSize)) {
createNewKeyframe(trackIndex, cursorTicks, keyframeType, keyframeTrack);
if (keyframeType instanceof CameraKeyframeType && Minecraft.getInstance().player != Minecraft.getInstance().cameraEntity) {
ReplayUI.setInfoOverlay("Warning: Don't use Camera keyframes for spectating a player");
Minecraft.getInstance().getConnection().sendUnsignedCommand("spectate");
}
}
drawList.addText(buttonX - 2, buttonY, -1, "\ue148");
ImGuiHelper.tooltip("Add keyframe");
@@ -25,6 +25,10 @@ public record MinecraftKeyframeHandler(Minecraft minecraft) implements KeyframeH
public void applyCameraPosition(Vector3d position, double yaw, double pitch, double roll) {
LocalPlayer player = this.minecraft.player;
if (player != null) {
if (this.minecraft.cameraEntity != this.minecraft.player) {
Minecraft.getInstance().getConnection().sendUnsignedCommand("spectate");
}
player.moveTo(position.x, position.y, position.z, (float) yaw, (float) pitch);
EditorState editorState = EditorStateManager.getCurrent();
@@ -9,9 +9,11 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stat;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.biome.BiomeManager;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.UUID;
@@ -43,6 +45,15 @@ public class ReplayPlayer extends ServerPlayer {
serverLevel.isDebug(), serverLevel.isFlat(), this.getLastDeathLocation(), this.getPortalCooldown());
}
@Override
public void setCamera(@Nullable Entity entity) {
super.setCamera(entity);
if (entity == null) {
this.spectatingUuid = null;
}
}
@Override
public int awardRecipes(Collection<RecipeHolder<?>> collection) {
return 0;
@@ -885,6 +885,7 @@ public class ReplayServer extends IntegratedServer {
if (targetEntity != null && !targetEntity.isRemoved()) {
replayViewer.setCamera(null);
replayViewer.setCamera(targetEntity);
replayViewer.spectatingUuid = targetEntity.getUUID();
if (replayViewer.forceRespectateTickCount == 0) {
replayViewer.forceRespectateTickCount = 5;