Skip to content

Commit ba60a6b

Browse files
committed
Use quad's Uv bounds instead of quadbounds for transluceny check
1 parent b8cca1a commit ba60a6b

File tree

6 files changed

+16
-47
lines changed

6 files changed

+16
-47
lines changed

common/src/main/java/ca/fxco/moreculling/mixin/blocks/EndRodBlock_cullMixin.java

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

common/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_cacheMixin.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
import ca.fxco.moreculling.api.data.QuadBounds;
44
import ca.fxco.moreculling.api.model.BakedOpacity;
55
import ca.fxco.moreculling.api.sprite.SpriteOpacity;
6-
import ca.fxco.moreculling.platform.Services;
7-
import ca.fxco.moreculling.utils.CullingUtils;
86
import ca.fxco.moreculling.utils.DirectionBits;
97
import ca.fxco.moreculling.utils.VertexUtils;
108
import com.mojang.blaze3d.platform.NativeImage;
119
import net.minecraft.client.renderer.block.model.BakedQuad;
12-
import net.minecraft.client.resources.model.BakedModel;
1310
import net.minecraft.client.resources.model.SimpleBakedModel;
14-
import net.minecraft.core.BlockPos;
1511
import net.minecraft.core.Direction;
16-
import net.minecraft.world.level.EmptyBlockGetter;
1712
import net.minecraft.world.level.block.state.BlockState;
1813
import net.minecraft.world.phys.shapes.VoxelShape;
1914
import org.jetbrains.annotations.Nullable;
@@ -57,8 +52,7 @@ public abstract class SimpleBakedModel_cacheMixin implements BakedOpacity {
5752
BakedQuad initialQuad = layeredQuads.removeFirst();
5853
SpriteOpacity opacity = ((SpriteOpacity) initialQuad.getSprite());
5954
NativeImage image = opacity.moreculling$getUnmipmappedImage();
60-
QuadBounds bounds = VertexUtils.getQuadBounds(initialQuad, direction.getAxis(),
61-
image.getWidth(), image.getHeight());
55+
QuadBounds bounds = VertexUtils.getQuadUvBounds(initialQuad, image.getWidth(), image.getHeight());
6256
if (!opacity.moreculling$hasTranslucency(bounds)) {
6357
if (!layeredQuads.isEmpty()) {
6458
List<NativeImage> overlappingImages = new ArrayList<>();

common/src/main/java/ca/fxco/moreculling/utils/CacheUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ public static void resetAllCache() {
2424
// Reset all model translucency cache
2525
Map<BlockState, BakedModel> allModels = ((BlockModelShaperAccessor) blockRenderManager.getBlockModelShaper()).getModels();
2626
allModels.forEach((state, model) -> {
27-
if (!state.canOcclude()) {
28-
((BakedOpacity) model).moreculling$resetTranslucencyCache(state);
29-
}
27+
((BakedOpacity) model).moreculling$resetTranslucencyCache(state);
3028
});
3129
//TODO: Reset quad cache
3230
MoreCulling.LOGGER.info(allModels.size() + " cache(s) where cleared!");

common/src/main/java/ca/fxco/moreculling/utils/CullingUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ca.fxco.moreculling.MoreCulling;
44
import ca.fxco.moreculling.api.blockstate.MoreStateCulling;
55
import ca.fxco.moreculling.api.blockstate.StateCullingShapeCache;
6+
import com.mojang.logging.LogUtils;
67
import it.unimi.dsi.fastutil.objects.Object2ByteLinkedOpenHashMap;
78
import net.caffeinemc.mods.sodium.client.SodiumClientMod;
89
import net.minecraft.client.GraphicsStatus;
@@ -13,6 +14,7 @@
1314
import net.minecraft.util.RandomSource;
1415
import net.minecraft.world.level.BlockGetter;
1516
import net.minecraft.world.level.block.Block;
17+
import net.minecraft.world.level.block.Blocks;
1618
import net.minecraft.world.level.block.LeavesBlock;
1719
import net.minecraft.world.level.block.RenderShape;
1820
import net.minecraft.world.level.block.state.BlockState;

common/src/main/java/ca/fxco/moreculling/utils/VertexUtils.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import ca.fxco.moreculling.api.data.QuadBounds;
44
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
55
import net.minecraft.client.renderer.block.model.BakedQuad;
6-
import net.minecraft.core.Direction;
6+
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
77
import org.joml.Math;
88
import org.joml.*;
99

@@ -36,34 +36,28 @@ private static Vector3f getPos(int[] data, int vertexIndex) {
3636
);
3737
}
3838

39-
private static Vector2f getPos(int[] data, int vertexIndex, Direction.Axis axis) {
39+
private static Vector2f getUv(TextureAtlasSprite sprite, int[] data, int vertexIndex, int imageWidth, int imageHeight) {
4040
final int index = vertexIndex * VERTEX_STRIDE;
41-
if (axis.isVertical()) {
42-
return new Vector2f(
43-
Float.intBitsToFloat(data[index]), // x
44-
Float.intBitsToFloat(data[index + 2]) // z
45-
);
46-
} else {
47-
return new Vector2f(
48-
(float) axis.choose(Float.intBitsToFloat(data[index + 2]), 0, Float.intBitsToFloat(data[index])),
49-
Float.intBitsToFloat(data[index + 1])
50-
);
51-
}
41+
float width = sprite.getU1() - sprite.getU0();
42+
float height = sprite.getV1() - sprite.getV0();
43+
return new Vector2f(
44+
((Float.intBitsToFloat(data[index + 4]) - sprite.getU0()) / width) * imageWidth, // x
45+
((Float.intBitsToFloat(data[index + 5]) - sprite.getV0()) / height) * imageHeight // y
46+
);
5247
}
5348

54-
public static QuadBounds getQuadBounds(BakedQuad quad, Direction.Axis axis,
55-
int resolutionScaleX, int resolutionScaleY) {
49+
public static QuadBounds getQuadUvBounds(BakedQuad quad, int imageWidth, int imageHeight) {
5650
Vector2i minPos = new Vector2i(Integer.MAX_VALUE);
5751
Vector2i maxPos = new Vector2i(-Integer.MAX_VALUE);
5852
int[] vertexData = quad.getVertices();
5953
for (int i = 0; i < 4; i++) {
60-
Vector2f tmpPos = getPos(vertexData, i, axis);
54+
Vector2f tmpPos = getUv(quad.getSprite(), vertexData, i, imageWidth, imageHeight);
6155
Vector2i pos = new Vector2i(Math.round(tmpPos.x), Math.round(tmpPos.y));
6256
minPos.min(pos);
6357
maxPos.max(pos);
6458
}
65-
return new QuadBounds(minPos.x * resolutionScaleX, minPos.y * resolutionScaleY,
66-
maxPos.x * resolutionScaleX, maxPos.y * resolutionScaleY);
59+
return new QuadBounds(minPos.x, minPos.y,
60+
maxPos.x, maxPos.y);
6761
}
6862

6963
public static boolean isAxisAligned(BakedQuad quad) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"blocks.cullshape.ChorusFlowerBlock_voxelMixin",
2626
"blocks.DoorBlock_cullAgainstMixin",
2727
"blocks.EndGatewayBlock_cullMixin",
28-
"blocks.EndRodBlock_cullMixin",
2928
"blocks.FletchingTableBlock_devMixin",
3029
"blocks.LadderBlock_cullAgainstMixin",
3130
"blocks.LeavesBlock_typesMixin",

0 commit comments

Comments
 (0)