Skip to content

Commit 3fdf070

Browse files
committed
Rework how mcpatcher is handled
1 parent bb6b6f2 commit 3fdf070

File tree

9 files changed

+163
-150
lines changed

9 files changed

+163
-150
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.parallel=true
55
# Mod properties
66
mod.name=Skyboxify
77
mod.id=skyboxify
8-
mod.version=2.0
8+
mod.version=2.1
99
mod.group=btw.lowercase
1010
mod.description=A skybox mod that allows you to use OptiFine skies in Fabric 1.21+
1111
mod.source=https://github.com/Legacy-Visuals-Project/Skyboxify

src/main/java/btw/lowercase/skyboxify/Skyboxify.java

Lines changed: 3 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
import btw.lowercase.skyboxify.config.SkyboxifyConfig;
2727
import btw.lowercase.skyboxify.events.LevelTickEvent;
2828
import btw.lowercase.skyboxify.events.SkyRenderEvent;
29-
import btw.lowercase.skyboxify.skybox.*;
30-
import btw.lowercase.skyboxify.utils.ParserCodecs;
31-
import com.google.gson.JsonArray;
32-
import com.google.gson.JsonObject;
29+
import btw.lowercase.skyboxify.skybox.Skybox;
30+
import btw.lowercase.skyboxify.skybox.SkyboxManager;
31+
import btw.lowercase.skyboxify.skybox.SkyboxSkyRenderer;
3332
import com.mojang.blaze3d.systems.RenderSystem;
3433
import com.mojang.math.Axis;
35-
import com.mojang.serialization.JsonOps;
3634
import lombok.Getter;
3735
import lombok.experimental.UtilityClass;
3836
import net.minecraft.client.multiplayer.ClientLevel;
@@ -43,15 +41,7 @@
4341
import org.slf4j.LoggerFactory;
4442
import org.visuals.legacy.lightconfig.lib.v1.events.EventManager;
4543

46-
import java.io.IOException;
47-
import java.io.InputStream;
4844
import java.nio.file.Path;
49-
import java.util.Comparator;
50-
import java.util.HashMap;
51-
import java.util.Map;
52-
import java.util.Properties;
53-
import java.util.regex.Matcher;
54-
import java.util.regex.Pattern;
5545

