Skip to content

Commit

Permalink
[Savestates] Reintroduced savestates at the end of the tick
Browse files Browse the repository at this point in the history
- More InfoHud changes
  • Loading branch information
ScribbleTAS committed Jul 27, 2024
1 parent 1af74d5 commit d2e219d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/minecrafttas/tasmod/events/EventClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public static interface EventDrawHotbar extends EventBase {
}

/**
* Fired when drawing something on screen. Always.
* Fired when drawing something on screen. Ignores F1
*/
@FunctionalInterface
public static interface EventDrawHotbarAlways extends EventBase {
/**
* Fired behind the hotbar hotbar is drawn on screen
* Fired when the gui is drawn on screen. Ignores F1
*/
public void onDrawHotbarAlways();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public boolean checkInit() {
+ "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
if (Minecraft.getMinecraft().currentScreen == this)
return "Velocity";
return "Velocity: " + Minecraft.getMinecraft().player.motionX + " " + Minecraft.getMinecraft().player.motionY + " " + Minecraft.getMinecraft().player.motionZ;
return Minecraft.getMinecraft().player.motionX + " " + Minecraft.getMinecraft().player.motionY + " " + Minecraft.getMinecraft().player.motionZ;
}));

title = "desyncstatus";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickContainer;
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiser;
import com.minecrafttas.tasmod.registries.TASmodAPIRegistry;
import com.minecrafttas.tasmod.registries.TASmodPackets;
import com.minecrafttas.tasmod.savestates.exceptions.SavestateException;
import com.minecrafttas.tasmod.savestates.gui.GuiSavestateSavingScreen;
Expand Down Expand Up @@ -248,6 +249,8 @@ public static void loadstate(String nameOfSavestate) throws Exception {
private static void preload(BigArrayList<TickContainer> containerList, long index) {
TickContainer containerToPreload = containerList.get(index);
TASmodClient.virtual.preloadInput(containerToPreload.getKeyboard(), containerToPreload.getMouse(), containerToPreload.getCameraAngle());

TASmodAPIRegistry.PLAYBACK_FILE_COMMAND.onPlaybackTick(index, containerToPreload);
}

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

// Player rotation does not change when loading a savestate
// CameraInterpolationEvents.rotationPitch = player.rotationPitch;
// CameraInterpolationEvents.rotationYaw = player.rotationYaw + 180f;
// Set the camera rotation to the player rotation
TASmodClient.virtual.CAMERA_ANGLE.setCamera(player.rotationPitch, player.rotationYaw);
SubtickDuck entityRenderer = (SubtickDuck) Minecraft.getMinecraft().entityRenderer;
entityRenderer.runUpdate(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.minecrafttas.tasmod.savestates.modules.PlayerHandler;
import com.minecrafttas.tasmod.util.Ducks.ChunkProviderDuck;
import com.minecrafttas.tasmod.util.LoggerMarkers;
import com.minecrafttas.tasmod.util.Scheduler.Task;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -395,11 +396,11 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex
ChunkHandler.addPlayerToServerChunk(player);
});

// WorldServer[] worlds = server.worlds;
//
// for (WorldServer world : worlds) {
// world.tick();
// }
WorldServer[] worlds = server.worlds;

for (WorldServer world : worlds) {
world.tick();
}

if (!tickrate0) {
TASmod.tickratechanger.pauseGame(false);
Expand Down Expand Up @@ -735,7 +736,8 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
switch (packet) {
case SAVESTATE_SAVE:
Integer index = TASmodBufferBuilder.readInt(buf);
TASmod.gameLoopSchedulerServer.add(() -> {

Task savestateTask = () -> {
try {
TASmod.savestateHandlerServer.saveState(index, true);
} catch (SavestateException e) {
Expand All @@ -751,12 +753,17 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
} finally {
TASmod.savestateHandlerServer.state = SavestateState.NONE;
}
});
};

if (TASmod.tickratechanger.ticksPerSecond == 0)
TASmod.gameLoopSchedulerServer.add(savestateTask);
else
TASmod.tickSchedulerServer.add(savestateTask);
break;

case SAVESTATE_LOAD:
int indexing = TASmodBufferBuilder.readInt(buf);
TASmod.gameLoopSchedulerServer.add(() -> {
Task loadstateTask = () -> {
try {
TASmod.savestateHandlerServer.loadState(indexing, true);
} catch (LoadstateException e) {
Expand All @@ -772,7 +779,11 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
LOGGER.error(e);
TASmod.savestateHandlerServer.state = SavestateState.NONE;
}
});
};
if (TASmod.tickratechanger.ticksPerSecond == 0)
TASmod.gameLoopSchedulerServer.add(loadstateTask);
else
TASmod.tickSchedulerServer.add(loadstateTask);
break;

case SAVESTATE_SCREEN:
Expand Down

0 comments on commit d2e219d

Please sign in to comment.