mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 14:38:50 +00:00
Prevent recording replay with incompatible mods
This commit is contained in:
1 parent
aaae3b946f
commit
b2ebee3cb8
2 files changed
+125
-56
No files matched your search
@@ -66,9 +66,7 @@ import net.minecraft.FileUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.toasts.SystemToast;
|
||||
import net.minecraft.client.gui.screens.PauseScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.gui.screens.*;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
@@ -98,6 +96,7 @@ import net.minecraft.world.level.levelgen.WorldOptions;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.PrimaryLevelData;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -141,6 +140,7 @@ public class Flashback implements ModInitializer, ClientModInitializer {
|
||||
|
||||
private static final List<Path> pendingReplaySave = new ArrayList<>();
|
||||
private static final List<Path> pendingReplayRecovery = new ArrayList<>();
|
||||
private static List<String> pendingUnsupportedModsForRecording = null;
|
||||
|
||||
public static ResourceLocation createResourceLocation(String value) {
|
||||
return ResourceLocation.fromNamespaceAndPath("flashback", value);
|
||||
@@ -391,59 +391,8 @@ public class Flashback implements ModInitializer, ClientModInitializer {
|
||||
});
|
||||
|
||||
ClientTickEvents.START_CLIENT_TICK.register(minecraft -> {
|
||||
if (unsupportedLoader.get() != null && canReplaceScreen(Minecraft.getInstance().screen)) {
|
||||
String loaderName = unsupportedLoader.get();
|
||||
if (System.currentTimeMillis() > Flashback.getConfig().nextUnsupportedModLoaderWarning) {
|
||||
String warning = String.format("""
|
||||
You are using an unsupported modloader: %s
|
||||
|
||||
Do not report crashes, bugs or other issues to Flashback
|
||||
|
||||
You will not receive support from Flashback
|
||||
|
||||
If you need assistance, please contact %s
|
||||
""", loaderName, loaderName);
|
||||
|
||||
Minecraft.getInstance().setScreen(new UnsupportedLoaderScreen(Minecraft.getInstance().screen,
|
||||
Component.literal("Flashback: Unsupported"), Component.literal(warning)));
|
||||
}
|
||||
unsupportedLoader.set(null);
|
||||
}
|
||||
|
||||
if (!pendingReplayRecovery.isEmpty() && canReplaceScreen(Minecraft.getInstance().screen)) {
|
||||
Component title = Component.literal("Flashback: Recovery");
|
||||
Component description = Component.empty()
|
||||
.append(Component.literal("Flashback has detected ").append(Component.literal("unfinished recordings\n").withStyle(ChatFormatting.YELLOW)))
|
||||
.append(Component.literal("This is usually because the game closed unexpectedly while recording\n\n"))
|
||||
.append(Component.literal("Unfortunately, up to 5 minutes of gameplay from the end of the recording may be lost\n\n").withStyle(ChatFormatting.RED)
|
||||
.append(Component.literal("Would you like to try to recover the recording?").withStyle(ChatFormatting.GREEN)));
|
||||
Minecraft.getInstance().setScreen(new RecoverRecordingsScreen(Minecraft.getInstance().screen, title, description, recover -> {
|
||||
switch (recover) {
|
||||
case RECOVER -> {
|
||||
pendingReplaySave.addAll(pendingReplayRecovery);
|
||||
pendingReplayRecovery.clear();
|
||||
}
|
||||
case SKIP -> {
|
||||
pendingReplayRecovery.clear();
|
||||
}
|
||||
case DELETE -> {
|
||||
TempFolderProvider.tryDeleteStaleFolders(TempFolderProvider.TempFolderType.RECORDING);
|
||||
pendingReplayRecovery.clear();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
if (!pendingReplaySave.isEmpty()) {
|
||||
Screen currentScreen = Minecraft.getInstance().screen;
|
||||
if (canReplaceScreen(currentScreen)) {
|
||||
Path recordFolder = pendingReplaySave.getFirst();
|
||||
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
dateTime = dateTime.withNano(0);
|
||||
Minecraft.getInstance().setScreen(new SaveReplayScreen(Minecraft.getInstance().screen,
|
||||
recordFolder, dateTime.toString()));
|
||||
}
|
||||
if (canReplaceScreen(Minecraft.getInstance().screen)) {
|
||||
openNewScreen(unsupportedLoader);
|
||||
}
|
||||
|
||||
if (Minecraft.getInstance().level != null && delayedStartRecording > 0) {
|
||||
@@ -481,6 +430,77 @@ public class Flashback implements ModInitializer, ClientModInitializer {
|
||||
}
|
||||
}
|
||||
|
||||
private static void openNewScreen(AtomicReference<String> unsupportedLoader) {
|
||||
if (unsupportedLoader.get() != null) {
|
||||
String loaderName = unsupportedLoader.get();
|
||||
unsupportedLoader.set(null);
|
||||
if (System.currentTimeMillis() > Flashback.getConfig().nextUnsupportedModLoaderWarning) {
|
||||
String warning = String.format("""
|
||||
You are using an unsupported modloader: %s
|
||||
|
||||
Do not report crashes, bugs or other issues to Flashback
|
||||
|
||||
You will not receive support from Flashback
|
||||
|
||||
If you need assistance, please contact %s
|
||||
""", loaderName, loaderName);
|
||||
|
||||
Minecraft.getInstance().setScreen(new UnsupportedLoaderScreen(Minecraft.getInstance().screen,
|
||||
Component.literal("Flashback: Unsupported"), Component.literal(warning)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pendingReplayRecovery.isEmpty()) {
|
||||
Component title = Component.literal("Flashback: Recovery");
|
||||
Component description = Component.empty()
|
||||
.append(Component.literal("Flashback has detected ").append(Component.literal("unfinished recordings\n").withStyle(ChatFormatting.YELLOW)))
|
||||
.append(Component.literal("This is usually because the game closed unexpectedly while recording\n\n"))
|
||||
.append(Component.literal("Unfortunately, up to 5 minutes of gameplay from the end of the recording may be lost\n\n").withStyle(ChatFormatting.RED)
|
||||
.append(Component.literal("Would you like to try to recover the recording?").withStyle(ChatFormatting.GREEN)));
|
||||
Minecraft.getInstance().setScreen(new RecoverRecordingsScreen(Minecraft.getInstance().screen, title, description, recover -> {
|
||||
switch (recover) {
|
||||
case RECOVER -> {
|
||||
pendingReplaySave.addAll(pendingReplayRecovery);
|
||||
pendingReplayRecovery.clear();
|
||||
}
|
||||
case SKIP -> {
|
||||
pendingReplayRecovery.clear();
|
||||
}
|
||||
case DELETE -> {
|
||||
TempFolderProvider.tryDeleteStaleFolders(TempFolderProvider.TempFolderType.RECORDING);
|
||||
pendingReplayRecovery.clear();
|
||||
}
|
||||
}
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pendingReplaySave.isEmpty()) {
|
||||
Path recordFolder = pendingReplaySave.getFirst();
|
||||
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
dateTime = dateTime.withNano(0);
|
||||
Minecraft.getInstance().setScreen(new SaveReplayScreen(Minecraft.getInstance().screen,
|
||||
recordFolder, dateTime.toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pendingUnsupportedModsForRecording != null) {
|
||||
String mods = StringUtils.join(pendingUnsupportedModsForRecording, ", ");
|
||||
String description = """
|
||||
You have mods which are known to cause issues when recording replays
|
||||
Please remove the following mods in order to be able to record replays:
|
||||
|
||||
""";
|
||||
Screen screen = Minecraft.getInstance().screen;
|
||||
Minecraft.getInstance().setScreen(new AlertScreen(() -> Minecraft.getInstance().setScreen(screen),
|
||||
Component.literal("Incompatible Mods"), Component.literal(description).append(Component.literal(mods).withStyle(ChatFormatting.RED))));
|
||||
pendingUnsupportedModsForRecording = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getReplayIncompatibleMods() {
|
||||
List<String> incompatible = new ArrayList<>();
|
||||
if (FabricLoader.getInstance().isModLoaded("vmp")) {
|
||||
@@ -492,6 +512,17 @@ public class Flashback implements ModInitializer, ClientModInitializer {
|
||||
return incompatible;
|
||||
}
|
||||
|
||||
public static List<String> getRecordingIncompatibleMods() {
|
||||
List<String> incompatible = new ArrayList<>();
|
||||
if (FabricLoader.getInstance().isModLoaded("farsight")) {
|
||||
incompatible.add("Farsight");
|
||||
}
|
||||
if (incompatible.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return incompatible;
|
||||
}
|
||||
|
||||
private static @Nullable String findUnsupportedLoaders() {
|
||||
if (FabricLoader.getInstance().isModLoaded("feather")) {
|
||||
return "Feather Client";
|
||||
@@ -692,6 +723,13 @@ public class Flashback implements ModInitializer, ClientModInitializer {
|
||||
Component.literal("Already Recording"), Component.literal("Cannot start new recording when already recording"));
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> unsupported = getRecordingIncompatibleMods();
|
||||
if (unsupported != null && !unsupported.isEmpty()) {
|
||||
pendingUnsupportedModsForRecording = unsupported;
|
||||
return;
|
||||
}
|
||||
|
||||
RECORDER = new Recorder(Minecraft.getInstance().player.registryAccess());
|
||||
if (Flashback.getConfig().showRecordingToasts) {
|
||||
SystemToast.add(Minecraft.getInstance().getToasts(), FlashbackSystemToasts.RECORDING_TOAST,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.moulberry.flashback.mixin.playback;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.moulberry.flashback.playback.ReplayServer;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MixinMinecraftServer {
|
||||
|
||||
/*
|
||||
* Force the server to use the pending tags we gathered instead of trying
|
||||
* to load them from the resource pack repository where it doesn't exist
|
||||
*/
|
||||
|
||||
@WrapOperation(method = "method_29437", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;loadTagsForExistingRegistries(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/RegistryAccess;)Ljava/util/List;"))
|
||||
public List<Registry.PendingTags<?>> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryAccess, Operation<List<Registry.PendingTags<?>>> original) {
|
||||
if ((Object) this instanceof ReplayServer replayServer && replayServer.overridePendingTags != null) {
|
||||
return replayServer.overridePendingTags;
|
||||
}
|
||||
return original.call(resourceManager, registryAccess);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user