From feca9c937be40bfed255e6574dea70d640fdafea Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 11 Jul 2024 01:58:23 +0200 Subject: Add custom head models --- .../custommodels/PatchHeadFeatureRenderer.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java (limited to 'src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java') diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java new file mode 100644 index 0000000..dca81b8 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java @@ -0,0 +1,50 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins.custommodels; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.features.texturepack.BakedModelExtra; +import net.minecraft.block.AbstractSkullBlock; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.client.render.entity.feature.HeadFeatureRenderer; +import net.minecraft.client.render.entity.model.EntityModel; +import net.minecraft.client.render.item.HeldItemRenderer; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(HeadFeatureRenderer.class) +public class PatchHeadFeatureRenderer> { + + @Shadow + @Final + private HeldItemRenderer heldItemRenderer; + + @WrapOperation(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockItem;getBlock()Lnet/minecraft/block/Block;")) + private Block replaceSkull(BlockItem instance, Operation original, @Local ItemStack itemStack) { + var oldBlock = original.call(instance); + if (oldBlock instanceof AbstractSkullBlock) { + var bakedModel = this.heldItemRenderer.itemRenderer + .getModel(itemStack, null, null, 0); + if (bakedModel instanceof BakedModelExtra extra && extra.getHeadModel_firmament() != null) + return Blocks.ENCHANTING_TABLE; // Any non skull block. Let's choose the enchanting table because it is very distinct. + } + return oldBlock; + } + + + + +} -- cgit