Proger 2.0
Proger 2.0

Reputation: 13

Problem writing a Mixin for Fabric (Minecraft 1.16.5)

This is the original code, which I am writing a Mixin for. What I want to do is next: change the boolean showOutline to true (I know how to do this) only if entity is instanceOf PlayerEntity.

protected RenderLayer getRenderLayer(LivingEntity entity, boolean showBody, boolean translucent, boolean showOutline) {
    Identifier identifier = this.getTexture(entity);
    if (translucent) {
        return RenderLayer.getItemEntityTranslucentCull(identifier);
    }
    if (showBody) {
        return ((Model)this.model).getLayer(identifier);
    }
    if (showOutline) {
        return RenderLayer.getOutline(identifier);
    }
    return null;
}

This is the code I wrote to change the boolean showOutline:

@ModifyVariable(method = "getRenderLayer(Lnet/minecraft/entity/LivingEntity;ZZZ)Lnet/minecraft/client/render/RenderLayer;", at = @At("HEAD"), ordinal = 2, argsOnly = true)
private boolean injected_showOutline(boolean showOutline) {
    return true;
}

and it works nice.But I do not know how to add checking if (entity instanceof PlayerEntity) there.

What I tried was next:

@Inject(method = "getRenderLayer(Lnet/minecraft/entity/LivingEntity;ZZZ)Lnet/minecraft/client/render/RenderLayer;", at = @At("HEAD"))
private void injection(LivingEntity entity, boolean showBody, boolean translucent, boolean showOutline, CallbackInfoReturnable<RenderLayer> cir, @Local(ordinal = 0, argsOnly = true) boolean _showBody, @Local(ordinal = 1, argsOnly = true) boolean _translucent, @Local(ordinal = 2, argsOnly = true) boolean _showOutline) {
    if (entity instanceof PlayerEntity){
        _showBody = false;
        _translucent = false;
        _showOutline = true;
    }
}

But it didn't work I guess because they are local variables

Upvotes: 0

Views: 190

Answers (0)

Related Questions