Skip to content

Commit 9cb5f67

Browse files
ScribbleScribble
authored andcommitted
Changes to input loading in ClientSavestates
- Loading a Client Savestate that doesn't exist prompted the container to clear all inputs. This is now removed. - If nothing is playing, inputs won't be overriden by the client savestates anmore, only when recording or playing back
1 parent 054f6cb commit 9cb5f67

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/main/java/de/scribble/lp/tasmod/savestates/client/InputSavestatesHandler.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
import java.io.File;
44
import java.io.IOException;
55

6+
import com.mojang.realmsclient.gui.ChatFormatting;
7+
68
import de.scribble.lp.tasmod.ClientProxy;
79
import de.scribble.lp.tasmod.CommonProxy;
10+
import de.scribble.lp.tasmod.TASmod;
811
import de.scribble.lp.tasmod.inputcontainer.InputContainer;
912
import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateException;
13+
import de.scribble.lp.tasmod.util.TASstate;
14+
import net.minecraft.client.Minecraft;
15+
import net.minecraft.util.text.TextComponentString;
1016
import net.minecraftforge.fml.relauncher.Side;
1117
import net.minecraftforge.fml.relauncher.SideOnly;
1218

@@ -43,9 +49,9 @@ public static void savestate(String nameOfSavestate) throws SavestateException,
4349

4450
InputContainer container = ClientProxy.virtual.getContainer();
4551
if (container.isRecording()) {
46-
ClientProxy.serialiser.saveToFileV1(targetfile, container);
52+
ClientProxy.serialiser.saveToFileV1(targetfile, container); //If the container is recording, store it entirely
4753
} else if(container.isPlayingback()){
48-
ClientProxy.serialiser.saveToFileV1Until(targetfile, container, container.index());
54+
ClientProxy.serialiser.saveToFileV1Until(targetfile, container, container.index()); //If the container is playing, store it until the current index
4955
}
5056
}
5157

@@ -68,10 +74,16 @@ public static void loadstate(String nameOfSavestate) throws IOException {
6874

6975
File targetfile = new File(savestateDirectory, nameOfSavestate + ".tas");
7076

71-
if (!targetfile.exists()) {
72-
ClientProxy.virtual.getContainer().clear();
73-
} else {
74-
ClientProxy.virtual.loadSavestate(ClientProxy.serialiser.fromEntireFileV1(targetfile));
77+
InputContainer container = ClientProxy.virtual.getContainer();
78+
if (!container.isNothingPlaying()) { // If the file exists and the container is recording or playing, load the clientSavestate
79+
if (targetfile.exists()) {
80+
ClientProxy.virtual.loadClientSavestate(ClientProxy.serialiser.fromEntireFileV1(targetfile));
81+
} else {
82+
ClientProxy.virtual.getContainer().setTASState(TASstate.NONE, false);
83+
Minecraft.getMinecraft().player.sendMessage(new TextComponentString(ChatFormatting.YELLOW
84+
+ "Inputs could not be loaded for this savestate, since the file doesn't exist. Stopping!"));
85+
TASmod.logger.warn("Inputs could not be loaded for this savestate, since the file doesn't exist.");
86+
}
7587
}
7688
}
7789
}

0 commit comments

Comments
 (0)