Skip to content

Commit 4dcc640

Browse files
committed
1.21.4 working
1 parent 4c5ecc8 commit 4dcc640

File tree

4 files changed

+72
-55
lines changed

4 files changed

+72
-55
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package btw.lowercase.optiboxes.mixins;
22

33
import org.spongepowered.asm.mixin.Mixin;
4-
import org.spongepowered.asm.mixin.gen.Accessor;
54

65
//? >= 1.21.5 {
76
@Mixin(net.minecraft.client.renderer.RenderPipelines.class)
7+
//?} else {
8+
/*@Mixin(net.minecraft.client.Minecraft.class)
9+
*///?}
810
public interface RenderPipelinesAccessor {
11+
//? >= 1.21.5 {
912
//? >=1.21.6 {
10-
@Accessor("MATRICES_PROJECTION_SNIPPET")
13+
@org.spongepowered.asm.mixin.gen.Accessor("MATRICES_PROJECTION_SNIPPET")
1114
//?} else {
12-
/*@Accessor("MATRICES_COLOR_FOG_SNIPPET")
15+
/*@org.spongepowered.asm.mixin.gen.Accessor("MATRICES_COLOR_FOG_SNIPPET")
1316
*///?}
1417
static com.mojang.blaze3d.pipeline.RenderPipeline.Snippet optiboxes$getMatricesProjectionSnippet() {
1518
return null;
1619
}
17-
}
18-
//?} else {
19-
/*public interface RenderPipelinesAccessor {
20-
}*/
21-
//?}
20+
//?}
21+
}

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

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
package btw.lowercase.optiboxes.skybox;
22

3-
import btw.lowercase.optiboxes.OptiBoxesClient;
4-
import btw.lowercase.optiboxes.mixins.RenderPipelinesAccessor;
53
import btw.lowercase.optiboxes.utils.CommonUtils;
6-
import btw.lowercase.optiboxes.utils.IrisUtil;
74
import btw.lowercase.optiboxes.utils.UVRange;
8-
import btw.lowercase.optiboxes.utils.components.Blend;
9-
import com.mojang.blaze3d.buffers.GpuBuffer;
10-
import com.mojang.blaze3d.pipeline.RenderTarget;
11-
import com.mojang.blaze3d.systems.RenderPass;
125
import com.mojang.blaze3d.systems.RenderSystem;
136
import com.mojang.blaze3d.vertex.*;
147
import net.minecraft.client.Minecraft;
15-
import net.minecraft.client.renderer.texture.AbstractTexture;
16-
import net.minecraft.resources.ResourceLocation;
8+
import net.minecraft.client.renderer.CoreShaders;
179
import net.minecraft.util.Mth;
1810
import net.minecraft.world.level.Level;
19-
import org.jetbrains.annotations.Nullable;
20-
import org.joml.*;
21-
22-
import java.lang.Math;
23-
import java.util.HashMap;
24-
import java.util.Map;
25-
import java.util.OptionalDouble;
26-
import java.util.OptionalInt;
11+
import org.joml.AxisAngle4f;
12+
import org.joml.Matrix4f;
13+
import org.joml.Matrix4fStack;
14+
import org.joml.Quaternionf;
2715

