diff --git a/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java b/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java index 46cffd0..10a1275 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java +++ b/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java @@ -12,16 +12,23 @@ import net.minecraft.util.math.ColorHelper.Argb; 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.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = LivingEntityRenderer.class, priority = 960) public abstract class HorseRenderer { + @Inject(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At("HEAD")) + void getAlpha(CallbackInfo ci, @Local(argsOnly = true) LivingEntity entity, @Share("alpha") LocalIntRef alpha) { + if (entity instanceof AbstractHorseEntity) + alpha.set(RenderUtils.getAlpha(entity)); + } + @ModifyArg(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/EntityModel;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;III)V"), index = 4) int setOpacityAndChromaForRender(int color, @Local(argsOnly = true, ordinal = 1) float tickDelta, @Local(argsOnly = true) LivingEntity entity, @Share("alpha") LocalIntRef alpha) { if (!(entity instanceof AbstractHorseEntity)) return color; - alpha.set(RenderUtils.getAlpha(entity)); if (RenderUtils.isJeb(entity)) { // see net/minecraft/client/render/entity/feature/SheepWoolFeatureRenderer int dyeIndex = entity.age / 25 + entity.getId(); @@ -39,10 +46,10 @@ int setOpacityAndChromaForRender(int color, @Local(argsOnly = true, ordinal = 1) @ModifyArg(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingEntityRenderer;getRenderLayer(Lnet/minecraft/entity/LivingEntity;ZZZ)Lnet/minecraft/client/render/RenderLayer;"), index = 2) - boolean makeRenderLayerTranslucent(boolean translucent, @Local(argsOnly = true) LivingEntity entity, @Share("alpha") LocalIntRef alpha) { + boolean makeRenderLayerTranslucent(boolean translucent, @Local(argsOnly = true) LivingEntity entity, @Share("alpha") LocalIntRef alphaRef) { if (translucent) return true; if (entity instanceof AbstractHorseEntity) - return alpha.get() != 255; + return alphaRef.get() != 255; return false; } } diff --git a/src/main/java/net/F53/HorseBuff/mixin/Client/TransparentMarkings.java b/src/main/java/net/F53/HorseBuff/mixin/Client/TransparentMarkings.java index 66fb89b..cffd412 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/Client/TransparentMarkings.java +++ b/src/main/java/net/F53/HorseBuff/mixin/Client/TransparentMarkings.java @@ -3,11 +3,15 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; +import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.entity.feature.HorseMarkingFeatureRenderer; import net.minecraft.client.render.entity.model.HorseEntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.passive.HorseEntity; +import net.minecraft.util.Identifier; import net.minecraft.util.math.ColorHelper.Argb; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -16,9 +20,17 @@ @Mixin(value = HorseMarkingFeatureRenderer.class, priority = 960) public class TransparentMarkings { + @WrapOperation(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/passive/HorseEntity;FFFFFF)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayer;getEntityTranslucent(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;")) + RenderLayer makeRenderLayerTranslucent(Identifier texture, Operation original, @Local(argsOnly = true) HorseEntity horseEntity, @Share("alpha") LocalIntRef alpha) { + alpha.set(getAlpha(horseEntity)); + if (alpha.get() == 255) return original.call(texture); + return RenderLayer.getItemEntityTranslucentCull(texture); + } + @WrapOperation(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/passive/HorseEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/HorseEntityModel;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;II)V")) - void modifyOverlayAlpha(HorseEntityModel instance, MatrixStack matrixStack, VertexConsumer vertexConsumer, int light, int overlay, Operation original, @Local(argsOnly = true) HorseEntity horseEntity) { - instance.render(matrixStack, vertexConsumer, light, overlay, Argb.withAlpha(getAlpha(horseEntity), 0xFFFFFF)); + void modifyOverlayAlpha(HorseEntityModel instance, MatrixStack matrixStack, VertexConsumer vertexConsumer, int light, int overlay, Operation original, @Share("alpha") LocalIntRef alpha) { + instance.render(matrixStack, vertexConsumer, light, overlay, Argb.withAlpha(alpha.get(), 0xFFFFFF)); } }