Skip to content

Commit decfc2d

Browse files
committed
v1.2 - Fix Rotations Finally
1 parent 206e300 commit decfc2d

File tree

7 files changed

+205
-174
lines changed

7 files changed

+205
-174
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ base {
1313
static def getCheckedOutGitCommitHash() {
1414
String commit = 'git rev-parse --verify --short HEAD'.execute().text.trim()
1515
if (commit.size() > 0) {
16-
return "-" + commit;
16+
return "-" + commit
1717
} else {
18-
return "";
18+
return ""
1919
}
2020
}
2121

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ fabric_version=0.114.1+1.21.3
1313
modmenu_version=12.0.0
1414

1515
# Mod Properties
16-
mod_version=1.1
16+
mod_version=1.2
1717
maven_group=btw.lowercase
1818
archives_base_name=optiboxes

src/main/java/btw/lowercase/optiboxes/OptiBoxesClient.java

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.minecraft.client.Minecraft;
2020
import net.minecraft.resources.ResourceLocation;
2121
import net.minecraft.server.packs.PackType;
22+
import net.minecraft.world.level.Level;
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425

@@ -91,76 +92,71 @@ public void convert(SkyboxResourceHelper skyboxResourceHelper) {
9192
private void parseSkyboxes(SkyboxResourceHelper skyboxResourceHelper, String skyParent, Pattern skyPattern) {
9293
final JsonArray overworldLayers = new JsonArray();
9394
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);
105138
}
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+
});
152148

153149
if (!overworldLayers.isEmpty()) {
154-
final JsonObject overworldJson = new JsonObject();
150+
JsonObject overworldJson = new JsonObject();
155151
overworldJson.add("layers", overworldLayers);
156-
overworldJson.addProperty("world", "minecraft:overworld");
152+
overworldJson.addProperty("world", Level.OVERWORLD.location().toString());
157153
SkyboxManager.INSTANCE.addSkybox(OptiFineSkybox.CODEC.decode(JsonOps.INSTANCE, overworldJson).getOrThrow().getFirst());
158154
}
159155

160156
if (!endLayers.isEmpty()) {
161-
final JsonObject endJson = new JsonObject();
157+
JsonObject endJson = new JsonObject();
162158
endJson.add("layers", endLayers);
163-
endJson.addProperty("world", "minecraft:the_end");
159+
endJson.addProperty("world", Level.END.location().toString());
164160
SkyboxManager.INSTANCE.addSkybox(OptiFineSkybox.CODEC.decode(JsonOps.INSTANCE, endJson).getOrThrow().getFirst());
165161
}
166162
}

src/main/java/btw/lowercase/optiboxes/mixins/MixinLevelRenderer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.spongepowered.asm.mixin.injection.Inject;
2727
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2828

29-
import java.util.List;
3029
import java.util.Objects;
3130

3231
@Mixin(value = LevelRenderer.class, priority = 900)
@@ -46,7 +45,6 @@ public abstract class MixinLevelRenderer {
4645
@WrapOperation(method = "method_62215", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/SkyRenderer;renderEndSky(Lcom/mojang/blaze3d/vertex/PoseStack;)V"))
4746
private void optiboxes$renderEndSkybox(SkyRenderer instance, PoseStack poseStack, Operation<Void> original) {
4847
original.call(instance, poseStack);
49-
List<OptiFineSkybox> activeSkyboxes = SkyboxManager.INSTANCE.getActiveSkyboxes();
5048
boolean isEnabled = SkyboxManager.INSTANCE.isEnabled(this.level);
5149
if (isEnabled) {
5250
RenderSystem.enableBlend();
@@ -57,7 +55,8 @@ public abstract class MixinLevelRenderer {
5755
ClientLevel clientLevel = Objects.requireNonNull(this.level);
5856
Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
5957
modelViewStack.pushMatrix();
60-
for (OptiFineSkybox optiFineSkybox : activeSkyboxes) {
58+
modelViewStack.rotate(Axis.YP.rotationDegrees(-90.0F));
59+
for (OptiFineSkybox optiFineSkybox : SkyboxManager.INSTANCE.getActiveSkyboxes()) {
6160
OptiFineSkyRenderer.INSTANCE.renderSkybox(optiFineSkybox, modelViewStack, clientLevel, 0.0F);
6261
}
6362
modelViewStack.popMatrix();
@@ -79,11 +78,11 @@ public abstract class MixinLevelRenderer {
7978
private void optiboxes$renderSkyboxes(SkyRenderer instance, PoseStack poseStack, Tesselator tesselator, float timeOfDay, int moonPhases, float rainLevel, float starBrightness, FogParameters fogParameters, Operation<Void> original) {
8079
boolean isEnabled = SkyboxManager.INSTANCE.isEnabled(this.level);
8180
if (isEnabled) {
82-
List<OptiFineSkybox> activeSkyboxes = SkyboxManager.INSTANCE.getActiveSkyboxes();
8381
ClientLevel clientLevel = Objects.requireNonNull(this.level);
8482
Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
8583
modelViewStack.pushMatrix();
86-
for (OptiFineSkybox optiFineSkybox : activeSkyboxes) {
84+
modelViewStack.rotate(Axis.YP.rotationDegrees(-90.0F));
85+
for (OptiFineSkybox optiFineSkybox : SkyboxManager.INSTANCE.getActiveSkyboxes()) {
8786
OptiFineSkyRenderer.INSTANCE.renderSkybox(optiFineSkybox, modelViewStack, clientLevel, this.optiboxes$tickDelta);
8887
}
8988
modelViewStack.popMatrix();

src/main/java/btw/lowercase/optiboxes/skybox/OptiFineSkyRenderer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ private void buildSky() {
4242

4343
this.skyBuffer = new VertexBuffer(BufferUsage.STATIC_WRITE);
4444
this.skyBuffer.bind();
45-
this.skyBuffer.upload(builder.build());
45+
try (MeshData meshData = builder.buildOrThrow()) {
46+
this.skyBuffer.upload(meshData);
47+
}
4648
VertexBuffer.unbind();
4749
}
4850

@@ -71,8 +73,7 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
7173
modelViewStack.pushMatrix();
7274
if (optiFineSkyLayer.rotate()) {
7375
// NOTE: Using `mulPose` directly gives a different result.
74-
final float angle = this.getAngle(level, skyAngle, optiFineSkyLayer.speed());
75-
modelViewStack.rotate(new Quaternionf(new AxisAngle4f((float) Math.toRadians(angle), optiFineSkyLayer.axis())));
76+
modelViewStack.rotate(new Quaternionf(new AxisAngle4f(this.getAngle(level, skyAngle, optiFineSkyLayer.speed()), optiFineSkyLayer.axis())));
7677
}
7778

7879
RenderSystem.setShaderTexture(0, optiFineSkyLayer.source());
@@ -104,6 +105,6 @@ private float getAngle(Level level, float skyAngle, float speed) {
104105
angleDayStart = (float) (currentAngle % 1.0D);
105106
}
106107

107-
return 360.0F * (angleDayStart + skyAngle * speed);
108+
return (float) Math.toRadians(360.0F * (angleDayStart + skyAngle * speed));
108109
}
109110
}

0 commit comments

Comments
 (0)