diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java index a01ba8766..a779ba944 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java @@ -8,6 +8,7 @@ import java.util.function.Supplier; import com.jozufozu.flywheel.core.virtual.VirtualEmptyBlockGetter; import com.jozufozu.flywheel.fabric.model.CullingBakedModel; import com.jozufozu.flywheel.fabric.model.DefaultLayerFilteringBakedModel; +import com.jozufozu.flywheel.fabric.model.FabricModelUtil; import com.jozufozu.flywheel.fabric.model.LayerFilteringBakedModel; import com.jozufozu.flywheel.util.Lazy; import com.jozufozu.flywheel.util.transform.TransformStack; @@ -16,6 +17,7 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexFormat; +import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.BlockModelShaper; @@ -68,13 +70,20 @@ public class ModelUtil { if (state.getRenderShape() != RenderShape.MODEL) continue; + BakedModel model = blockModels.getBlockModel(state); + if (((FabricBakedModel) model).isVanillaAdapter()) { + if (!FabricModelUtil.doesLayerMatch(state, layer)) { + continue; + } + } else { + model = CullingBakedModel.wrap(model); + model = LayerFilteringBakedModel.wrap(model, layer); + } + BlockPos pos = info.pos; ms.pushPose(); ms.translate(pos.getX(), pos.getY(), pos.getZ()); - BakedModel model = blockModels.getBlockModel(state); - model = CullingBakedModel.wrap(model); - model = LayerFilteringBakedModel.wrap(model, layer); modelRenderer.tesselateBlock(renderWorld, model, state, pos, ms, builder, true, random, 42, OverlayTexture.NO_OVERLAY); ms.popPose(); diff --git a/src/main/java/com/jozufozu/flywheel/fabric/model/CullingBakedModel.java b/src/main/java/com/jozufozu/flywheel/fabric/model/CullingBakedModel.java index a96d7cf04..897935401 100644 --- a/src/main/java/com/jozufozu/flywheel/fabric/model/CullingBakedModel.java +++ b/src/main/java/com/jozufozu/flywheel/fabric/model/CullingBakedModel.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.fabric.model; import java.util.Random; import java.util.function.Supplier; -import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.minecraft.client.resources.model.BakedModel; @@ -22,7 +21,7 @@ public class CullingBakedModel extends ForwardingBakedModel { protected final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(); public static BakedModel wrap(BakedModel model) { - if (!FabricModelUtil.FREX_LOADED && !((FabricBakedModel) model).isVanillaAdapter()) { + if (!FabricModelUtil.FREX_LOADED) { CullingBakedModel wrapper = THREAD_LOCAL.get(); wrapper.wrapped = model; return wrapper; diff --git a/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java b/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java index 432aa86d4..5c9044a00 100644 --- a/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java @@ -10,6 +10,9 @@ import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; import net.fabricmc.fabric.impl.client.indigo.renderer.RenderMaterialImpl; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.renderer.ItemBlockRenderTypes; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.world.level.block.state.BlockState; public class FabricModelUtil { public static final boolean INDIUM_LOADED = FabricLoader.getInstance().isModLoaded("indium"); @@ -61,6 +64,10 @@ public class FabricModelUtil { return BLEND_MODE_GETTER.getBlendMode(material); } + public static boolean doesLayerMatch(BlockState modelState, RenderType layer) { + return ItemBlockRenderTypes.getChunkRenderType(modelState) == layer; + } + private interface BlendModeGetter { BlendMode getBlendMode(RenderMaterial material); } diff --git a/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java b/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java index 5bf88755a..16f9e0127 100644 --- a/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java +++ b/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.fabric.model; import java.util.Random; import java.util.function.Supplier; -import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.minecraft.client.renderer.ItemBlockRenderTypes; @@ -36,7 +35,7 @@ public class LayerFilteringBakedModel extends ForwardingBakedModel { @Override public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { RenderType defaultLayer = ItemBlockRenderTypes.getChunkRenderType(state); - if (((FabricBakedModel) wrapped).isVanillaAdapter()) { + if (super.isVanillaAdapter()) { if (defaultLayer == targetLayer) { super.emitBlockQuads(blockView, state, pos, randomSupplier, context); }