diff --git a/FABRIC_CHANGELOG.txt b/FABRIC_CHANGELOG.txt index 51181c167a..0cf1594431 100644 --- a/FABRIC_CHANGELOG.txt +++ b/FABRIC_CHANGELOG.txt @@ -17,3 +17,4 @@ Change logging starts below: - fix a crash with Jade and Deployers (#1139) - fix the Wand of Symmetry always placing double slabs (#1086) - fix switched inputs in clipboard tooltip (#1212) +- fix copycats having bad translucency (#1167) diff --git a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java index 10f44c21aa..d82b7d89a2 100644 --- a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java +++ b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java @@ -1,11 +1,18 @@ package com.simibubi.create.content.decoration.copycat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.Objects; import java.util.Random; import java.util.function.Supplier; +import com.jozufozu.flywheel.fabric.model.FabricModelUtil; + +import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; +import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; +import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; +import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext.QuadTransform; + import org.jetbrains.annotations.Nullable; import com.simibubi.create.AllBlocks; @@ -16,6 +23,8 @@ import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemBlockRenderTypes; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; @@ -72,7 +81,13 @@ public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, Block } } + // fabric: need to change the default render material + context.pushTransform(MaterialFixer.create(material)); + emitBlockQuadsInner(blockView, state, pos, randomSupplier, context, material, cullFaceRemovalData, occlusionData); + + // fabric: pop the material changer transform + context.popTransform(); } protected abstract void emitBlockQuadsInner(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context, BlockState material, CullFaceRemovalData cullFaceRemovalData, OcclusionData occlusionData); @@ -137,4 +152,23 @@ public boolean shouldRemove(Direction face) { } } + private record MaterialFixer(RenderMaterial materialDefault) implements QuadTransform { + @Override + public boolean transform(MutableQuadView quad) { + BlendMode quadBlendMode = FabricModelUtil.getBlendMode(quad); + if (quadBlendMode == BlendMode.DEFAULT) { + // default needs to be changed from the Copycat's default (cutout) to the wrapped material's default. + quad.material(materialDefault); + } + return true; + } + + public static MaterialFixer create(BlockState materialState) { + RenderType type = ItemBlockRenderTypes.getChunkRenderType(materialState); + BlendMode blendMode = BlendMode.fromRenderLayer(type); + MaterialFinder finder = Objects.requireNonNull(RendererAccess.INSTANCE.getRenderer()).materialFinder(); + RenderMaterial renderMaterial = finder.blendMode(0, blendMode).find(); + return new MaterialFixer(renderMaterial); + } + } } diff --git a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java index 2c2b4c7307..b705d87ed8 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java +++ b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java @@ -115,10 +115,8 @@ public static NonNullUnaryOperator p.noOcclusion() .color(MaterialColor.NONE)) - .addLayer(() -> RenderType::solid) + // fabric: only render base model on cutout. When rendering the wrapped model's material is copied. .addLayer(() -> RenderType::cutout) - .addLayer(() -> RenderType::cutoutMipped) - .addLayer(() -> RenderType::translucent) .color(() -> CopycatBlock::wrappedColor) .transform(TagGen.axeOrPickaxe()); }