Skip to content

Commit be876fd

Browse files
committed
Multi Realm Background Shader
1 parent 5a45157 commit be876fd

12 files changed

Lines changed: 790 additions & 75 deletions

src/main/java/net/wurstclient/WurstClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import net.wurstclient.util.SetbackDetector;
5050
import net.wurstclient.util.ServerObserver;
5151
import net.wurstclient.util.HackToggleFeedback;
52+
import net.wurstclient.util.TitleBackgroundModeManager;
5253
import net.wurstclient.util.timer.TimerManager;
5354
import net.wurstclient.util.json.JsonException;
5455
import net.wurstclient.nicewurst.NiceWurstModule;
@@ -156,6 +157,7 @@ public void initialize()
156157
settingsProfileFolder = wurstFolder.resolve("settings");
157158
this.settingsFile = new SettingsFile(settingsFile, hax, cmds, otfs);
158159
this.settingsFile.load();
160+
TitleBackgroundModeManager.advanceForStartup();
159161
hax.tooManyHaxHack.loadBlockedHacksFile();
160162
otfs.hackListOtf.loadHiddenHacksFile();
161163

src/main/java/net/wurstclient/options/WurstOptionsScreen.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import net.wurstclient.util.ChatUtils;
4343
import net.wurstclient.util.ColorUtils;
4444
import net.wurstclient.util.LastServerRememberer;
45+
import net.wurstclient.util.TitleBackgroundModeManager;
4546
import net.wurstclient.util.WurstColors;
4647
import net.wurstclient.clickgui.screens.EditColorScreen;
4748

@@ -215,8 +216,12 @@ private void addCoreSection()
215216
() -> "Shadertoy Background: "
216217
+ onOff(titleScreenShadertoyBackground.isChecked()),
217218
"Render a Shadertoy-style animated background behind the title screen.",
218-
b -> titleScreenShadertoyBackground
219-
.setChecked(!titleScreenShadertoyBackground.isChecked()));
219+
b -> {
220+
boolean wasEnabled = titleScreenShadertoyBackground.isChecked();
221+
titleScreenShadertoyBackground.setChecked(!wasEnabled);
222+
if(!wasEnabled)
223+
TitleBackgroundModeManager.advanceForEnableToggle();
224+
});
220225

221226
addButton(column, () -> "Import Shadertoy",
222227
"Import a Shadertoy by URL or pasted source code as the menu background.",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2014-2026 Wurst-Imperium and contributors.
3+
*
4+
* This source code is subject to the terms of the GNU General Public
5+
* License, version 3. If a copy of the GPL was not distributed with this
6+
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
7+
*/
8+
package net.wurstclient.util;
9+
10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
15+
import net.minecraft.resources.Identifier;
16+
import net.wurstclient.WurstClient;
17+
18+
public enum TitleBackgroundModeManager
19+
{
20+
;
21+
22+
private static final Path MODE_FILE = WurstClient.INSTANCE.getWurstFolder()
23+
.resolve("title-background-mode.txt");
24+
private static Mode currentMode = loadModeFromDisk();
25+
26+
public static void advanceForStartup()
27+
{
28+
currentMode = currentMode.next();
29+
saveModeToDisk();
30+
}
31+
32+
public static void advanceForEnableToggle()
33+
{
34+
currentMode = currentMode.next();
35+
saveModeToDisk();
36+
}
37+
38+
public static Mode getCurrentMode()
39+
{
40+
return currentMode;
41+
}
42+
43+
private static Mode loadModeFromDisk()
44+
{
45+
if(!Files.isRegularFile(MODE_FILE))
46+
return Mode.END;
47+
48+
try
49+
{
50+
String value =
51+
Files.readString(MODE_FILE, StandardCharsets.UTF_8).trim();
52+
return Mode.valueOf(value);
53+
}catch(Exception e)
54+
{
55+
return Mode.END;
56+
}
57+
}
58+
59+
private static void saveModeToDisk()
60+
{
61+
try
62+
{
63+
Files.writeString(MODE_FILE, currentMode.name(),
64+
StandardCharsets.UTF_8);
65+
}catch(IOException e)
66+
{
67+
throw new RuntimeException("Failed to save title background mode.",
68+
e);
69+
}
70+
}
71+
72+
public enum Mode
73+
{
74+
OVERWORLD("wurst:textures/shader_blocks_overworld.png", 0),
75+
NETHER("wurst:textures/shader_blocks_nether.png", 1),
76+
END("wurst:textures/shader_blocks_end.png", 2);
77+
78+
private final Identifier atlasId;
79+
private final int shaderIndex;
80+
81+
private Mode(String atlasId, int shaderIndex)
82+
{
83+
this.atlasId = Identifier.parse(atlasId);
84+
this.shaderIndex = shaderIndex;
85+
}
86+
87+
public Identifier getAtlasId()
88+
{
89+
return atlasId;
90+
}
91+
92+
public int getShaderIndex()
93+
{
94+
return shaderIndex;
95+
}
96+
97+
public Mode next()
98+
{
99+
return values()[(ordinal() + 1) % values().length];
100+
}
101+
}
102+
}

src/main/java/net/wurstclient/util/TitleScreenBackgroundRenderer.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,29 @@
1414
import net.minecraft.client.gui.render.TextureSetup;
1515
import net.minecraft.client.Minecraft;
1616
import net.minecraft.client.renderer.texture.AbstractTexture;
17-
import net.minecraft.resources.Identifier;
1817
import net.wurstclient.TitleScreenShaderPipelines;
18+
import net.wurstclient.util.TitleBackgroundModeManager.Mode;
1919

2020
public enum TitleScreenBackgroundRenderer
2121
{
2222
;
2323

24-
private static final Identifier BLOCK_ATLAS =
25-
Identifier.parse("wurst:textures/shader_blocks.png");
26-
2724
public static void addBackground(GuiGraphicsExtractor context, int width,
2825
int height)
2926
{
3027
Matrix3x2f pose = new Matrix3x2f();
3128
ScreenRectangle bounds = new ScreenRectangle(0, 0, width, height);
29+
Mode mode = TitleBackgroundModeManager.getCurrentMode();
3230
int time = (int)((System.currentTimeMillis() / 50L) & 0xFFFF);
33-
int timeColor = 0xFF0000FF | ((time >> 8) << 16) | ((time & 0xFF) << 8);
34-
AbstractTexture texture =
35-
Minecraft.getInstance().getTextureManager().getTexture(BLOCK_ATLAS);
31+
int packedColor = 0xFF000000 | ((time >> 8) << 16)
32+
| ((time & 0xFF) << 8) | (mode.getShaderIndex() & 0xFF);
33+
AbstractTexture texture = Minecraft.getInstance().getTextureManager()
34+
.getTexture(mode.getAtlasId());
3635
context.guiRenderState.addGuiElement(new CustomQuadRenderState(
3736
TitleScreenShaderPipelines.TITLE_SHADERTOY_BACKGROUND,
3837
TextureSetup.singleTexture(texture.getTextureView(),
3938
texture.getSampler()),
40-
pose, -1, -1, 1, -1, 1, 1, -1, 1, timeColor, timeColor, timeColor,
41-
timeColor, null, bounds));
39+
pose, -1, -1, 1, -1, 1, 1, -1, 1, packedColor, packedColor,
40+
packedColor, packedColor, null, bounds));
4241
}
4342
}

0 commit comments

Comments
 (0)