5646
@UtilityClass
5747
public class Skyboxify {
@@ -60,11 +50,6 @@ public class Skyboxify {
6050
private final Logger logger = LoggerFactory.getLogger(Skyboxify.class);
6151
@Getter
6252
private final EventManager eventManager = new EventManager();
63-
private final String OPTIFINE_SKY_PARENT = "optifine/sky";
64-
private final String SKY_PATTERN_ENDING = "(?<world>[\\w-]+)/(?<name>\\w+).properties$";
65-
private final Pattern OPTIFINE_SKY_PATTERN = Pattern.compile(OPTIFINE_SKY_PARENT + "/" + SKY_PATTERN_ENDING);
66-
private final String MCPATCHER_SKY_PARENT = "mcpatcher/sky";
67-
private final Pattern MCPATCHER_SKY_PATTERN = Pattern.compile(MCPATCHER_SKY_PARENT + "/" + SKY_PATTERN_ENDING);
6853
@Getter
6954
private SkyboxifyConfig config;
7055

@@ -117,90 +102,4 @@ private void renderSkyboxes(ClientLevel clientLevel, float tickDelta) {
117102
}
118103
}
119104
}
120-
121-
public void convert(SkyboxResourceHelper skyboxResourceHelper) {
122-
if (config.processOptiFine.isEnabled()) {
123-
parseSkyboxes(skyboxResourceHelper, OPTIFINE_SKY_PARENT, OPTIFINE_SKY_PATTERN);
124-
}
125-
126-
if (config.processMCPatcher.isEnabled()) {
127-
parseSkyboxes(skyboxResourceHelper, MCPATCHER_SKY_PARENT, MCPATCHER_SKY_PATTERN);
128-
}
129-
}
130-
131-
private void parseSkyboxes(SkyboxResourceHelper skyboxResourceHelper, String skyParent, Pattern skyPattern) {
132-
final Map<String, JsonArray> layers = new HashMap<>();
133-
layers.put("world0", new JsonArray()); // Overworld
134-
layers.put("world-1", new JsonArray()); // Nether
135-
layers.put("world1", new JsonArray()); // The End
136-
skyboxResourceHelper.searchIn(skyParent).filter(id -> id.getPath().endsWith(".properties")).sorted(Comparator.comparing(ResourceLocation::getPath, (id1, id2) -> {
137-
final Matcher matcherId1 = skyPattern.matcher(id1);
138-
final Matcher matcherId2 = skyPattern.matcher(id2);
139-
if (matcherId1.find() && matcherId2.find()) {
140-
final int a = ParserCodecs.safeParseInteger(matcherId1.group("name").replace("sky", ""), -1);
141-
final int b = ParserCodecs.safeParseInteger(matcherId2.group("name").replace("sky", ""), -1);
142-
if (a >= 0 && b >= 0) {
143-
return a - b;
144-
}
145-
}
146-
147-
return 0;
148-
})).forEach(id -> {
149-
final Matcher matcher = skyPattern.matcher(id.getPath());
150-
if (matcher.find()) {
151-
final String world = matcher.group("world");
152-
final String name = matcher.group("name");
153-
if (world == null || name == null) {
154-
return;
155-
}
156-
157-
if (name.equals("moon_phases") || name.equals("sun")) {
158-
// TODO/NOTE: Support moon/sun
159-
logger.warn("Skipping {}, moon_phases/sun aren't currently supported!", id);
160-
return;
161-
}
162-
163-
final InputStream inputStream = skyboxResourceHelper.getInputStream(id);
164-
if (inputStream == null) {
165-
logger.error("Error trying to read namespaced identifier: {}", id);
166-
return;
167-
}
168-
169-
final Properties properties = new Properties();
170-
try {
171-
properties.load(inputStream);
172-
} catch (IOException e) {
173-
logger.error("Error trying to read properties from: {}", id);
174-
return;
175-
} finally {
176-
try {
177-
inputStream.close();
178-
} catch (IOException e) {
179-
logger.error("Error trying to close input stream at namespaced identifier: {}", id);
180-
}
181-
}
182-
183-
final JsonObject json = SkyboxParser.parseSkyProperties(properties, id);
184-
// NOTE: Don't add broken skies (returns null if broken)
185-
if (json != null && layers.containsKey(world)) {
186-
layers.get(world).add(json);
187-
}
188-
}
189-
});
190-
191-
for (Map.Entry<String, JsonArray> entry : layers.entrySet()) {
192-
final JsonArray skyLayers = entry.getValue();
193-
if (!skyLayers.isEmpty()) {
194-
final JsonObject skyboxJson = new JsonObject();
195-
skyboxJson.add("layers", skyLayers);
196-
skyboxJson.addProperty("world", switch (entry.getKey()) {
197-
case "world0" -> "overworld";
198-
case "world-1" -> "nether";
199-
case "world1" -> "end";
200-
default -> entry.getKey();
201-
});
202-
SkyboxManager.INSTANCE.addSkybox(Skybox.CODEC.decode(JsonOps.INSTANCE, skyboxJson).getOrThrow().getFirst());
203-
}
204-
}
205-
}
206105
}

src/main/java/btw/lowercase/skyboxify/config/SkyboxifyConfig.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434

