Skip to content

Commit

Permalink
1.21: Fix entities incorrectly getting assigned translucent layer
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeF53 committed May 30, 2024
1 parent 719ebd2 commit 570a69e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<RenderLayer> 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<Void> 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<Void> original, @Share("alpha") LocalIntRef alpha) {
instance.render(matrixStack, vertexConsumer, light, overlay, Argb.withAlpha(alpha.get(), 0xFFFFFF));
}
}

0 comments on commit 570a69e

Please sign in to comment.