11package me .pepperbell .continuity .client .model ;
22
33import java .util .function .Function ;
4+ import java .util .function .Predicate ;
45import java .util .function .Supplier ;
56
7+ import org .jetbrains .annotations .Nullable ;
8+
69import me .pepperbell .continuity .api .client .QuadProcessor ;
710import me .pepperbell .continuity .client .config .ContinuityConfig ;
811import me .pepperbell .continuity .client .util .RenderUtil ;
912import me .pepperbell .continuity .impl .client .ProcessingContextImpl ;
1013import net .fabricmc .fabric .api .renderer .v1 .mesh .MutableQuadView ;
11- import net .fabricmc .fabric .api .renderer .v1 .model . ForwardingBakedModel ;
12- import net .fabricmc .fabric .api .renderer .v1 .render . RenderContext ;
14+ import net .fabricmc .fabric .api .renderer .v1 .mesh . QuadEmitter ;
15+ import net .fabricmc .fabric .api .renderer .v1 .mesh . QuadTransform ;
1316import net .minecraft .block .BlockState ;
1417import net .minecraft .client .render .model .BakedModel ;
18+ import net .minecraft .client .render .model .WrapperBakedModel ;
1519import net .minecraft .client .texture .Sprite ;
1620import net .minecraft .util .math .BlockPos ;
1721import net .minecraft .util .math .Direction ;
1822import net .minecraft .util .math .random .Random ;
1923import net .minecraft .world .BlockRenderView ;
2024
21- public class CtmBakedModel extends ForwardingBakedModel {
25+ public class CtmBakedModel extends WrapperBakedModel {
2226 public static final int PASSES = 4 ;
2327
2428 protected final BlockState defaultState ;
2529 protected volatile Function <Sprite , QuadProcessors .Slice > defaultSliceFunc ;
2630
2731 public CtmBakedModel (BakedModel wrapped , BlockState defaultState ) {
28- this . wrapped = wrapped ;
32+ super ( wrapped ) ;
2933 this .defaultState = defaultState ;
3034 }
3135
3236 @ Override
33- public void emitBlockQuads (BlockRenderView blockView , BlockState state , BlockPos pos , Supplier <Random > randomSupplier , RenderContext context ) {
37+ public void emitBlockQuads (QuadEmitter emitter , BlockRenderView blockView , BlockState state , BlockPos pos , Supplier <Random > randomSupplier , Predicate < @ Nullable Direction > cullTest ) {
3438 if (!ContinuityConfig .INSTANCE .connectedTextures .get ()) {
35- super .emitBlockQuads (blockView , state , pos , randomSupplier , context );
39+ super .emitBlockQuads (emitter , blockView , state , pos , randomSupplier , cullTest );
3640 return ;
3741 }
3842
3943 ModelObjectsContainer container = ModelObjectsContainer .get ();
4044 if (!container .featureStates .getConnectedTexturesState ().isEnabled ()) {
41- super .emitBlockQuads (blockView , state , pos , randomSupplier , context );
45+ super .emitBlockQuads (emitter , blockView , state , pos , randomSupplier , cullTest );
4246 return ;
4347 }
4448
4549 CtmQuadTransform quadTransform = container .ctmQuadTransform ;
4650 if (quadTransform .isActive ()) {
47- super .emitBlockQuads (blockView , state , pos , randomSupplier , context );
51+ super .emitBlockQuads (emitter , blockView , state , pos , randomSupplier , cullTest );
4852 return ;
4953 }
5054
@@ -65,13 +69,13 @@ public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos
6569 // especially if there is an actual use case for it.
6670 BlockState appearanceState = state .getAppearance (blockView , pos , Direction .DOWN , state , pos );
6771
68- quadTransform .prepare (blockView , appearanceState , state , pos , randomSupplier , context , ContinuityConfig . INSTANCE . useManualCulling . get () , getSliceFunc (appearanceState ));
72+ quadTransform .prepare (blockView , appearanceState , state , pos , randomSupplier , cullTest , getSliceFunc (appearanceState ));
6973
70- context .pushTransform (quadTransform );
71- super .emitBlockQuads (blockView , state , pos , randomSupplier , context );
72- context .popTransform ();
74+ emitter .pushTransform (quadTransform );
75+ super .emitBlockQuads (emitter , blockView , state , pos , randomSupplier , cullTest );
76+ emitter .popTransform ();
7377
74- quadTransform .processingContext .outputTo (context . getEmitter () );
78+ quadTransform .processingContext .outputTo (emitter );
7579 quadTransform .reset ();
7680 }
7781
@@ -100,23 +104,22 @@ protected Function<Sprite, QuadProcessors.Slice> getSliceFunc(BlockState state)
100104 return QuadProcessors .getCache (state );
101105 }
102106
103- protected static class CtmQuadTransform implements RenderContext . QuadTransform {
107+ protected static class CtmQuadTransform implements QuadTransform {
104108 protected final ProcessingContextImpl processingContext = new ProcessingContextImpl ();
105109
106110 protected BlockRenderView blockView ;
107111 protected BlockState appearanceState ;
108112 protected BlockState state ;
109113 protected BlockPos pos ;
110114 protected Supplier <Random > randomSupplier ;
111- protected RenderContext renderContext ;
112- protected boolean useManualCulling ;
115+ protected Predicate <@ Nullable Direction > cullTest ;
113116 protected Function <Sprite , QuadProcessors .Slice > sliceFunc ;
114117
115118 protected boolean active ;
116119
117120 @ Override
118121 public boolean transform (MutableQuadView quad ) {
119- if (useManualCulling && renderContext . isFaceCulled (quad .cullFace ())) {
122+ if (cullTest . test (quad .cullFace ())) {
120123 return false ;
121124 }
122125
@@ -156,19 +159,16 @@ public boolean isActive() {
156159 return active ;
157160 }
158161
159- public void prepare (BlockRenderView blockView , BlockState appearanceState , BlockState state , BlockPos pos , Supplier <Random > randomSupplier , RenderContext renderContext , boolean useManualCulling , Function <Sprite , QuadProcessors .Slice > sliceFunc ) {
162+ public void prepare (BlockRenderView blockView , BlockState appearanceState , BlockState state , BlockPos pos , Supplier <Random > randomSupplier , Predicate < @ Nullable Direction > cullTest , Function <Sprite , QuadProcessors .Slice > sliceFunc ) {
160163 this .blockView = blockView ;
161164 this .appearanceState = appearanceState ;
162165 this .state = state ;
163166 this .pos = pos ;
164167 this .randomSupplier = randomSupplier ;
165- this .renderContext = renderContext ;
166- this .useManualCulling = useManualCulling ;
168+ this .cullTest = cullTest ;
167169 this .sliceFunc = sliceFunc ;
168170
169171 active = true ;
170-
171- processingContext .prepare ();
172172 }
173173
174174 public void reset () {
@@ -177,8 +177,7 @@ public void reset() {
177177 state = null ;
178178 pos = null ;
179179 randomSupplier = null ;
180- renderContext = null ;
181- useManualCulling = false ;
180+ cullTest = null ;
182181 sliceFunc = null ;
183182
184183 active = false ;
0 commit comments