11package ca .fxco .moreculling .mixin .renderers ;
22
33import ca .fxco .moreculling .MoreCulling ;
4+ import ca .fxco .moreculling .api .renderers .ExtendedPaintingRenderState ;
45import ca .fxco .moreculling .utils .CullingUtils ;
56import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
67import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
78import com .llamalad7 .mixinextras .sugar .Local ;
89import com .mojang .blaze3d .vertex .PoseStack ;
910import com .mojang .blaze3d .vertex .VertexConsumer ;
11+ import com .mojang .logging .LogUtils ;
1012import me .fallenbreath .conditionalmixin .api .annotation .Condition ;
1113import me .fallenbreath .conditionalmixin .api .annotation .Restriction ;
1214import net .minecraft .client .renderer .RenderType ;
2325import org .spongepowered .asm .mixin .injection .Inject ;
2426import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2527
26- import static ca .fxco .moreculling .states .PaintingRendererStates .DIRECTION ;
27- import static ca .fxco .moreculling .states .PaintingRendererStates .PAINTING_POS ;
28+ import java .util .Arrays ;
2829
2930@ Restriction (conflict = {
3031 @ Condition ("smoothmaps" )
@@ -46,8 +47,7 @@ public abstract class PaintingRenderer_faceCullingMixin {
4647 private void moreculling$getPaintingPos (Painting painting , PaintingRenderState renderState , float partialTick ,
4748 CallbackInfo ci , @ Local (ordinal = 0 ) int width ,
4849 @ Local (ordinal = 1 ) int height ) {
49- PAINTING_POS = new BlockPos [width ][height ];
50- DIRECTION = painting .getDirection ();
50+ ((ExtendedPaintingRenderState ) renderState ).moreculling$setBlockPos (new BlockPos [width ][height ]);
5151 }
5252
5353 @ WrapOperation (
@@ -58,23 +58,31 @@ public abstract class PaintingRenderer_faceCullingMixin {
5858 target = "(III)Lnet/minecraft/core/BlockPos;" )
5959 )
6060 private BlockPos moreculling$getPaintingPos (int x , int y , int z , Operation <BlockPos > original ,
61- @ Local (ordinal = 3 ) int width , @ Local (ordinal = 2 ) int height ) {
61+ @ Local (ordinal = 3 ) int width , @ Local (ordinal = 2 ) int height ,
62+ @ Local (argsOnly = true ) PaintingRenderState renderState ) {
6263 BlockPos pos = original .call (x , y , z );
63- PAINTING_POS [width ][height ] = pos ;
64+ (( ExtendedPaintingRenderState ) renderState ). moreculling$getBlockPoses () [width ][height ] = pos ;
6465 return pos ;
6566 }
6667
67- @ Inject (
68- method = "renderPainting " ,
68+ @ WrapOperation (
69+ method = "submit(Lnet/minecraft/client/renderer/entity/state/PaintingRenderState;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/SubmitNodeCollector;Lnet/minecraft/client/renderer/state/CameraRenderState;)V " ,
6970 at = @ At (
70- value = "HEAD"
71- ),
72- cancellable = true
71+ value = "INVOKE" ,
72+ target = "Lnet/minecraft/client/renderer/entity/PaintingRenderer;" +
73+ "renderPainting(Lcom/mojang/blaze3d/vertex/PoseStack;" +
74+ "Lnet/minecraft/client/renderer/SubmitNodeCollector;" +
75+ "Lnet/minecraft/client/renderer/RenderType;" +
76+ "[IIILnet/minecraft/client/renderer/texture/TextureAtlasSprite;" +
77+ "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;)V"
78+ )
7379 )
74- private void moreculling$cullFace (PoseStack poseStack , SubmitNodeCollector nodeCollector , RenderType renderType ,
75- int [] lightCoords , int width , int height , TextureAtlasSprite variant ,
76- TextureAtlasSprite paintingAtlas , CallbackInfo ci ) {
80+ private void moreculling$cullFace (PaintingRenderer instance , PoseStack poseStack , SubmitNodeCollector nodeCollector ,
81+ RenderType renderType , int [] lightCoords , int width , int height ,
82+ TextureAtlasSprite variant , TextureAtlasSprite paintingAtlas ,
83+ Operation <Void > original , PaintingRenderState paintingRenderState ) {
7784 if (!MoreCulling .CONFIG .paintingCulling ) {
85+ original .call (instance , poseStack , nodeCollector , renderType , lightCoords , width , height , variant , paintingAtlas );
7886 return ;
7987 }
8088 nodeCollector .submitCustomGeometry (poseStack , renderType , (pose , consumer ) -> {
@@ -88,7 +96,7 @@ public abstract class PaintingRenderer_faceCullingMixin {
8896 float uY = paintingAtlas .getU (0.0625F );
8997 double d0 = 1.0 / (double ) width ; // fast math
9098 double d1 = 1.0 / (double ) height ; // fast math
91- Direction opposite = DIRECTION .getOpposite ();
99+ Direction opposite = paintingRenderState . direction .getOpposite ();
92100
93101 for (int x = 0 ; x < width ; x ++) {
94102 for (int y = 0 ; y < height ; y ++) {
@@ -109,7 +117,7 @@ public abstract class PaintingRenderer_faceCullingMixin {
109117 this .vertex (pose , consumer , x1 , y2 , fU0 , fV1 , -0.03125F , 0 , 0 , -1 , light );
110118 this .vertex (pose , consumer , x2 , y2 , fU1 , fV1 , -0.03125F , 0 , 0 , -1 , light );
111119
112- if (!CullingUtils .shouldCullPaintingBack (PAINTING_POS [x ][y ], opposite )) {
120+ if (!CullingUtils .shouldCullPaintingBack ((( ExtendedPaintingRenderState ) paintingRenderState ). moreculling$getBlockPoses () [x ][y ], opposite )) {
113121 //back
114122 this .vertex (pose , consumer , x2 , y2 , u1 , v0 , 0.03125F , 0 , 0 , 1 , light );
115123 this .vertex (pose , consumer , x1 , y2 , u0 , v0 , 0.03125F , 0 , 0 , 1 , light );
@@ -151,6 +159,5 @@ public abstract class PaintingRenderer_faceCullingMixin {
151159 }
152160 }
153161 });
154- ci .cancel ();
155162 }
156163}
0 commit comments