|
| 1 | +package me.juancarloscp52.bedrockify.mixin.client.features.babyVillagerHeads; |
| 2 | + |
| 3 | +import com.google.common.collect.ImmutableList; |
| 4 | +import me.juancarloscp52.bedrockify.client.BedrockifyClient; |
| 5 | +import net.minecraft.client.model.ModelPart; |
| 6 | +import net.minecraft.client.render.VertexConsumer; |
| 7 | +import net.minecraft.client.render.entity.model.EntityModelPartNames; |
| 8 | +import net.minecraft.client.render.entity.model.VillagerResemblingModel; |
| 9 | +import net.minecraft.client.util.math.MatrixStack; |
| 10 | +import net.minecraft.entity.Entity; |
| 11 | +import org.spongepowered.asm.mixin.Final; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Shadow; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | + |
| 19 | +@Mixin(VillagerResemblingModel.class) |
| 20 | +public abstract class VillagerResemblingModelMixin<T extends Entity> extends SinglePartEntityModelMixin<T> { |
| 21 | + |
| 22 | + @Shadow @Final private ModelPart rightLeg; |
| 23 | + @Shadow @Final private ModelPart leftLeg; |
| 24 | + @Shadow @Final private ModelPart head; |
| 25 | + @Unique |
| 26 | + public ModelPart body; |
| 27 | + @Unique |
| 28 | + public ModelPart arms; |
| 29 | + |
| 30 | + @Inject(method = "<init>", at=@At("RETURN")) |
| 31 | + private void ctr(ModelPart root, CallbackInfo ci){ |
| 32 | + this.body = root.getChild(EntityModelPartNames.BODY); |
| 33 | + this.arms = root.getChild(EntityModelPartNames.ARMS); |
| 34 | + } |
| 35 | + |
| 36 | + //Override parent injection with baby villager renderer. For more information see: https://www.fabricmc.net/wiki/tutorial:mixinheritance |
| 37 | + @Override |
| 38 | + protected void injectCustomBabyRender(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color, CallbackInfo ci) { |
| 39 | + if(this.child && BedrockifyClient.getInstance().settings.babyVillagerHeads){ |
| 40 | + // Render scaled head. |
| 41 | + float scale = 1.5f; |
| 42 | + matrices.push(); |
| 43 | + matrices.scale(scale,scale,scale); |
| 44 | + this.getHeadParts().forEach(modelPart -> modelPart.render(matrices,vertices,light,overlay,color)); |
| 45 | + matrices.pop(); |
| 46 | + |
| 47 | + // Render rest of the body. |
| 48 | + this.getBodyParts().forEach(modelPart -> modelPart.render(matrices,vertices,light,overlay,color)); |
| 49 | + ci.cancel(); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + @Unique |
| 54 | + public Iterable<ModelPart> getHeadParts() { |
| 55 | + return ImmutableList.of(this.head); |
| 56 | + } |
| 57 | + |
| 58 | + @Unique |
| 59 | + protected Iterable<ModelPart> getBodyParts() { |
| 60 | + return ImmutableList.of(this.body, this.rightLeg, this.leftLeg, this.arms); |
| 61 | + } |
| 62 | +} |
0 commit comments