Skip to content

Commit 6ec1dc1

Browse files
committed
Begin reworking stuff
1 parent 348c3a9 commit 6ec1dc1

File tree

8 files changed

+171
-41
lines changed

8 files changed

+171
-41
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package btw.lowercase.optiboxes;
2+
3+
import net.minecraft.client.gui.screens.Screen;
4+
import net.minecraft.network.chat.Component;
5+
6+
public class TestScreen extends Screen {
7+
private final Screen parent;
8+
9+
public TestScreen(Screen screen) {
10+
super(Component.literal("Test"));
11+
this.parent = screen;
12+
}
13+
14+
@Override
15+
@SuppressWarnings("DataFlowIssue")
16+
public void onClose() {
17+
minecraft.setScreen(this.parent);
18+
}
19+
}

src/main/java/btw/lowercase/optiboxes/command/OptiboxesCommand.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package btw.lowercase.optiboxes.command;
22

33
import btw.lowercase.optiboxes.OptiBoxesClient;
4-
import btw.lowercase.optiboxes.config.OptiBoxesConfig;
4+
import btw.lowercase.optiboxes.TestScreen;
55
import btw.lowercase.optiboxes.skybox.OptiFineSkyLayer;
66
import btw.lowercase.optiboxes.skybox.OptiFineSkybox;
77
import btw.lowercase.optiboxes.skybox.SkyboxManager;
@@ -17,8 +17,9 @@
1717
public class OptiboxesCommand extends LiteralArgumentBuilder<FabricClientCommandSource> {
1818
public OptiboxesCommand() {
1919
super("optiboxes");
20+
21+
Minecraft minecraft = Minecraft.getInstance();
2022
executes((context) -> {
21-
Minecraft minecraft = Minecraft.getInstance();
2223
minecraft.schedule(() -> minecraft.setScreen(OptiBoxesClient.getConfig().getConfigScreen(minecraft.screen)));
2324
return Command.SINGLE_SUCCESS;
2425
});
@@ -50,5 +51,10 @@ public OptiboxesCommand() {
5051

5152
return Command.SINGLE_SUCCESS;
5253
}));
54+
55+
then(ClientCommandManager.literal("test").executes((context) -> {
56+
minecraft.schedule(() -> minecraft.setScreen(new TestScreen(minecraft.screen)));
57+
return Command.SINGLE_SUCCESS;
58+
}));
5359
}
5460
}

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

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package btw.lowercase.optiboxes.skybox;
22

33
import btw.lowercase.optiboxes.utils.CommonUtils;
4+
import btw.lowercase.optiboxes.utils.SkyMapping;
5+
import btw.lowercase.optiboxes.utils.SkyPart;
46
import btw.lowercase.optiboxes.utils.UVRange;
57
import com.mojang.blaze3d.systems.RenderSystem;
68
import com.mojang.blaze3d.vertex.*;
@@ -12,8 +14,12 @@
1214
import org.joml.Matrix4fStack;
1315
import org.joml.Quaternionf;
1416

