Update CarryOnRenderType.java
This commit is contained in:
parent
32db7222b7
commit
41b518942d
|
|
@ -1,108 +1,108 @@
|
||||||
package tschipp.carryon.client.render;
|
// package tschipp.carryon.client.render;
|
||||||
|
|
||||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
// import com.mojang.blaze3d.pipeline.BlendFunction;
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
// import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.DepthTestFunction;
|
// import com.mojang.blaze3d.platform.DepthTestFunction;
|
||||||
import com.mojang.blaze3d.vertex.MeshData;
|
// import com.mojang.blaze3d.vertex.MeshData;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
// import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
// import net.minecraft.client.renderer.RenderType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
// import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
// import java.util.IdentityHashMap;
|
||||||
import java.util.Map;
|
// import java.util.Map;
|
||||||
|
|
||||||
//Credit: klikli for the idea and code for this wrapper
|
// //Credit: klikli for the idea and code for this wrapper
|
||||||
public class CarryOnRenderType extends RenderType {
|
// public class CarryOnRenderType extends RenderType {
|
||||||
|
|
||||||
private static final Map<RenderType, RenderType> remappedTypes = new IdentityHashMap<>();
|
// private static final Map<RenderType, RenderType> remappedTypes = new IdentityHashMap<>();
|
||||||
private final RenderPipeline pipeline;
|
// private final RenderPipeline pipeline;
|
||||||
private final RenderType original;
|
// private final RenderType original;
|
||||||
|
|
||||||
private CarryOnRenderType(RenderType original, RenderPipeline pipeline) {
|
// private CarryOnRenderType(RenderType original, RenderPipeline pipeline) {
|
||||||
super(String.format("%s_carryon", original.toString()), original.bufferSize(), original.affectsCrumbling(), true, original::setupRenderState, original::clearRenderState);
|
// super(String.format("%s_carryon", original.toString()), original.bufferSize(), original.affectsCrumbling(), true, original::setupRenderState, original::clearRenderState);
|
||||||
this.pipeline = pipeline;
|
// this.pipeline = pipeline;
|
||||||
this.original = original;
|
// this.original = original;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static RenderType remap(RenderType in) {
|
// public static RenderType remap(RenderType in) {
|
||||||
return remappedTypes.computeIfAbsent(in, (type) -> {
|
// return remappedTypes.computeIfAbsent(in, (type) -> {
|
||||||
|
|
||||||
//modify the pipeline
|
// //modify the pipeline
|
||||||
var pipeline = toBuilder(in.pipeline())
|
// var pipeline = toBuilder(in.pipeline())
|
||||||
.withBlend(BlendFunction.TRANSLUCENT)
|
// .withBlend(BlendFunction.TRANSLUCENT)
|
||||||
.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST)
|
// .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST)
|
||||||
.withCull(false);
|
// .withCull(false);
|
||||||
|
|
||||||
return new CarryOnRenderType(type, pipeline.build());
|
// return new CarryOnRenderType(type, pipeline.build());
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
private static RenderPipeline.Builder toBuilder(RenderPipeline pipeline) {
|
// private static RenderPipeline.Builder toBuilder(RenderPipeline pipeline) {
|
||||||
RenderPipeline.Builder builder = RenderPipeline.builder();
|
// RenderPipeline.Builder builder = RenderPipeline.builder();
|
||||||
builder.withLocation(pipeline.getLocation());
|
// builder.withLocation(pipeline.getLocation());
|
||||||
builder.withFragmentShader(pipeline.getFragmentShader());
|
// builder.withFragmentShader(pipeline.getFragmentShader());
|
||||||
builder.withVertexShader(pipeline.getVertexShader());
|
// builder.withVertexShader(pipeline.getVertexShader());
|
||||||
|
|
||||||
if (!pipeline.getShaderDefines().isEmpty()) {
|
// if (!pipeline.getShaderDefines().isEmpty()) {
|
||||||
for (Map.Entry<String, String> entry : pipeline.getShaderDefines().values().entrySet()) {
|
// for (Map.Entry<String, String> entry : pipeline.getShaderDefines().values().entrySet()) {
|
||||||
try {
|
// try {
|
||||||
int parsed = Integer.parseInt(entry.getValue());
|
// int parsed = Integer.parseInt(entry.getValue());
|
||||||
builder.withShaderDefine(entry.getKey(), parsed);
|
// builder.withShaderDefine(entry.getKey(), parsed);
|
||||||
} catch (NumberFormatException e) {
|
// } catch (NumberFormatException e) {
|
||||||
float parsed = Float.parseFloat(entry.getValue());
|
// float parsed = Float.parseFloat(entry.getValue());
|
||||||
builder.withShaderDefine(entry.getKey(), parsed);
|
// builder.withShaderDefine(entry.getKey(), parsed);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
for (String flag : pipeline.getShaderDefines().flags()) {
|
// for (String flag : pipeline.getShaderDefines().flags()) {
|
||||||
builder.withShaderDefine(flag);
|
// builder.withShaderDefine(flag);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!pipeline.getSamplers().isEmpty()) {
|
// if (!pipeline.getSamplers().isEmpty()) {
|
||||||
pipeline.getSamplers().forEach(builder::withSampler);
|
// pipeline.getSamplers().forEach(builder::withSampler);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!pipeline.getUniforms().isEmpty()) {
|
// if (!pipeline.getUniforms().isEmpty()) {
|
||||||
pipeline.getUniforms().forEach(u -> builder.withUniform(u.name(), u.type()));
|
// pipeline.getUniforms().forEach(u -> builder.withUniform(u.name(), u.type()));
|
||||||
}
|
// }
|
||||||
|
|
||||||
builder.withDepthTestFunction(pipeline.getDepthTestFunction());
|
// builder.withDepthTestFunction(pipeline.getDepthTestFunction());
|
||||||
builder.withPolygonMode(pipeline.getPolygonMode());
|
// builder.withPolygonMode(pipeline.getPolygonMode());
|
||||||
builder.withCull(pipeline.isCull());
|
// builder.withCull(pipeline.isCull());
|
||||||
builder.withColorWrite(pipeline.isWriteColor(), pipeline.isWriteAlpha());
|
// builder.withColorWrite(pipeline.isWriteColor(), pipeline.isWriteAlpha());
|
||||||
builder.withDepthWrite(pipeline.isWriteDepth());
|
// builder.withDepthWrite(pipeline.isWriteDepth());
|
||||||
builder.withColorLogic(pipeline.getColorLogic());
|
// builder.withColorLogic(pipeline.getColorLogic());
|
||||||
|
|
||||||
if (pipeline.getBlendFunction().isPresent())
|
// if (pipeline.getBlendFunction().isPresent())
|
||||||
builder.withBlend(pipeline.getBlendFunction().get());
|
// builder.withBlend(pipeline.getBlendFunction().get());
|
||||||
else
|
// else
|
||||||
builder.withoutBlend();
|
// builder.withoutBlend();
|
||||||
builder.withVertexFormat(pipeline.getVertexFormat(), pipeline.getVertexFormatMode());
|
// builder.withVertexFormat(pipeline.getVertexFormat(), pipeline.getVertexFormatMode());
|
||||||
builder.withDepthBias(pipeline.getDepthBiasScaleFactor(), pipeline.getDepthBiasConstant());
|
// builder.withDepthBias(pipeline.getDepthBiasScaleFactor(), pipeline.getDepthBiasConstant());
|
||||||
|
|
||||||
return builder;
|
// return builder;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void draw(@NotNull MeshData meshData) {
|
// public void draw(@NotNull MeshData meshData) {
|
||||||
this.original.draw(meshData);
|
// this.original.draw(meshData);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public @NotNull VertexFormat format() {
|
// public @NotNull VertexFormat format() {
|
||||||
return this.original.format();
|
// return this.original.format();
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public VertexFormat.@NotNull Mode mode() {
|
// public VertexFormat.@NotNull Mode mode() {
|
||||||
return this.original.mode();
|
// return this.original.mode();
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public RenderPipeline pipeline() {
|
// public RenderPipeline pipeline() {
|
||||||
return this.pipeline; //get our own modified pipeline
|
// return this.pipeline; //get our own modified pipeline
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user