|
19 | 19 | import net.minecraft.client.Minecraft; |
20 | 20 | import net.minecraft.resources.ResourceLocation; |
21 | 21 | import net.minecraft.server.packs.PackType; |
| 22 | +import net.minecraft.world.level.Level; |
22 | 23 | import org.slf4j.Logger; |
23 | 24 | import org.slf4j.LoggerFactory; |
24 | 25 |
|
@@ -91,76 +92,71 @@ public void convert(SkyboxResourceHelper skyboxResourceHelper) { |
91 | 92 | private void parseSkyboxes(SkyboxResourceHelper skyboxResourceHelper, String skyParent, Pattern skyPattern) { |
92 | 93 | final JsonArray overworldLayers = new JsonArray(); |
93 | 94 | final JsonArray endLayers = new JsonArray(); |
94 | | - skyboxResourceHelper.searchIn(skyParent) |
95 | | - .filter(id -> id.getPath().endsWith(".properties")) |
96 | | - .sorted(Comparator.comparing(ResourceLocation::getPath, (id1, id2) -> { |
97 | | - final Matcher matcherId1 = skyPattern.matcher(id1); |
98 | | - final Matcher matcherId2 = skyPattern.matcher(id2); |
99 | | - if (matcherId1.find() && matcherId2.find()) { |
100 | | - final int id1No = CommonUtils.parseInt(matcherId1.group("name").replace("sky", ""), -1); |
101 | | - final int id2No = CommonUtils.parseInt(matcherId2.group("name").replace("sky", ""), -1); |
102 | | - if (id1No >= 0 && id2No >= 0) { |
103 | | - return id1No - id2No; |
104 | | - } |
| 95 | + skyboxResourceHelper.searchIn(skyParent).filter(id -> id.getPath().endsWith(".properties")).sorted(Comparator.comparing(ResourceLocation::getPath, (id1, id2) -> { |
| 96 | + final Matcher matcherId1 = skyPattern.matcher(id1); |
| 97 | + final Matcher matcherId2 = skyPattern.matcher(id2); |
| 98 | + if (matcherId1.find() && matcherId2.find()) { |
| 99 | + final int a = CommonUtils.safeParseInteger(matcherId1.group("name").replace("sky", ""), -1); |
| 100 | + final int b = CommonUtils.safeParseInteger(matcherId2.group("name").replace("sky", ""), -1); |
| 101 | + if (a >= 0 && b >= 0) { |
| 102 | + return a - b; |
| 103 | + } |
| 104 | + } |
| 105 | + return 0; |
| 106 | + })).forEach(id -> { |
| 107 | + Matcher matcher = skyPattern.matcher(id.getPath()); |
| 108 | + if (matcher.find()) { |
| 109 | + final String world = matcher.group("world"); |
| 110 | + final String name = matcher.group("name"); |
| 111 | + if (world == null || name == null) { |
| 112 | + return; |
| 113 | + } |
| 114 | + |
| 115 | + if (name.equals("moon_phases") || name.equals("sun")) { |
| 116 | + // TODO/NOTE: Support moon/sun |
| 117 | + LOGGER.warn("Skipping {}, moon_phases/sun aren't currently supported!", id); |
| 118 | + return; |
| 119 | + } |
| 120 | + |
| 121 | + final InputStream inputStream = skyboxResourceHelper.getInputStream(id); |
| 122 | + if (inputStream == null) { |
| 123 | + LOGGER.error("Error trying to read namespaced identifier: {}", id); |
| 124 | + return; |
| 125 | + } |
| 126 | + |
| 127 | + final Properties properties = new Properties(); |
| 128 | + try { |
| 129 | + properties.load(inputStream); |
| 130 | + } catch (IOException e) { |
| 131 | + LOGGER.error("Error trying to read properties from: {}", id); |
| 132 | + return; |
| 133 | + } finally { |
| 134 | + try { |
| 135 | + inputStream.close(); |
| 136 | + } catch (IOException e) { |
| 137 | + LOGGER.error("Error trying to close input stream at namespaced identifier: {}", id); |
105 | 138 | } |
106 | | - return 0; |
107 | | - })) |
108 | | - .forEach(id -> { |
109 | | - Matcher matcher = skyPattern.matcher(id.getPath()); |
110 | | - if (matcher.find()) { |
111 | | - final String world = matcher.group("world"); |
112 | | - final String name = matcher.group("name"); |
113 | | - if (world == null || name == null) { |
114 | | - return; |
115 | | - } |
116 | | - |
117 | | - if (name.equals("moon_phases") || name.equals("sun")) { |
118 | | - // TODO/NOTE: Support moon/sun |
119 | | - LOGGER.info("Skipping {}, moon_phases/sun aren't supported!", id); |
120 | | - return; |
121 | | - } |
122 | | - |
123 | | - final InputStream inputStream = skyboxResourceHelper.getInputStream(id); |
124 | | - if (inputStream == null) { |
125 | | - LOGGER.error("Error trying to read namespaced identifier: {}", id); |
126 | | - return; |
127 | | - } |
128 | | - |
129 | | - final Properties properties = new Properties(); |
130 | | - try { |
131 | | - properties.load(inputStream); |
132 | | - } catch (IOException e) { |
133 | | - LOGGER.error("Error trying to read properties from: {}", id); |
134 | | - return; |
135 | | - } finally { |
136 | | - try { |
137 | | - inputStream.close(); |
138 | | - } catch (IOException e) { |
139 | | - LOGGER.error("Error trying to close input stream at namespaced identifier: {}", id); |
140 | | - } |
141 | | - } |
142 | | - |
143 | | - final JsonObject json = CommonUtils.convertOptiFineSkyProperties(skyboxResourceHelper, properties, id); |
144 | | - if (json != null) { |
145 | | - switch (world) { |
146 | | - case "world0" -> overworldLayers.add(json); |
147 | | - case "world1" -> endLayers.add(json); |
148 | | - } |
149 | | - } |
150 | | - } |
151 | | - }); |
| 139 | + } |
| 140 | + |
| 141 | + final JsonObject json = CommonUtils.convertOptiFineSkyProperties(skyboxResourceHelper, properties, id); |
| 142 | + switch (world) { |
| 143 | + case "world0" -> overworldLayers.add(json); |
| 144 | + case "world1" -> endLayers.add(json); |
| 145 | + } |
| 146 | + } |
| 147 | + }); |
152 | 148 |
|
153 | 149 | if (!overworldLayers.isEmpty()) { |
154 | | - final JsonObject overworldJson = new JsonObject(); |
| 150 | + JsonObject overworldJson = new JsonObject(); |
155 | 151 | overworldJson.add("layers", overworldLayers); |
156 | | - overworldJson.addProperty("world", "minecraft:overworld"); |
| 152 | + overworldJson.addProperty("world", Level.OVERWORLD.location().toString()); |
157 | 153 | SkyboxManager.INSTANCE.addSkybox(OptiFineSkybox.CODEC.decode(JsonOps.INSTANCE, overworldJson).getOrThrow().getFirst()); |
158 | 154 | } |
159 | 155 |
|
160 | 156 | if (!endLayers.isEmpty()) { |
161 | | - final JsonObject endJson = new JsonObject(); |
| 157 | + JsonObject endJson = new JsonObject(); |
162 | 158 | endJson.add("layers", endLayers); |
163 | | - endJson.addProperty("world", "minecraft:the_end"); |
| 159 | + endJson.addProperty("world", Level.END.location().toString()); |
164 | 160 | SkyboxManager.INSTANCE.addSkybox(OptiFineSkybox.CODEC.decode(JsonOps.INSTANCE, endJson).getOrThrow().getFirst()); |
165 | 161 | } |
166 | 162 | } |
|
0 commit comments