Skip to content

Commit 5b91d9e

Browse files
committed
[Savestates] Add warning screen when resources.zip is present
Specifically, if the resources.zip and the user is loadstating is present, then it will show a message saying that the loadstating takes severely longer Added a MessageUtils helper that can split lines with "\n" into multiple lines automatically
1 parent 79bcbc2 commit 5b91d9e

File tree

6 files changed

+72
-5
lines changed

6 files changed

+72
-5
lines changed

src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinMinecraft.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class MixinMinecraft {
1515
@Inject(method = "refreshResources", at = @At(value = "RETURN"))
1616
public void inject_refreshResources(CallbackInfo ci) {
1717
if (SavestateResourcePackHandler.clientRPLatch != null && SavestateResourcePackHandler.clientRPLatch.getCount() > 0) {
18-
System.out.println("Countdown");
1918
SavestateResourcePackHandler.clientRPLatch.countDown();
2019
}
2120
}

src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.minecrafttas.tasmod.TASmodClient;
88
import com.minecrafttas.tasmod.networking.TASmodBufferBuilder;
99
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
10-
import com.minecrafttas.tasmod.savestates.gui.GuiResourcepackWarn;
1110
import com.minecrafttas.tasmod.virtual.VirtualKeybindings;
1211

1312
import net.minecraft.client.Minecraft;
@@ -41,7 +40,6 @@ public enum TASmodKeybinds {
4140
}),
4241

4342
TEST1("Various Testing", "TASmod", Keyboard.KEY_F12, () -> {
44-
Minecraft.getMinecraft().displayGuiScreen(new GuiResourcepackWarn());
4543
}, VirtualKeybindings::isKeyDown),
4644
TEST2("Various Testing2", "TASmod", Keyboard.KEY_F7, () -> {
4745
}, VirtualKeybindings::isKeyDown);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.minecrafttas.tasmod.savestates.gui;
2+
3+
import com.minecrafttas.tasmod.util.MessageUtils;
4+
5+
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.gui.GuiScreen;
7+
import net.minecraft.client.gui.ScaledResolution;
8+
import net.minecraft.client.resources.I18n;
9+
10+
/**
11+
* Screen for warning the player that a "reources.zip" is present in the world folder,<br>
12+
* which significantly slows down savestates
13+
*/
14+
public class GuiResourcepackWarn extends GuiScreen {
15+
16+
/**
17+
* Screen for warning the player that a "reources.zip" is present in the world folder,<br>
18+
* which significantly slows down savestates
19+
*/
20+
public GuiResourcepackWarn() {
21+
this.mc = Minecraft.getMinecraft();
22+
}
23+
24+
@Override
25+
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
26+
this.drawDefaultBackground();
27+
28+
ScaledResolution scaled = new ScaledResolution(Minecraft.getMinecraft());
29+
int width = scaled.getScaledWidth();
30+
int height = scaled.getScaledHeight();
31+
32+
MessageUtils.splitNewline(I18n.format("gui.tasmod.savestate.resourcepack"), 15, (line, y) -> {
33+
drawCenteredString(fontRenderer, line, width / 2, height / 4 + 40 + y, 0xFF5555);
34+
});
35+
36+
super.drawScreen(mouseX, mouseY, partialTicks);
37+
}
38+
39+
@Override
40+
public boolean doesGuiPauseGame() {
41+
return false;
42+
}
43+
}

src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateResourcePackHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.minecrafttas.tasmod.networking.TASmodBufferBuilder;
2222
import com.minecrafttas.tasmod.registries.TASmodPackets;
2323
import com.minecrafttas.tasmod.savestates.exceptions.SavestateException;
24+
import com.minecrafttas.tasmod.savestates.gui.GuiResourcepackWarn;
2425
import com.minecrafttas.tasmod.util.LoggerMarkers;
2526

2627
import net.fabricmc.api.EnvType;
@@ -89,6 +90,8 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
8990

9091
TASmod.LOGGER.debug(LoggerMarkers.Savestate, "Clearing server resource pack");
9192

93+
mc.displayGuiScreen(new GuiResourcepackWarn());
94+
9295
/**
9396
* Using a countdown latch here, which is counted down in
9497
* savestates.MixinMinecraft.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.minecrafttas.tasmod.util;
2+
3+
public class MessageUtils {
4+
5+
public static void splitNewline(String phrase, GuiInterface method) {
6+
splitNewline(phrase, 10, method);
7+
}
8+
9+
public static void splitNewline(String phrase, int distance, GuiInterface method) {
10+
int y = 0;
11+
String[] lines = phrase.split("\r?\n");
12+
for (String line : lines) {
13+
method.draw(line, y);
14+
y += distance;
15+
}
16+
}
17+
18+
@FunctionalInterface
19+
public interface GuiInterface {
20+
21+
public void draw(String line, int y);
22+
}
23+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2-
"tickratechanger.tasmod.command.show": "Current tickrate: %s",
3-
"tickratechanger.tasmod.command.usage": "/tickrate <ticks per second>"
2+
"tickratechanger.tasmod.command.show":"Current tickrate: %s",
3+
"tickratechanger.tasmod.command.usage":"/tickrate <ticks per second>",
4+
"gui.tasmod.savestate.resourcepack":"You have a resource pack (resources.zip) in your world folder.\nLoadstating will take severely longer!"
45
}

0 commit comments

Comments
 (0)