Skip to content

Commit

Permalink
Fix ItemRenderContextMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Oct 28, 2024
1 parent 72ddf70 commit 5e9287a
Showing 1 changed file with 25 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,82 +1,45 @@
package com.mmodding.mmodding_lib.mixin.injectors.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mmodding.mmodding_lib.MModdingLib;
import com.mmodding.mmodding_lib.library.glint.client.GlintPack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
import net.fabricmc.fabric.impl.client.indigo.renderer.render.ItemRenderContext;
import net.minecraft.client.render.TexturedRenderLayers;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = ItemRenderContext.class, remap = false)
import java.util.Optional;

@Mixin(value = ItemRenderContext.class)
public class ItemRenderContextMixin {

@Shadow
private ItemStack itemStack;

@Shadow
private VertexConsumerProvider vertexConsumerProvider;

@Shadow
private VertexConsumer translucentVertexConsumer;

@Shadow
private VertexConsumer cutoutVertexConsumer;

@Inject(method = "quadVertexConsumer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getItemGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lcom/mojang/blaze3d/vertex/VertexConsumer;", ordinal = 0), cancellable = true)
private void changeFirstItemConsumer(BlendMode blendMode, CallbackInfoReturnable<VertexConsumer> cir) {
GlintPack.of(this.itemStack).ifPresent(glintPack -> {
this.translucentVertexConsumer = glintPack.getItemConsumer(
this.vertexConsumerProvider,
TexturedRenderLayers.getItemEntityTranslucentCull(),
true,
this.itemStack.hasGlint()
);
cir.setReturnValue(this.translucentVertexConsumer);
});
}

@Inject(method = "quadVertexConsumer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getItemGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lcom/mojang/blaze3d/vertex/VertexConsumer;", ordinal = 1), cancellable = true)
private void changeSecondItemConsumer(BlendMode blendMode, CallbackInfoReturnable<VertexConsumer> cir) {
GlintPack.of(this.itemStack).ifPresent(glintPack -> {
this.translucentVertexConsumer = glintPack.getItemConsumer(
this.vertexConsumerProvider,
TexturedRenderLayers.getEntityTranslucentCull(),
true,
this.itemStack.hasGlint()
);
cir.setReturnValue(this.translucentVertexConsumer);
});
}

@Inject(method = "quadVertexConsumer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getDirectItemGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lcom/mojang/blaze3d/vertex/VertexConsumer;", ordinal = 0), cancellable = true)
private void changeFirstDirectItemConsumer(BlendMode blendMode, CallbackInfoReturnable<VertexConsumer> cir) {
GlintPack.of(this.itemStack).ifPresent(glintPack -> {
this.translucentVertexConsumer = glintPack.getDirectItemConsumer(
this.vertexConsumerProvider,
TexturedRenderLayers.getEntityTranslucentCull(),
true,
this.itemStack.hasGlint()
);
cir.setReturnValue(this.translucentVertexConsumer);
});
@WrapOperation(method = "quadVertexConsumer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getItemGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lcom/mojang/blaze3d/vertex/VertexConsumer;"))
private VertexConsumer changeItemConsumer(VertexConsumerProvider vertexConsumers, RenderLayer layer, boolean solid, boolean glint, Operation<VertexConsumer> original) {
Optional<GlintPack> glintPack = GlintPack.of(this.itemStack);
if (glintPack.isPresent()) {
return glintPack.get().getItemConsumer(vertexConsumers, layer, solid, glint);
}
else {
return original.call(vertexConsumers, layer, solid, glint);
}
}

@Inject(method = "quadVertexConsumer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getDirectItemGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lcom/mojang/blaze3d/vertex/VertexConsumer;", ordinal = 1), cancellable = true)
private void changeSecondDirectItemConsumer(BlendMode blendMode, CallbackInfoReturnable<VertexConsumer> cir) {
GlintPack.of(this.itemStack).ifPresent(glintPack -> {
this.cutoutVertexConsumer = glintPack.getDirectItemConsumer(
this.vertexConsumerProvider,
TexturedRenderLayers.getEntityCutout(),
true,
this.itemStack.hasGlint()
);
cir.setReturnValue(this.cutoutVertexConsumer);
});
@WrapOperation(method = "quadVertexConsumer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getDirectItemGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lcom/mojang/blaze3d/vertex/VertexConsumer;"))
private VertexConsumer changeDirectItemConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, Operation<VertexConsumer> original) {
Optional<GlintPack> glintPack = GlintPack.of(this.itemStack);
if (glintPack.isPresent()) {
return glintPack.get().getDirectItemConsumer(provider, layer, solid, glint);
}
else {
return original.call(provider, layer, solid, glint);
}
}
}

0 comments on commit 5e9287a

Please sign in to comment.