17+
import java.util.HashMap;
18+
import java.util.Map;
19+
1520
public final class OptiFineSkyRenderer {
1621
public static final OptiFineSkyRenderer INSTANCE = new OptiFineSkyRenderer();
22+
private static final Map<SkyPart, SkyMapping> SKY_MAPPING = new HashMap<>();
1723

1824
//? >=1.21.5 {
1925
private com.mojang.blaze3d.buffers.GpuBuffer skyBuffer;
@@ -31,11 +37,12 @@ private void buildSky() {
3137
VertexFormat vertexFormat = DefaultVertexFormat.POSITION_TEX;
3238
VertexFormat.Mode vertexFormatMode = VertexFormat.Mode.QUADS;
3339

34-
ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder(vertexFormat.getVertexSize() * 24);
40+
ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder(vertexFormat.getVertexSize() * SkyPart.COUNT * 4);
3541
BufferBuilder builder = new BufferBuilder(byteBufferBuilder, vertexFormatMode, vertexFormat);
36-
for (int face = 0; face < 6; ++face) {
37-
UVRange uvRange = CommonUtils.getUvRangeForFace(face);
38-
Matrix4f matrix4f = CommonUtils.getRotationMatrixForFace(face);
42+
for (SkyPart part : SkyPart.VALUES) {
43+
SkyMapping skyMapping = SKY_MAPPING.get(part);
44+
Matrix4f matrix4f = skyMapping.rotationMatrix();
45+
UVRange uvRange = skyMapping.mapping();
3946
final float quadSize = 100.0F;
4047
builder.addVertex(CommonUtils.getMatrixTransform(matrix4f, -quadSize, -quadSize, -quadSize)).setUv(uvRange.minU(), uvRange.minV());
4148
builder.addVertex(CommonUtils.getMatrixTransform(matrix4f, -quadSize, -quadSize, quadSize)).setUv(uvRange.minU(), uvRange.maxV());
@@ -122,7 +129,7 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
122129
.build();
123130
//?} else {
124131
/*RenderSystem.setShaderTexture(0, optiFineSkyLayer.source());
125-
RenderSystem.setShader(net.minecraft.client.renderer.CoreShaders.POSITION_TEX);
132+
RenderSystem.setShader(net.minecraft.client.renderer.CoreShaders.POSITION_TEX); // TODO: Use our custom_skybox shader
126133
optiFineSkyLayer.blend().apply(finalAlpha);
127134
*///?}
128135

@@ -198,4 +205,31 @@ public void clearCache() {
198205
this.renderPipelineCache.clear();
199206
//?}
200207
}
208+
209+
static {
210+
SKY_MAPPING.put(SkyPart.BOTTOM, new SkyMapping(
211+
new Matrix4f().rotateY((float) Math.toRadians(90.0F)),
212+
new UVRange(0.0F, 0.0F, 0.33333334F, 0.5F)
213+
));
214+
SKY_MAPPING.put(SkyPart.TOP, new SkyMapping(
215+
new Matrix4f().rotateX((float) Math.toRadians(180.0F)).rotateY((float) Math.toRadians(-90.0F)),
216+
new UVRange(0.33333334F, 0.0F, 0.6666667F, 0.5F)
217+
));
218+
SKY_MAPPING.put(SkyPart.EAST, new SkyMapping(
219+
new Matrix4f().rotateX((float) Math.toRadians(90.0F)).rotateZ((float) Math.toRadians(90.0F)),
220+
new UVRange(0.6666667F, 0.0F, 1.0F, 0.5F)
221+
));
222+
SKY_MAPPING.put(SkyPart.SOUTH, new SkyMapping(
223+
new Matrix4f().rotateX((float) Math.toRadians(90.0F)).rotateZ((float) Math.toRadians(180.0F)),
224+
new UVRange(0.0F, 0.5F, 0.33333334F, 1.0F)
225+
));
226+
SKY_MAPPING.put(SkyPart.WEST, new SkyMapping(
227+
new Matrix4f().rotateX((float) Math.toRadians(90.0F)).rotateZ((float) Math.toRadians(-90.0F)),
228+
new UVRange(0.33333334F, 0.5F, 0.6666667F, 1.0F)
229+
));
230+
SKY_MAPPING.put(SkyPart.NORTH, new SkyMapping(
231+
new Matrix4f().rotateX((float) Math.toRadians(90.0F)),
232+
new UVRange(0.6666667F, 0.5F, 1.0F, 1.0F)
233+
));
234+
}
201235
}

src/main/java/btw/lowercase/optiboxes/utils/CommonUtils.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,6 @@ public final class CommonUtils {
2626
private static final Pattern OPTIFINE_RANGE_SEPARATOR = Pattern.compile("(\\d|\\))-(\\d|\\()");
2727
private static final Logger LOGGER = LoggerFactory.getLogger(CommonUtils.class);
2828

29-
public static final UVRange[] TEXTURE_UV_RANGE_FACES = new UVRange[]{
30-
new UVRange(0.0F, 0.0F, 0.33333334F, 0.5F), // 0 (Bottom)
31-
new UVRange(0.33333334F, 0.0F, 0.6666667F, 0.5F), // 1 (Top)
32-
new UVRange(0.6666667F, 0.0F, 1.0F, 0.5F), // 2 (East)
33-
new UVRange(0.0F, 0.5F, 0.33333334F, 1.0F), // 3 (South)
34-
new UVRange(0.33333334F, 0.5F, 0.6666667F, 1.0F), // 4 (West)
35-
new UVRange(0.6666667F, 0.5F, 1.0F, 1.0F), // 5 (North)
36-
};
37-
38-
private static final Matrix4f[] MATRIX4F_ROTATED_FACES = new Matrix4f[]{
39-
new Matrix4f().rotateY((float) Math.toRadians(90.0F)), // 0 (Bottom)
40-
new Matrix4f().rotateX((float) Math.toRadians(180.0F)).rotateY((float) Math.toRadians(-90.0F)), // 1 (Top)
41-
new Matrix4f().rotateX((float) Math.toRadians(90.0F)).rotateZ((float) Math.toRadians(90.0F)), // 2 (East)
42-
new Matrix4f().rotateX((float) Math.toRadians(90.0F)).rotateZ((float) Math.toRadians(180.0F)), // 3 (South)
43-
new Matrix4f().rotateX((float) Math.toRadians(90.0F)).rotateZ((float) Math.toRadians(-90.0F)), // 4 (West)
44-
new Matrix4f().rotateX((float) Math.toRadians(90.0F)) // 5 (North)
45-
};
46-
4729
private CommonUtils() {
4830
}
4931

@@ -427,22 +409,6 @@ public static float getWeatherAlpha(List<Weather> weatherConditions, float rainS
427409
return Mth.clamp(weatherAlpha, 0.0F, 1.0F);
428410
}
429411

430-
public static UVRange getUvRangeForFace(int face) {
431-
if (face < 0 || face >= TEXTURE_UV_RANGE_FACES.length) {
432-
throw new RuntimeException("Face is out of bounds");
433-
} else {
434-
return TEXTURE_UV_RANGE_FACES[face];
435-
}
436-
}
437-
438-
public static Matrix4f getRotationMatrixForFace(int face) {
439-
if (face < 0 || face >= MATRIX4F_ROTATED_FACES.length) {
440-
throw new RuntimeException("Face is out of bounds");
441-
} else {
442-
return MATRIX4F_ROTATED_FACES[face];
443-
}
444-
}
445-
446412
public static Vector3f getMatrixTransform(Matrix4f matrix4f, float x, float y, float z) {
447413
return new Vector3f(
448414
matrix4f.m00() * x + matrix4f.m10() * y + matrix4f.m20() * z + matrix4f.m30(),
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package btw.lowercase.optiboxes.utils;
2+
3+
import org.joml.Matrix4f;
4+
import org.joml.Matrix4fStack;
5+
import org.joml.Vector4f;
6+
7+
public final class Renderer {
8+
private static final Renderer INSTANCE = new Renderer();
9+
10+
private Color shaderColor = new Color();
11+
private Matrix4fStack modelViewMatrix;
12+
private Matrix4f textureMatrix;
13+
14+
public static void setModelViewMatrix(Matrix4fStack matrix4fStack) {
15+
INSTANCE.modelViewMatrix = matrix4fStack;
16+
}
17+
18+
public static void setTextureMatrix(Matrix4f matrix4f) {
19+
INSTANCE.textureMatrix = matrix4f;
20+
}
21+
22+
public static void setShaderColor(float red, float green, float blue, float alpha) {
23+
INSTANCE.shaderColor = new Color(red, green, blue, alpha);
24+
}
25+
26+
public static void setShaderColor(float red, float green, float blue) {
27+
setShaderColor(red, green, blue, 1.0F);
28+
}
29+
30+
public static void drawWithShader() {
31+
//? >=1.21.5
32+
//? >=1.21.6
33+
com.mojang.blaze3d.buffers.GpuBufferSlice transforms = btw.lowercase.optiboxes.utils.DynamicTransformsBuilder.of()
34+
.withModelViewMatrix(INSTANCE.modelViewMatrix)
35+
.withTextureMatrix(INSTANCE.textureMatrix)
36+
.withShaderColor(INSTANCE.shaderColor.vector4f())
37+
.build();
38+
//? }
39+
//? } else {
40+
/*
41+
RenderSystem.setTextureMatrix(INSTANCE.textureMatrix);
42+
RenderSystem.setShaderColor(INSTANCE.shaderColor.red(), INSTANCE.shaderColor.green(), INSTANCE.shaderColor.blue(), INSTANCE.shaderColor.alpha());
43+
*///? }
44+
}
45+
46+
private record Color(float red, float green, float blue, float alpha) {
47+
public Color() {
48+
this(1.0F, 1.0F, 1.0F, 1.0F);
49+
}
50+
51+
public Vector4f vector4f() {
52+
return new Vector4f(red, green, blue, alpha);
53+
}
54+
}
55+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package btw.lowercase.optiboxes.utils;
2+
3+
import org.joml.Matrix4f;
4+
5+
public record SkyMapping(Matrix4f rotationMatrix, UVRange mapping) {
6+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package btw.lowercase.optiboxes.utils;
2+
3+
public enum SkyPart {
4+
BOTTOM,
5+
TOP,
6+
EAST,
7+
SOUTH,
8+
WEST,
9+
NORTH;
10+
11+
public static final SkyPart[] VALUES = values();
12+
public static final int COUNT = VALUES.length;
13+
14+
public static SkyPart of(int ordinal) {
15+
if (ordinal < 0) {
16+
throw new RuntimeException("Face not found! Ordinal is below 0 which is not allowed!");
17+
} else if (ordinal > COUNT) {
18+
throw new RuntimeException("Face not found! Ordinal is above the count of faces!");
19+
} else {
20+
return VALUES[ordinal];
21+
}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"options.optiboxes.title": "OptiBoxes Beállítások",
3+
"options.optiboxes.enabled": "Bekapcsolva",
4+
"options.optiboxes.enabled.tooltip": "Egyedi égbolt ki/bekapcsolása.",
5+
"options.optiboxes.processOptiFine": "OptiFine feldolgozása",
6+
"options.optiboxes.processOptiFine.tooltip": "Ha be van kapcsolva, a mod megpróbálja olvasni/betölteni az OptiFine egyedi égboltját.",
7+
"options.optiboxes.processMCPatcher": "MCPatcher feldolgozása",
8+
"options.optiboxes.processMCPatcher.tooltip": "Ha be van kapcsolva, a mod megpróbálja olvasni/betölteni az MCPatcher egyedi égboltját.",
9+
"options.optiboxes.renderSunMoon": "Nap és Hold mutatása",
10+
"options.optiboxes.renderSunMoon.tooltip": "Nap és Hold mutatásának ki/bekapcsolása.",
11+
"options.optiboxes.renderStars": "Csillagok mutatása",
12+
"options.optiboxes.renderStars.tooltip": "Csillagok mutatásának ki/bekapcsolása.",
13+
"options.optiboxes.showOverworldForUnknownDimension": "Felvilág mutatása ismeretlen dimenzióban",
14+
"options.optiboxes.showOverworldForUnknownDimension.tooltip": "A felvilág égboltját fogja mutatni ismeretlen dimenzióban. A nether/end-ben nem fogja mutatni, ha csak egy égbolt nem definiálja.",
15+
"options.optiboxes.ignoreBrokenSkies": "Hibás egek figyelmen kívül hagyása",
16+
"options.optiboxes.ignoreBrokenSkies.tooltip": "Ha valamit egy égbolt rétegben nem sikerül betölteni, figyelmen kívül lesz hagyva és nem lesz betöltve.",
17+
"options.template": "%s: %s",
18+
"options.on": "BE",
19+
"options.off": "KI",
20+
"options.reset": "Visszaállít"
21+
}

0 commit comments

Comments
 (0)