2816
public final class OptiFineSkyRenderer {
2917
public static final OptiFineSkyRenderer INSTANCE = new OptiFineSkyRenderer();
3018

31-
private GpuBuffer skyBuffer;
19+
//? >=1.21.5 {
20+
private com.mojang.blaze3d.buffers.GpuBuffer skyBuffer;
3221
private RenderSystem.AutoStorageIndexBuffer skyBufferIndices;
3322
private int skyBufferIndexCount;
23+
//?} else {
24+
/*private com.mojang.blaze3d.vertex.VertexBuffer skyBuffer;
25+
*///?}
3426

3527
private OptiFineSkyRenderer() {
3628
Minecraft.getInstance().schedule(this::buildSky);
@@ -52,29 +44,37 @@ private void buildSky() {
5244
builder.addVertex(CommonUtils.getMatrixTransform(matrix4f, quadSize, -quadSize, -quadSize)).setUv(uvRange.maxU(), uvRange.minV());
5345
}
5446

47+
//? >=1.21.5
5548
skyBufferIndices = RenderSystem.getSequentialBuffer(vertexFormatMode);
5649
try (MeshData meshData = builder.buildOrThrow()) {
50+
//? >=1.21.5 {
5751
skyBufferIndexCount = meshData.drawState().indexCount();
5852
skyBuffer = RenderSystem.getDevice().createBuffer(
5953
() -> "OptiFine Skybox",
6054
//? >=1.21.6 {
61-
GpuBuffer.USAGE_COPY_DST,
55+
com.mojang.blaze3d.buffers.GpuBuffer.USAGE_COPY_DST,
6256
//?} else {
6357
/*com.mojang.blaze3d.buffers.BufferType.VERTICES, com.mojang.blaze3d.buffers.BufferUsage.STATIC_WRITE,
64-
*///?}
58+
*///?}
6559
meshData.vertexBuffer()
6660
);
61+
//?} else {
62+
/*skyBuffer = new com.mojang.blaze3d.vertex.VertexBuffer(com.mojang.blaze3d.buffers.BufferUsage.STATIC_WRITE);
63+
skyBuffer.bind();
64+
skyBuffer.upload(meshData);
65+
com.mojang.blaze3d.vertex.VertexBuffer.unbind();
66+
*///?}
6767
}
6868
}
6969

7070
//? >=1.21.5 {
7171
private final Map<ResourceLocation, com.mojang.blaze3d.pipeline.RenderPipeline> renderPipelineCache = new HashMap<>();
7272

73-
public static com.mojang.blaze3d.pipeline.RenderPipeline getSkyboxPipeline(@Nullable btw.lowercase.optiboxes.utils.BlendFunction blendFunction) {
74-
com.mojang.blaze3d.pipeline.RenderPipeline.Builder builder = com.mojang.blaze3d.pipeline.RenderPipeline.builder(RenderPipelinesAccessor.optiboxes$getMatricesProjectionSnippet());
75-
builder.withLocation(OptiBoxesClient.id("pipeline/custom_skybox"));
76-
builder.withVertexShader(OptiBoxesClient.id("core/custom_skybox"));
77-
builder.withFragmentShader(OptiBoxesClient.id("core/custom_skybox"));
73+
public static com.mojang.blaze3d.pipeline.RenderPipeline getSkyboxPipeline(@org.jetbrains.annotations.Nullable btw.lowercase.optiboxes.utils.BlendFunction blendFunction) {
74+
com.mojang.blaze3d.pipeline.RenderPipeline.Builder builder = com.mojang.blaze3d.pipeline.RenderPipeline.builder(btw.lowercase.optiboxes.mixins.RenderPipelinesAccessor.optiboxes$getMatricesProjectionSnippet());
75+
builder.withLocation(btw.lowercase.optiboxes.OptiBoxesClient.id("pipeline/custom_skybox"));
76+
builder.withVertexShader(btw.lowercase.optiboxes.OptiBoxesClient.id("core/custom_skybox"));
77+
builder.withFragmentShader(btw.lowercase.optiboxes.OptiBoxesClient.id("core/custom_skybox"));
7878
builder.withDepthWrite(false);
7979
builder.withColorWrite(true, false);
8080
if (blendFunction != null) {
@@ -101,8 +101,7 @@ public void renderSkybox(OptiFineSkybox optiFineSkybox, Matrix4fStack modelViewS
101101
}
102102

103103
//? <=1.21.5 {
104-
/*Vector4f shaderColor = Blend.ADD.getShaderColor(1.0F - rainLevel);
105-
RenderSystem.setShaderColor(shaderColor.x, shaderColor.y, shaderColor.z, shaderColor.w);
104+
/*btw.lowercase.optiboxes.utils.components.Blend.ADD.apply(1.0F - rainLevel);
106105
*///?}
107106
}
108107

@@ -117,26 +116,25 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
117116
modelViewStack.rotate(new Quaternionf(new AxisAngle4f(this.getAngle(level, skyAngle, optiFineSkyLayer.speed()), optiFineSkyLayer.axis())));
118117
}
119118

120-
Vector4f shaderColor = optiFineSkyLayer.blend().getShaderColor(finalAlpha);
121-
AbstractTexture skyTexture = Minecraft.getInstance().getTextureManager().getTexture(optiFineSkyLayer.source());
122-
123119
//? >=1.21.6 {
124120
com.mojang.blaze3d.buffers.GpuBufferSlice transforms = btw.lowercase.optiboxes.utils.DynamicTransformsBuilder.of()
125121
.withModelViewMatrix(modelViewStack)
126-
.withShaderColor(shaderColor)
122+
.withShaderColor(optiFineSkyLayer.blend().getShaderColor(finalAlpha))
127123
.build();
128124
//?} else {
129-
/*RenderSystem.setShaderColor(shaderColor.x, shaderColor.y, shaderColor.z, shaderColor.w);
125+
/*RenderSystem.setShaderTexture(0, optiFineSkyLayer.source());
126+
RenderSystem.setShader(CoreShaders.POSITION_TEX);
127+
optiFineSkyLayer.blend().apply(finalAlpha);
130128
*///?}
131129

132130
//? >=1.21.5 {
133131
com.mojang.blaze3d.pipeline.RenderPipeline renderPipeline = this.renderPipelineCache.computeIfAbsent(optiFineSkyLayer.source(), (resourceLocation) -> {
134132
com.mojang.blaze3d.pipeline.RenderPipeline pipeline = getSkyboxPipeline(optiFineSkyLayer.blend().getBlendFunction());
135-
IrisUtil.assignPipeline(pipeline, IrisUtil.skyTextured());
133+
btw.lowercase.optiboxes.utils.IrisUtil.assignPipeline(pipeline, btw.lowercase.optiboxes.utils.IrisUtil.skyTextured());
136134
return pipeline;
137135
});
138136

139-
RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget();
137+
com.mojang.blaze3d.pipeline.RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget();
140138

141139
//? >=1.21.6 {
142140
com.mojang.blaze3d.textures.GpuTextureView texture = skyTexture.getTextureView();
@@ -148,8 +146,9 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
148146
com.mojang.blaze3d.textures.GpuTexture depthTexture = renderTarget.getDepthTexture();
149147
*///?}
150148

151-
GpuBuffer indexBuffer = this.skyBufferIndices.getBuffer(this.skyBufferIndexCount);
152-
try (RenderPass renderPass = RenderSystem.getDevice()
149+
net.minecraft.client.renderer.texture.AbstractTexture skyTexture = Minecraft.getInstance().getTextureManager().getTexture(optiFineSkyLayer.source());
150+
com.mojang.blaze3d.buffers.GpuBuffer indexBuffer = this.skyBufferIndices.getBuffer(this.skyBufferIndexCount);
151+
try (com.mojang.blaze3d.systems.RenderPass renderPass = RenderSystem.getDevice()
153152
.createCommandEncoder()
154153
.createRenderPass(
155154
//? >=1.21.6
@@ -169,13 +168,15 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
169168
renderPass.bindSampler("Sampler0", texture);
170169
//? >=1.21.6 {
171170
renderPass.drawIndexed(0, 0, this.skyBufferIndexCount, 1);
172-
//?} else {
171+
//?} else {
173172
/*renderPass.drawIndexed(0, this.skyBufferIndexCount);
174-
*///?}
173+
*///?}
175174
}
176175
//?} else {
177-
178-
//?}
176+
/*this.skyBuffer.bind();
177+
this.skyBuffer.drawWithShader(modelViewStack, RenderSystem.getProjectionMatrix(), RenderSystem.getShader());
178+
com.mojang.blaze3d.vertex.VertexBuffer.unbind();
179+
*///?}
179180

180181
modelViewStack.popMatrix();
181182
}
@@ -196,6 +197,6 @@ private float getAngle(Level level, float skyAngle, float speed) {
196197
public void clearCache() {
197198
//? >=1.21.5 {
198199
this.renderPipelineCache.clear();
199-
//?}
200+
//?}
200201
}
201202
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package btw.lowercase.optiboxes.utils;
22

3-
import com.mojang.blaze3d.pipeline.RenderPipeline;
43
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
65

7-
import java.lang.reflect.Method;
8-
96
public final class IrisUtil {
107
private static final Logger LOGGER = LoggerFactory.getLogger(IrisUtil.class);
118

129
private static Object IRIS_INSTANCE = null;
13-
private static Method IRIS_ASSIGN_PIPELINE_METHOD = null;
10+
//? >= 1.21.5 {
11+
private static java.lang.reflect.Method IRIS_ASSIGN_PIPELINE_METHOD = null;
1412
private static Enum<?> IRIS_PROGRAM_SKY_BASIC = null;
1513
private static Enum<?> IRIS_PROGRAM_SKY_TEXTURED = null;
14+
//?}
1615

1716
private IrisUtil() {
1817
}
@@ -25,19 +24,22 @@ private static void initialize() {
2524
Class<?> irisInstanceClass = IRIS_INSTANCE.getClass();
2625

2726
// Enum
27+
//? >= 1.21.5 {
2828
Class<?> irisProgramEnum = Class.forName("net.irisshaders.iris.api.v0.IrisProgram");
2929
IRIS_PROGRAM_SKY_BASIC = Enum.valueOf(irisProgramEnum.asSubclass(Enum.class), "SKY_BASIC");
3030
IRIS_PROGRAM_SKY_TEXTURED = Enum.valueOf(irisProgramEnum.asSubclass(Enum.class), "SKY_TEXTURED");
3131

3232
// Methods
33-
IRIS_ASSIGN_PIPELINE_METHOD = irisInstanceClass.getMethod("assignPipeline", RenderPipeline.class, irisProgramEnum);
33+
IRIS_ASSIGN_PIPELINE_METHOD = irisInstanceClass.getMethod("assignPipeline", com.mojang.blaze3d.pipeline.RenderPipeline.class, irisProgramEnum);
34+
//?}
3435
} catch (Exception exception) {
3536
LOGGER.error("Failed to initialize iris util! Iris may not be installed so just ignore this message!");
3637
exception.printStackTrace();
3738
}
3839
}
3940

40-
public static void assignPipeline(RenderPipeline pipeline, Object enumValue) {
41+
//? >= 1.21.5 {
42+
public static void assignPipeline(com.mojang.blaze3d.pipeline.RenderPipeline pipeline, Object enumValue) {
4143
if (IRIS_ASSIGN_PIPELINE_METHOD != null) {
4244
try {
4345
IRIS_ASSIGN_PIPELINE_METHOD.invoke(IRIS_INSTANCE, pipeline, enumValue);
@@ -55,6 +57,7 @@ public static Enum<?> skyBasic() {
5557
public static Enum<?> skyTextured() {
5658
return IRIS_PROGRAM_SKY_TEXTURED;
5759
}
60+
//?}
5861

5962
static {
6063
initialize();

src/main/java/btw/lowercase/optiboxes/utils/components/Blend.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ public Vector4f getShaderColor(float value) {
4040
return this.blendConsumer.apply(value);
4141
}
4242

43+
//? <=1.21.5 {
44+
/*public void apply(float value) {
45+
final Vector4f shaderColor = getShaderColor(value);
46+
com.mojang.blaze3d.systems.RenderSystem.setShaderColor(shaderColor.x, shaderColor.y, shaderColor.z, shaderColor.w);
47+
if (this.blendFunction != null) {
48+
com.mojang.blaze3d.systems.RenderSystem.enableBlend();
49+
com.mojang.blaze3d.systems.RenderSystem.blendFunc(this.blendFunction.srcFactor(), this.blendFunction.dstFactor());
50+
} else {
51+
com.mojang.blaze3d.systems.RenderSystem.disableBlend();
52+
}
53+
}
54+
*///?}
55+
4356
public BlendFunction getBlendFunction() {
4457
return this.blendFunction;
4558
}

0 commit comments

Comments
 (0)