-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathConfigTexture.java
More file actions
59 lines (50 loc) · 2.62 KB
/
ConfigTexture.java
File metadata and controls
59 lines (50 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package eu.midnightdust.customsplashscreen.texture;
import eu.midnightdust.customsplashscreen.CustomSplashScreenClient;
import net.minecraft.client.resource.metadata.TextureResourceMetadata;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.client.texture.TextureContents;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.Random;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Objects;
public class ConfigTexture extends ResourceTexture {
public static int randomBackgroundId;
public static int prevBackgroundLength;
// Load textures from the config directory //
public boolean shouldBlur = false;
public ConfigTexture(Identifier location) {
super(location);
}
@Override
public TextureContents loadContents(ResourceManager resourceManager) {
try {
Identifier location = getId();
InputStream input = new FileInputStream(CustomSplashScreenClient.CONFIG_PATH+"/"+location.getPath());
if (location.getPath().equals("background.png") && CustomSplashScreenClient.CONFIG_PATH.toPath().resolve("backgrounds").toFile().isDirectory()) {
if (CustomSplashScreenClient.CONFIG_PATH.toPath().resolve("backgrounds").toFile().listFiles() != null) {
File[] backgrounds = Arrays.stream(Objects.requireNonNull(CustomSplashScreenClient.CONFIG_PATH.toPath().resolve("backgrounds").toFile().listFiles())).filter(file -> file.toString().endsWith(".png") || file.toString().endsWith(".jpg") || file.toString().endsWith(".jpeg")).toList().toArray(new File[0]);
if (backgrounds.length > 0) {
if (ConfigTexture.randomBackgroundId == -1 || ConfigTexture.prevBackgroundLength != backgrounds.length) ConfigTexture.randomBackgroundId = Random.create().nextInt(backgrounds.length);
input = new FileInputStream(backgrounds[ConfigTexture.randomBackgroundId]);
ConfigTexture.prevBackgroundLength = backgrounds.length;
}
}
}
TextureContents texture;
try {
texture = new TextureContents(NativeImage.read(input), new TextureResourceMetadata(shouldBlur, true));
} finally {
input.close();
}
return texture;
} catch (IOException var18) {
return TextureContents.createMissing();
}
}
}