1717package net .fabricmc .fabric .api .client .rendering .v1 ;
1818
1919import java .util .Optional ;
20+ import java .util .function .Consumer ;
2021
2122import com .mojang .blaze3d .pipeline .RenderPipeline ;
2223
24+ import net .fabricmc .fabric .impl .client .rendering .FabricRenderPipelineImpl ;
25+
2326/**
2427 * General purpose Fabric extensions to the {@link RenderPipeline} class.
2528 *
@@ -35,6 +38,41 @@ default boolean usePipelineDrawModeForGui() {
3538 throw new AssertionError ("Implemented in Mixin" );
3639 }
3740
41+ /**
42+ * Creates a builder that when built would create this pipeline.
43+ * Note that the caller must call {@link RenderPipeline.Builder#withLocation(net.minecraft.resources.Identifier)} returned builder before building.
44+ *
45+ * @return a builder that could build this pipeline
46+ */
47+ default RenderPipeline .Builder toBuilder () {
48+ RenderPipeline $self = (RenderPipeline ) this ;
49+ RenderPipeline .Builder builder = RenderPipeline .builder ()
50+ .withLocation ($self .getLocation ())
51+ .withVertexShader ($self .getVertexShader ())
52+ .withFragmentShader ($self .getFragmentShader ())
53+ .withDepthTestFunction ($self .getDepthTestFunction ())
54+ .withPolygonMode ($self .getPolygonMode ())
55+ .withCull ($self .isCull ())
56+ .withColorLogic ($self .getColorLogic ())
57+ .withColorWrite ($self .isWriteColor (), $self .isWriteAlpha ())
58+ .withDepthWrite ($self .isWriteDepth ())
59+ .withVertexFormat ($self .getVertexFormat (), $self .getVertexFormatMode ())
60+ .withDepthBias ($self .getDepthBiasScaleFactor (), $self .getDepthBiasConstant ())
61+ .withUsePipelineDrawModeForGui ($self .usePipelineDrawModeForGui ());
62+ $self .getShaderDefines ().values ().forEach ((v1 , v2 ) -> ((FabricRenderPipelineImpl .BuilderImpl ) builder ).fabric$getShaderDefines ().define (v1 , v2 ));
63+ $self .getShaderDefines ().flags ().forEach (flag -> ((FabricRenderPipelineImpl .BuilderImpl ) builder ).fabric$getShaderDefines ().define (flag ));
64+ return builder ;
65+ }
66+
67+ /**
68+ * Creates a snippet that describes this pipeline.
69+ *
70+ * @return a snippet that describes this pipeline
71+ */
72+ default RenderPipeline .Snippet toSnippet () {
73+ return toBuilder ().buildSnippet ();
74+ }
75+
3876 /**
3977 * General purpose Fabric extensions to the {@link RenderPipeline.Builder} class.
4078 *
@@ -76,6 +114,18 @@ default Optional<Boolean> usePipelineDrawModeForGui() {
76114 throw new AssertionError ("Implemented in Mixin" );
77115 }
78116
117+ /**
118+ * Creates a new snippet that is identical to this one aside from the changes induced by {@code mutator}.
119+ *
120+ * @param mutator the changes to make to this snippet
121+ * @return a new snippet identical to this one aside from the changes applied by mutator
122+ */
123+ default RenderPipeline .Snippet with (Consumer <RenderPipeline .Builder > mutator ) {
124+ RenderPipeline .Builder builder = RenderPipeline .builder ((RenderPipeline .Snippet ) this );
125+ mutator .accept (builder );
126+ return builder .buildSnippet ();
127+ }
128+
79129 /**
80130 * Creates a new snippet with the specified pipeline draw mode for GUI rendering.
81131 *
0 commit comments