Skip to content

Commit c0e4b8a

Browse files
committed
Fix painting culling
Fixes: #399
1 parent 1dc3b4e commit c0e4b8a

File tree

6 files changed

+65
-28
lines changed

6 files changed

+65
-28
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ca.fxco.moreculling.api.renderers;
2+
3+
import net.minecraft.core.BlockPos;
4+
5+
public interface ExtendedPaintingRenderState {
6+
7+
default BlockPos[][] moreculling$getBlockPoses() {
8+
return null;
9+
}
10+
11+
default void moreculling$setBlockPos(BlockPos[][] pos) {
12+
13+
}
14+
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ca.fxco.moreculling.mixin.renderers;
2+
3+
import ca.fxco.moreculling.api.renderers.ExtendedPaintingRenderState;
4+
import net.minecraft.client.renderer.entity.state.PaintingRenderState;
5+
import net.minecraft.core.BlockPos;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Unique;
8+
9+
@Mixin(PaintingRenderState.class)
10+
public class PaintingRenderState_apiMixin implements ExtendedPaintingRenderState {
11+
@Unique
12+
private BlockPos[][] moreculling$blockposes;
13+
14+
@Override
15+
public BlockPos[][] moreculling$getBlockPoses() {
16+
return moreculling$blockposes;
17+
}
18+
19+
@Override
20+
public void moreculling$setBlockPos(BlockPos[][] pos) {
21+
moreculling$blockposes = pos;
22+
}
23+
}

common/src/main/java/ca/fxco/moreculling/mixin/renderers/PaintingRenderer_faceCullingMixin.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package ca.fxco.moreculling.mixin.renderers;
22

33
import ca.fxco.moreculling.MoreCulling;
4+
import ca.fxco.moreculling.api.renderers.ExtendedPaintingRenderState;
45
import ca.fxco.moreculling.utils.CullingUtils;
56
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
67
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
78
import com.llamalad7.mixinextras.sugar.Local;
89
import com.mojang.blaze3d.vertex.PoseStack;
910
import com.mojang.blaze3d.vertex.VertexConsumer;
11+
import com.mojang.logging.LogUtils;
1012
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
1113
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
1214
import net.minecraft.client.renderer.RenderType;
@@ -23,8 +25,7 @@
2325
import org.spongepowered.asm.mixin.injection.Inject;
2426
import 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
}

common/src/main/java/ca/fxco/moreculling/states/PaintingRendererStates.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

common/src/main/resources/moreculling.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"renderers.ItemStackRenderState_faceCullingMixin",
5858
"renderers.LayerRenderState_apiMixin",
5959
"renderers.ModelBlockRenderer_cullMixin",
60-
"renderers.PaintingRenderer_faceCullingMixin"
60+
"renderers.PaintingRenderer_faceCullingMixin",
61+
"renderers.PaintingRenderState_apiMixin"
6162
],
6263
"injectors": {
6364
"defaultRequire": 1

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ neoforge_loader_version_range=[21.9.0-beta,)
2525
fabric_loader_version=0.17.2
2626

2727
# Mod Properties
28-
mod_version=1.5.0-beta.1
28+
mod_version=1.5.0-beta.2
2929
maven_group=ca.fxco.moreculling
3030
archives_base_name=moreculling
3131
license=GPL-3.0-only

0 commit comments

Comments
 (0)