Skip to content

Commit

Permalink
Fix glint rendering issue (Indigo PR port)
Browse files Browse the repository at this point in the history
  • Loading branch information
comp500 and PepperCode1 committed Jun 16, 2024
1 parent 1415284 commit b740df8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
# Mod Properties
mod_version=1.0.32
mod_version=1.0.33
maven_group=link.infra
archives_base_name=indium
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package link.infra.indium.mixin.renderer;

import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ItemRenderer.class)
public interface ItemRendererAccessor {
@Invoker("usesDynamicDisplay")
static boolean indium$usesDynamicDisplay(ItemStack stack) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package link.infra.indium.renderer.render;

import link.infra.indium.mixin.renderer.ItemRendererAccessor;
import link.infra.indium.renderer.helper.ColorHelper;
import link.infra.indium.renderer.mesh.EncodingFormat;
import link.infra.indium.renderer.mesh.MutableQuadViewImpl;
Expand All @@ -36,6 +37,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MatrixUtil;
import net.minecraft.util.math.random.LocalRandom;
import net.minecraft.util.math.random.Random;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -82,13 +84,16 @@ public ModelTransformationMode itemTransformationMode() {

private ItemStack itemStack;
private ModelTransformationMode transformMode;
private MatrixStack matrixStack;
private VertexConsumerProvider vertexConsumerProvider;
private int lightmap;

private boolean isDefaultTranslucent;
private boolean isTranslucentDirect;
private boolean isDefaultGlint;
private boolean isGlintDynamicDisplay;

private MatrixStack.Entry dynamicDisplayGlintEntry;
private VertexConsumer translucentVertexConsumer;
private VertexConsumer cutoutVertexConsumer;
private VertexConsumer translucentGlintVertexConsumer;
Expand All @@ -112,6 +117,7 @@ public BakedModelConsumer bakedModelConsumer() {
public void renderModel(ItemStack itemStack, ModelTransformationMode transformMode, boolean invert, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int lightmap, int overlay, BakedModel model) {
this.itemStack = itemStack;
this.transformMode = transformMode;
this.matrixStack = matrixStack;
this.vertexConsumerProvider = vertexConsumerProvider;
this.lightmap = lightmap;
this.overlay = overlay;
Expand All @@ -123,8 +129,10 @@ public void renderModel(ItemStack itemStack, ModelTransformationMode transformMo
model.emitItemQuads(itemStack, randomSupplier, this);

this.itemStack = null;
this.matrixStack = null;
this.vertexConsumerProvider = null;

dynamicDisplayGlintEntry = null;
translucentVertexConsumer = null;
cutoutVertexConsumer = null;
translucentGlintVertexConsumer = null;
Expand All @@ -151,6 +159,7 @@ private void computeOutputInfo() {
}

isDefaultGlint = itemStack.hasGlint();
isGlintDynamicDisplay = ItemRendererAccessor.indium$usesDynamicDisplay(itemStack);
}

private void renderQuad(MutableQuadViewImpl quad) {
Expand All @@ -170,7 +179,7 @@ private void renderQuad(MutableQuadViewImpl quad) {

private void colorizeQuad(MutableQuadViewImpl quad, int colorIndex) {
if (colorIndex != -1) {
final int itemColor = 0xFF000000 | colorMap.getColor(itemStack, colorIndex);
final int itemColor = colorMap.getColor(itemStack, colorIndex);

for (int i = 0; i < 4; i++) {
quad.color(i, ColorHelper.multiplyColor(itemColor, quad.color(i)));
Expand Down Expand Up @@ -245,6 +254,10 @@ private VertexConsumer getVertexConsumer(BlendMode blendMode, TriState glintMode
}

private VertexConsumer createTranslucentVertexConsumer(boolean glint) {
if (glint && isGlintDynamicDisplay) {
return createDynamicDisplayGlintVertexConsumer(MinecraftClient.isFabulousGraphicsOrBetter() && !isTranslucentDirect ? TexturedRenderLayers.getItemEntityTranslucentCull() : TexturedRenderLayers.getEntityTranslucentCull());
}

if (isTranslucentDirect) {
return ItemRenderer.getDirectItemGlintConsumer(vertexConsumerProvider, TexturedRenderLayers.getEntityTranslucentCull(), true, glint);
} else if (MinecraftClient.isFabulousGraphicsOrBetter()) {
Expand All @@ -255,9 +268,27 @@ private VertexConsumer createTranslucentVertexConsumer(boolean glint) {
}

private VertexConsumer createCutoutVertexConsumer(boolean glint) {
if (glint && isGlintDynamicDisplay) {
return createDynamicDisplayGlintVertexConsumer(TexturedRenderLayers.getEntityCutout());
}

return ItemRenderer.getDirectItemGlintConsumer(vertexConsumerProvider, TexturedRenderLayers.getEntityCutout(), true, glint);
}

private VertexConsumer createDynamicDisplayGlintVertexConsumer(RenderLayer layer) {
if (dynamicDisplayGlintEntry == null) {
dynamicDisplayGlintEntry = matrixStack.peek().copy();

if (transformMode == ModelTransformationMode.GUI) {
MatrixUtil.scale(dynamicDisplayGlintEntry.getPositionMatrix(), 0.5F);
} else if (transformMode.isFirstPerson()) {
MatrixUtil.scale(dynamicDisplayGlintEntry.getPositionMatrix(), 0.75F);
}
}

return ItemRenderer.getDynamicDisplayGlintConsumer(vertexConsumerProvider, layer, dynamicDisplayGlintEntry);
}

private class BakedModelConsumerImpl implements BakedModelConsumer {
@Override
public void accept(BakedModel model) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/indium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"renderer.MixinBlockModelRenderer",
"renderer.MixinItemRenderer",
"renderer.MixinBakedModel",
"renderer.ItemRendererAccessor",
"sodium.AccessBlockRenderer",
"sodium.MixinBlockRenderCache",
"sodium.MixinChunkBuilderMeshingTask"
Expand Down

0 comments on commit b740df8

Please sign in to comment.