Skip to content

Commit

Permalink
Fix 1.20 armor and armor trim glint rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralhalo committed Jun 11, 2023
1 parent b9ee6a3 commit 25ac054
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
1 change: 1 addition & 0 deletions fabric/src/main/resources/mixins.canvas.client.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"MixinGlStateManager",
"MixinGui",
"MixinGuiGraphics",
"MixinHumanoidArmorLayer",
"MixinItemFrameRenderer",
"MixinItemRenderer",
"MixinLevelChunk",
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/grondag/canvas/mixin/MixinHumanoidArmorLayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* This file is part of Canvas Renderer and is licensed to the project under
* terms that are compatible with the GNU Lesser General Public License.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership and licensing.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package grondag.canvas.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;

import io.vram.frex.api.rendertype.RenderTypeUtil;

import grondag.canvas.buffer.input.CanvasImmediate;

@Mixin(HumanoidArmorLayer.class)
public class MixinHumanoidArmorLayer {
private boolean canvas_hasFoil = false;

@Inject(method = "renderArmorPiece", at = @At("HEAD"))
void captureFoil(PoseStack poseStack, MultiBufferSource multiBufferSource, LivingEntity livingEntity, EquipmentSlot equipmentSlot, int i, HumanoidModel humanoidModel, CallbackInfo ci) {
canvas_hasFoil = livingEntity.getItemBySlot(equipmentSlot).hasFoil();
}

@Redirect(method = "renderModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;"))
VertexConsumer adjustModelGlint(MultiBufferSource bufferSource, RenderType renderType) {
if (bufferSource instanceof CanvasImmediate immediate) {
return immediate.getConsumer(RenderTypeUtil.toMaterial(renderType, canvas_hasFoil));
} else {
return bufferSource.getBuffer(renderType);
}
}

@Redirect(method = "renderTrim", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;"))
VertexConsumer adjustTrimGlint(MultiBufferSource bufferSource, RenderType renderType) {
if (bufferSource instanceof CanvasImmediate immediate) {
return immediate.getConsumer(RenderTypeUtil.toMaterial(renderType, canvas_hasFoil));
} else {
return bufferSource.getBuffer(renderType);
}
}

@Inject(method = "renderGlint", at = @At("HEAD"), cancellable = true)
void onRenderGlint(PoseStack poseStack, MultiBufferSource bufferSource, int i, HumanoidModel humanoidModel, CallbackInfo ci) {
if (bufferSource instanceof CanvasImmediate) {
ci.cancel();
}
}
}
10 changes: 8 additions & 2 deletions src/main/resources/assets/canvas/pipelines/canvas_basic.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
vertexSource: "canvas:shaders/pipeline/standard.vert",
fragmentSource: "canvas:shaders/pipeline/basic.frag",
// glsl names for samplers additive to the FREX pre-defined samplers
samplers: ["cvu_glint_item", "cvu_glint_entity"],
samplers: [
"cvu_glint_item",
"cvu_glint_entity"
],
// image names for samplers additive to the FREX pre-defined samplers
samplerImages: ["minecraft:textures/misc/enchanted_glint_item.png", "minecraft:textures/misc/enchanted_glint_entity.png"]
samplerImages: [
"minecraft:textures/misc/enchanted_glint_item.png",
"minecraft:textures/misc/enchanted_glint_entity.png"
]
},

drawTargets: {
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/assets/canvas/pipelines/canvas_standard.json5
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
vertexSource: "canvas:shaders/pipeline/standard.vert",
fragmentSource: "canvas:shaders/pipeline/standard.frag",
// glsl names for samplers additive to the FREX pre-defined samplers
samplers: ["cvu_glint_item", "cvu_glint_entity"],
samplers: [
"cvu_glint_item",
"cvu_glint_entity"
],
// image names for samplers additive to the FREX pre-defined samplers
samplerImages: ["minecraft:textures/misc/enchanted_glint_item.png", "minecraft:textures/misc/enchanted_glint_entity.png"]
samplerImages: [
"minecraft:textures/misc/enchanted_glint_item.png",
"minecraft:textures/misc/enchanted_glint_entity.png"
]
},

drawTargets: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
materialProgram: {
vertexSource: "abstract:shaders/pipeline/abstract.vert",
fragmentSource: "abstract:shaders/pipeline/abstract.frag",
samplers: ["cvu_glint_item", "cvu_glint_entity"],
samplerImages: ["minecraft:textures/misc/enchanted_glint_item.png", "minecraft:textures/misc/enchanted_glint_entity.png"],
samplers: [
"cvu_glint_item",
"cvu_glint_entity"
],
samplerImages: [
"minecraft:textures/misc/enchanted_glint_item.png",
"minecraft:textures/misc/enchanted_glint_entity.png"
],
compileByTarget: true
},

Expand Down

0 comments on commit 25ac054

Please sign in to comment.