Skip to content

Commit

Permalink
fix #1167
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Mar 3, 2024
1 parent 442d1f8 commit 3db14df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions FABRIC_CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Random> randomSupplier, RenderContext context, BlockState material, CullFaceRemovalData cullFaceRemovalData, OcclusionData occlusionData);
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ public static <B extends CopycatBlock, P> NonNullUnaryOperator<BlockBuilder<B, P
.initialProperties(SharedProperties::softMetal)
.properties(p -> 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());
}
Expand Down

0 comments on commit 3db14df

Please sign in to comment.