3535
public class SkyboxifyConfig extends Config {
3636
public final BooleanConfigField enabled = this.booleanFieldOf("enabled", true);
37-
public final BooleanConfigField processOptiFine = this.booleanFieldOf("processOptiFine", true);
38-
public final BooleanConfigField processMCPatcher = this.booleanFieldOf("processMCPatcher", false);
3937
public final BooleanConfigField renderSunMoon = this.booleanFieldOf("renderSunMoon", true);
4038
public final BooleanConfigField renderStars = this.booleanFieldOf("renderStars", true);
4139
public final BooleanConfigField showOverworldForUnknownDimension = this.booleanFieldOf("showOverworldForUnknownDimension", true);
@@ -44,8 +42,6 @@ public class SkyboxifyConfig extends Config {
4442
public SkyboxifyConfig(final Path path) {
4543
super(Skyboxify.MOD_ID, path);
4644
final Minecraft minecraft = Minecraft.getInstance();
47-
this.processOptiFine.onValueChanged((oldVal, newVal) -> minecraft.reloadResourcePacks());
48-
this.processMCPatcher.onValueChanged((oldVal, newVal) -> minecraft.reloadResourcePacks());
4945
this.ignoreBrokenSkies.onValueChanged((oldVal, newVal) -> minecraft.reloadResourcePacks());
5046
}
5147

src/main/java/btw/lowercase/skyboxify/config/SkyboxifyConfigScreen.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ protected void init() {
5555
// Didn't iterate fields here because I wanted custom order
5656
rowHelper.addChild(skyboxifyConfig.enabled.createWidget());
5757
rowHelper.addChild(skyboxifyConfig.showOverworldForUnknownDimension.createWidget());
58-
rowHelper.addChild(skyboxifyConfig.processOptiFine.createWidget());
59-
rowHelper.addChild(skyboxifyConfig.processMCPatcher.createWidget());
6058
rowHelper.addChild(skyboxifyConfig.renderSunMoon.createWidget());
6159
rowHelper.addChild(skyboxifyConfig.renderStars.createWidget());
6260
rowHelper.addChild(skyboxifyConfig.ignoreBrokenSkies.createWidget());

src/main/java/btw/lowercase/skyboxify/screen/SkyLayerListScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public class SkyLayerListScreen extends DebugScreen {
4242
public SkyLayerListScreen(final Screen parent, final Skybox skybox) {
4343
super(Component.literal(
4444
//? >=1.21.11 {
45-
/*skybox.getWorldResourceKey().identifier().toString()
45+
/*skybox.getWorldKey().identifier().toString()
4646
*///?} else {
47-
skybox.getWorldResourceKey().location().toString()
47+
skybox.getWorldKey().location().toString()
4848
//?}
4949
), parent);
5050
this.skybox = skybox;

src/main/java/btw/lowercase/skyboxify/screen/SkyboxListScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected void init() {
5555

5656
final List<Gidget> gidgets = new ArrayList<>();
5757
for (final Skybox skybox : this.skyboxes) {
58-
final Component name = Component.literal(skybox.getWorldResourceKey().location().toString())
58+
final Component name = Component.literal(skybox.getWorldKey().location().toString())
5959
.withColor(skybox.isActive() ? ARGB.color(155, 0x00FF00) : ARGB.color(155, 0xFF0000));
6060
gidgets.add(SimpleButton.builder(name,button -> this.minecraft.setScreen(new SkyLayerListScreen(this, skybox))).build());
6161
}

src/main/java/btw/lowercase/skyboxify/skybox/Skybox.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,36 @@
3939

4040
public class Skybox {
4141
public static final Codec<Skybox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
42-
SkyLayer.CODEC.listOf().optionalFieldOf("layers", ImmutableList.of()).forGetter(Skybox::getLayers),
43-
Level.RESOURCE_KEY_CODEC.fieldOf("world").forGetter(Skybox::getWorldResourceKey)
42+
Level.RESOURCE_KEY_CODEC.fieldOf("world").forGetter(Skybox::getWorldKey),
43+
SkyLayer.CODEC.listOf().fieldOf("layers").forGetter(Skybox::getLayers)
4444
).apply(instance, Skybox::new));
4545

4646
@Getter
4747
private final List<SkyLayer> layers;
4848
@Getter
49-
private final ResourceKey<@NotNull Level> worldResourceKey;
49+
private final ResourceKey<@NotNull Level> worldKey;
5050
private final Map<SkyLayer, Float> alphaMap = new HashMap<>();
5151
@Getter
5252
private boolean active = true;
5353

54-
public Skybox(List<SkyLayer> layers, ResourceKey<@NotNull Level> worldResourceKey) {
54+
public Skybox(final ResourceKey<@NotNull Level> worldKey, final List<SkyLayer> layers) {
55+
this.worldKey = worldKey;
5556
this.layers = layers;
56-
this.worldResourceKey = worldResourceKey;
5757
}
5858

59-
public void tick(ClientLevel level) {
59+
public void tick(final ClientLevel level) {
6060
this.active = true;
6161

62-
final boolean allowOtherDimensions = Skyboxify.getConfig().showOverworldForUnknownDimension.isEnabled() && this.worldResourceKey.equals(Level.OVERWORLD) && !level.dimension().equals(Level.NETHER) && !level.dimension().equals(Level.END);
63-
if (level.dimension().equals(this.worldResourceKey) || allowOtherDimensions) {
62+
final boolean allowOtherDimensions = Skyboxify.getConfig().showOverworldForUnknownDimension.isEnabled() && this.worldKey.equals(Level.OVERWORLD) && !level.dimension().equals(Level.NETHER) && !level.dimension().equals(Level.END);
63+
if (level.dimension().equals(this.worldKey) || allowOtherDimensions) {
6464
this.layers.forEach(layer -> alphaMap.put(layer, layer.getPositionBrightness(level, this.getConditionAlphaFor(layer))));
6565
} else {
6666
this.layers.forEach(layer -> alphaMap.put(layer, -1.0F));
6767
this.active = false;
6868
}
6969
}
7070

71-
public float getConditionAlphaFor(SkyLayer skyLayer) {
71+
public float getConditionAlphaFor(final SkyLayer skyLayer) {
7272
return this.alphaMap.getOrDefault(skyLayer, -1.0F);
7373
}
7474
}

src/main/java/btw/lowercase/skyboxify/skybox/SkyboxManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final class SkyboxManager {
4646
private SkyboxManager() {
4747
}
4848

49-
public void addSkybox(Skybox skybox) {
49+
public void addSkybox(final Skybox skybox) {
5050
Preconditions.checkNotNull(skybox, "Skybox was null");
5151
this.loadedSkyboxes.add(skybox);
5252
}
@@ -57,7 +57,7 @@ public void clearSkyboxes() {
5757
this.activeSkyboxes.clear();
5858
}
5959

60-
public void tick(ClientLevel level) {
60+
public void tick(final ClientLevel level) {
6161
if (!Skyboxify.getConfig().enabled.isEnabled()) {
6262
return;
6363
}
@@ -74,15 +74,15 @@ public void tick(ClientLevel level) {
7474
}
7575
}
7676

77-
public boolean isEnabled(Level level) {
77+
public boolean isEnabled(final Level level) {
7878
return Skyboxify.getConfig().enabled.isEnabled() && !activeSkyboxes.isEmpty() && level != null;
7979
}
8080

81-
public List<Skybox> getSkiesFor(ResourceKey<@NotNull Level> resourceKey) {
82-
return getActiveSkyboxes().stream().filter(skybox -> resourceKey.equals(skybox.getWorldResourceKey())).toList();
81+
public List<Skybox> getSkiesFor(final ResourceKey<@NotNull Level> resourceKey) {
82+
return getActiveSkyboxes().stream().filter(skybox -> resourceKey.equals(skybox.getWorldKey())).toList();
8383
}
8484

85-
public boolean containsEnabled(ResourceKey<@NotNull Level> resourceKey) {
85+
public boolean containsEnabled(final ResourceKey<@NotNull Level> resourceKey) {
8686
return !getSkiesFor(resourceKey).isEmpty();
8787
}
8888
}

0 commit comments

Comments
 (0)