|
| 1 | +/* |
| 2 | + * Swansong |
| 3 | + * |
| 4 | + * Copyright 2025 Ven, FalsePattern |
| 5 | + * |
| 6 | + * This software is licensed under the Open Software License version |
| 7 | + * 3.0. The full text of this license can be found in https://opensource.org/licenses/OSL-3.0 |
| 8 | + * or in the LICENSES directory which is distributed along with the software. |
| 9 | + */ |
| 10 | + |
| 11 | +package com.ventooth.swansong.mixin.mixins.client.hooks; |
| 12 | + |
| 13 | +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; |
| 14 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 15 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 16 | +import com.llamalad7.mixinextras.sugar.Share; |
| 17 | +import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; |
| 18 | +import com.ventooth.swansong.api.ShaderStateInfo; |
| 19 | +import com.ventooth.swansong.mixin.extensions.RendererLivingEntityExt; |
| 20 | +import com.ventooth.swansong.shader.ShaderEngine; |
| 21 | +import com.ventooth.swansong.shader.StateGraph; |
| 22 | +import lombok.val; |
| 23 | +import org.spongepowered.asm.mixin.Dynamic; |
| 24 | +import org.spongepowered.asm.mixin.Mixin; |
| 25 | +import org.spongepowered.asm.mixin.Unique; |
| 26 | +import org.spongepowered.asm.mixin.injection.At; |
| 27 | +import org.spongepowered.asm.mixin.injection.Slice; |
| 28 | + |
| 29 | +import net.minecraft.client.model.ModelBase; |
| 30 | +import net.minecraft.client.renderer.entity.RendererLivingEntity; |
| 31 | +import net.minecraft.entity.Entity; |
| 32 | + |
| 33 | +@Mixin(RendererLivingEntity.class) |
| 34 | +public abstract class RendererLivingEntityMixin_CustomPlayerModels { |
| 35 | + @Unique |
| 36 | + private static final String CPM_ASM_HOOK_METHOD = "Lcom/tom/cpmcore/CPMASMClientHooks;renderPass(Lnet/minecraft/client/model/ModelBase;Lnet/minecraft/entity/Entity;FFFFFFLnet/minecraft/client/renderer/entity/RendererLivingEntity;I)V"; |
| 37 | + @Unique |
| 38 | + private static final String DYNAMIC_COMMENT = "Applied by: [com.tom.cpmcore.CPMTransformerService]"; |
| 39 | + |
| 40 | + @Dynamic(DYNAMIC_COMMENT) |
| 41 | + @WrapOperation(method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", |
| 42 | + at = @At(value = "INVOKE", |
| 43 | + target = CPM_ASM_HOOK_METHOD, |
| 44 | + remap = false, |
| 45 | + ordinal = 0), |
| 46 | + require = 1) |
| 47 | + private void hook_WrapSpiderEyes(ModelBase modelBase, |
| 48 | + Entity entity, |
| 49 | + float limbSwing, |
| 50 | + float limbSwingAmount, |
| 51 | + float ageInTicks, |
| 52 | + float netHeadYaw, |
| 53 | + float headPitch, |
| 54 | + float scale, |
| 55 | + RendererLivingEntity renderer, |
| 56 | + int callLoc, |
| 57 | + Operation<Void> original, |
| 58 | + @Share("pass_ref") LocalIntRef passRef) { |
| 59 | + //separated out here because intellij screams due to the unsafe cast when inlined |
| 60 | + val self = (RendererLivingEntity) (Object) this; |
| 61 | + if (ShaderEngine.graph.isManaged() && |
| 62 | + RendererLivingEntityExt.isSpiderEyes(self, entity, modelBase, passRef.get())) { |
| 63 | + if (ShaderStateInfo.shadowPassActive()) { |
| 64 | + return; |
| 65 | + } |
| 66 | + ShaderEngine.graph.push(StateGraph.Stack.SpiderEyes); |
| 67 | + original.call(modelBase, entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, renderer, callLoc); |
| 68 | + ShaderEngine.graph.pop(StateGraph.Stack.SpiderEyes); |
| 69 | + } else { |
| 70 | + original.call(modelBase, entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, renderer, callLoc); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + @Dynamic(DYNAMIC_COMMENT) |
| 75 | + @WrapWithCondition(method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", |
| 76 | + at = @At(value = "INVOKE", |
| 77 | + target = CPM_ASM_HOOK_METHOD, |
| 78 | + remap = false), |
| 79 | + slice = @Slice(from = @At(value = "INVOKE", |
| 80 | + target = "Lnet/minecraft/client/renderer/entity/RendererLivingEntity;renderEquippedItems(Lnet/minecraft/entity/EntityLivingBase;F)V")), |
| 81 | + require = 1) |
| 82 | + private boolean skip_VanillaMobHurtRender(ModelBase instance, |
| 83 | + Entity entity, |
| 84 | + float limbSwing, |
| 85 | + float limbSwingAmount, |
| 86 | + float ageInTicks, |
| 87 | + float netHeadYaw, |
| 88 | + float headPitch, |
| 89 | + float scale, |
| 90 | + RendererLivingEntity renderer, |
| 91 | + int callLoc) { |
| 92 | + return !ShaderEngine.isInitialized(); |
| 93 | + } |
| 94 | +} |
0 commit comments