3333import net .minecraft .server .packs .PackType ;
3434import net .minecraft .server .packs .resources .IoSupplier ;
3535import net .minecraft .server .packs .resources .PreparableReloadListener ;
36- import net .minecraft .server .packs .resources .Resource ;
3736import net .minecraft .server .packs .resources .ResourceManager ;
3837import org .jetbrains .annotations .NotNull ;
3938import org .slf4j .Logger ;
4645import java .util .concurrent .Executor ;
4746import java .util .regex .Matcher ;
4847import java .util .regex .Pattern ;
49- import java .util .stream .Stream ;
5048
5149public class SkyboxResourceHelper implements
5250 //? >=1.21.10 {
@@ -62,8 +60,6 @@ public class SkyboxResourceHelper implements
6260 private static final Pattern MCPATCHER_SKY_PATTERN = Pattern .compile (MCPATCHER_SKY_PARENT + "/" + SKY_PATTERN_ENDING );
6361 private static final Logger LOGGER = LoggerFactory .getLogger (SkyboxResourceHelper .class );
6462
65- private ResourceManager resourceManager ;
66-
6763 @ Override
6864 public @ NotNull CompletableFuture <Void > reload (
6965 //? >=1.21.9
@@ -77,7 +73,7 @@ public class SkyboxResourceHelper implements
7773 PreparationBarrier preparationBarrier ,
7874 @ NotNull Executor gameExecutor
7975 ) {
80- this . resourceManager =
76+ final ResourceManager theResourceManager =
8177 //? >=1.21.9 {
8278 sharedState .resourceManager ();
8379 //?} else {
@@ -87,15 +83,14 @@ public class SkyboxResourceHelper implements
8783 SkyboxManager .INSTANCE .clearSkyboxes ();
8884 if (Skyboxify .getConfig ().enabled .isEnabled ()) {
8985 LOGGER .info ("Looking for OptiFine/MCPatcher Skies..." );
90- this .resourceManager .listPacks ().forEach (pack -> {
91- // TODO: Find a better cleaner way to do this bruh
92- final List <ResourceLocation > resources = new ArrayList <>();
93- final PackResources .ResourceOutput resourceOutput = (resourceLocation , inputStreamIoSupplier ) -> resources .add (resourceLocation );
94- pack .listResources (PackType .CLIENT_RESOURCES , "minecraft" , MCPATCHER_SKY_PARENT , resourceOutput );
95- pack .listResources (PackType .CLIENT_RESOURCES , "minecraft" , OPTIFINE_SKY_PARENT , resourceOutput );
96- if (!resources .isEmpty ()) {
97- this .searchAndParseSkyboxes (pack );
98- }
86+ theResourceManager .listPacks ().forEach (pack -> {
87+ final List <ResourceLocation > optifineSkies = new ArrayList <>();
88+ pack .listResources (PackType .CLIENT_RESOURCES , ResourceLocation .DEFAULT_NAMESPACE , OPTIFINE_SKY_PARENT , (resourceLocation , inputStreamIoSupplier ) -> optifineSkies .add (resourceLocation ));
89+
90+ final List <ResourceLocation > mcpatcherSkies = new ArrayList <>();
91+ pack .listResources (PackType .CLIENT_RESOURCES , ResourceLocation .DEFAULT_NAMESPACE , MCPATCHER_SKY_PARENT , (resourceLocation , inputStreamIoSupplier ) -> mcpatcherSkies .add (resourceLocation ));
92+
93+ this .parseSkyboxes (pack , optifineSkies , mcpatcherSkies );
9994 });
10095 }
10196 }).thenCompose (preparationBarrier ::wait );
@@ -108,30 +103,25 @@ public ResourceLocation getFabricId() {
108103 }
109104 */ //?}
110105
111- private Stream <ResourceLocation > searchIn (final PackResources packResources , final String parent ) {
112- // TODO: Find a better cleaner way to do this bruh
113- return this .resourceManager
114- .listResourceStacks (parent , path -> true )
115- .entrySet ()
116- .stream ()
117- .filter (entry -> entry .getValue ().stream ().anyMatch (resource -> resource .sourcePackId ().equals (packResources .packId ())))
118- .map (Map .Entry ::getKey );
119- }
106+ private void parseSkyboxes (final PackResources packResources , final List <ResourceLocation > optifineSkies , final List <ResourceLocation > mcpatcherSkies ) {
107+ if (optifineSkies .isEmpty () && mcpatcherSkies .isEmpty ()) {
108+ return ;
109+ }
120110
121- private void searchAndParseSkyboxes (final PackResources packResources ) {
122- // TODO: Find a better cleaner way to do this bruh
123111 Pattern skyPattern = OPTIFINE_SKY_PATTERN ;
124- List <ResourceLocation > skies = this . searchIn ( packResources , OPTIFINE_SKY_PARENT ).filter (SkyboxResourceHelper ::isProperties ).sorted (compareLocations (skyPattern )).toList ();
125- if (skies .isEmpty ()) {
112+ List <ResourceLocation > skies = optifineSkies . stream ( ).filter (SkyboxResourceHelper ::isProperties ).sorted (compareLocations (skyPattern )).toList ();
113+ if (optifineSkies .isEmpty ()) {
126114 LOGGER .info ("Couldn't find any skies under \" optifine\" , searching for skies under \" mcpatcher\" instead..." );
127115 skyPattern = MCPATCHER_SKY_PATTERN ;
128- skies = this . searchIn ( packResources , MCPATCHER_SKY_PARENT ).filter (SkyboxResourceHelper ::isProperties ).sorted (compareLocations (skyPattern )).toList ();
116+ skies = mcpatcherSkies . stream ( ).filter (SkyboxResourceHelper ::isProperties ).sorted (compareLocations (skyPattern )).toList ();
129117 }
130118
131- this .parseSkyboxes (packResources , skies , skyPattern );
119+ if (!skies .isEmpty ()) {
120+ this .parseSkyboxesInPack (packResources , skies , skyPattern );
121+ }
132122 }
133123
134- private void parseSkyboxes (final PackResources packResources , final List <ResourceLocation > skies , final Pattern skyPattern ) {
124+ private void parseSkyboxesInPack (final PackResources packResources , final List <ResourceLocation > skies , final Pattern skyPattern ) {
135125 final Map <String , JsonArray > layers = new HashMap <>();
136126 skies .forEach (id -> {
137127 final Matcher matcher = skyPattern .matcher (id .getPath ());
0 commit comments